Skip to content

Instantly share code, notes, and snippets.

@hernan604
Last active December 26, 2015 08:39
Show Gist options
  • Save hernan604/7123681 to your computer and use it in GitHub Desktop.
Save hernan604/7123681 to your computer and use it in GitHub Desktop.
quick perl code generator
#quick perl code generator, im pretty sure mst mentioned this tip, so here it is
use strict;
use warnings;
use IO::All;
use Encode qw/decode encode/;
use v5.10;
use Path::Class;
my $config = {
site => "perldelux",
domain => "perldelux.com.br",
base_path => "/home/hernan/perl/",
img_logo => "http://perldelux.com.br/logo.png",
};
##Create my base path if does not exists
io->dir( $config->{ base_path } )->mkpath;
##Creates a file named: filename1.htm with the following content
io->file( file( $config->{ base_path } ,'filename1.htm' ) )->print(<<END);
<ul>
<li class="imagem">
<a href="$config->{ domain }">
<img src="$config->{ img_logo }" alt="$config->{ site }" title="$config->{ site }" />
</a>
</li>
</ul>
END
##Creates another file, however this time write everything in utf8, but saves the file as iso-8859-1
io->file( file( $config->{ base_path } ,'filename2.htm' ) )->print( encode( "iso-8859-1", decode( "utf8" , <<END ) ) );
this file is saved as iso-8859-1 but was converted from utf8 input
bla bla bla bla bla lalalala
some accents: ãéíóú
END
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment