mirror of
https://github.com/adambard/learnxinyminutes-docs.git
synced 2024-12-25 08:13:29 +03:00
tamed indentation/whitespace
This commit is contained in:
parent
e07c4e7b8b
commit
75ecb5aa81
@ -47,9 +47,9 @@ my %fruit_color = ("apple", "red", "banana", "yellow");
|
|||||||
# You can use whitespace and the "=>" operator to lay them out more nicely:
|
# You can use whitespace and the "=>" operator to lay them out more nicely:
|
||||||
|
|
||||||
my %fruit_color = (
|
my %fruit_color = (
|
||||||
apple => "red",
|
apple => "red",
|
||||||
banana => "yellow",
|
banana => "yellow",
|
||||||
);
|
);
|
||||||
# Scalars, arrays and hashes are documented more fully in perldata.
|
# Scalars, arrays and hashes are documented more fully in perldata.
|
||||||
# (perldoc perldata).
|
# (perldoc perldata).
|
||||||
|
|
||||||
@ -60,17 +60,17 @@ my %fruit_color = (
|
|||||||
|
|
||||||
# Perl has most of the usual conditional and looping constructs.
|
# Perl has most of the usual conditional and looping constructs.
|
||||||
|
|
||||||
if ( $var ) {
|
if ($var) {
|
||||||
...
|
...
|
||||||
} elsif ( $var eq 'bar' ) {
|
} elsif ($var eq 'bar') {
|
||||||
...
|
...
|
||||||
} else {
|
} else {
|
||||||
...
|
...
|
||||||
}
|
}
|
||||||
|
|
||||||
unless ( condition ) {
|
unless (condition) {
|
||||||
...
|
...
|
||||||
}
|
}
|
||||||
# This is provided as a more readable version of "if (!condition)"
|
# This is provided as a more readable version of "if (!condition)"
|
||||||
|
|
||||||
# the Perlish post-condition way
|
# the Perlish post-condition way
|
||||||
@ -78,19 +78,19 @@ print "Yow!" if $zippy;
|
|||||||
print "We have no bananas" unless $bananas;
|
print "We have no bananas" unless $bananas;
|
||||||
|
|
||||||
# while
|
# while
|
||||||
while ( condition ) {
|
while (condition) {
|
||||||
...
|
...
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
# for and foreach
|
# for and foreach
|
||||||
for ($i = 0; $i <= $max; $i++) {
|
for ($i = 0; $i <= $max; $i++) {
|
||||||
...
|
...
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach (@array) {
|
foreach (@array) {
|
||||||
print "This element is $_\n";
|
print "This element is $_\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#### Regular expressions
|
#### Regular expressions
|
||||||
@ -129,9 +129,11 @@ my @lines = <$in>;
|
|||||||
# Writing subroutines is easy:
|
# Writing subroutines is easy:
|
||||||
|
|
||||||
sub logger {
|
sub logger {
|
||||||
my $logmessage = shift;
|
my $logmessage = shift;
|
||||||
open my $logfile, ">>", "my.log" or die "Could not open my.log: $!";
|
|
||||||
print $logfile $logmessage;
|
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:
|
# Now we can use the subroutine just as any other built-in function:
|
||||||
|
Loading…
Reference in New Issue
Block a user