diff options
author | Mark Canlas <github@htmlism.com> | 2015-06-10 00:00:12 +0200 |
---|---|---|
committer | Mark Canlas <github@htmlism.com> | 2015-06-10 00:00:12 +0200 |
commit | 75ecb5aa8133325f14d97d00675c3b039da06530 (patch) | |
tree | 475409b8428b06c015d6f5b39997977be04ecf7b /perl.html.markdown | |
parent | e07c4e7b8be8d3051ad5e4cbaa24a1cc23c86f7d (diff) |
tamed indentation/whitespace
Diffstat (limited to 'perl.html.markdown')
-rw-r--r-- | perl.html.markdown | 44 |
1 files changed, 23 insertions, 21 deletions
diff --git a/perl.html.markdown b/perl.html.markdown index aac95939..ab8c7a32 100644 --- a/perl.html.markdown +++ b/perl.html.markdown @@ -47,9 +47,9 @@ my %fruit_color = ("apple", "red", "banana", "yellow"); # You can use whitespace and the "=>" operator to lay them out more nicely: my %fruit_color = ( - apple => "red", - banana => "yellow", - ); + apple => "red", + banana => "yellow", +); # Scalars, arrays and hashes are documented more fully in perldata. # (perldoc perldata). @@ -60,17 +60,17 @@ my %fruit_color = ( # Perl has most of the usual conditional and looping constructs. -if ( $var ) { - ... -} elsif ( $var eq 'bar' ) { - ... +if ($var) { + ... +} elsif ($var eq 'bar') { + ... } else { - ... + ... } -unless ( condition ) { - ... - } +unless (condition) { + ... +} # This is provided as a more readable version of "if (!condition)" # the Perlish post-condition way @@ -78,19 +78,19 @@ print "Yow!" if $zippy; print "We have no bananas" unless $bananas; # while - while ( condition ) { - ... - } +while (condition) { + ... +} # for and foreach for ($i = 0; $i <= $max; $i++) { - ... - } + ... +} foreach (@array) { - print "This element is $_\n"; - } + print "This element is $_\n"; +} #### Regular expressions @@ -129,9 +129,11 @@ my @lines = <$in>; # Writing subroutines is easy: sub logger { - my $logmessage = shift; - open my $logfile, ">>", "my.log" or die "Could not open my.log: $!"; - print $logfile $logmessage; + my $logmessage = shift; + + open my $logfile, ">>", "my.log" or die "Could not open my.log: $!"; + + print $logfile $logmessage; } # Now we can use the subroutine just as any other built-in function: |