mirror of
https://github.com/adambard/learnxinyminutes-docs.git
synced 2025-05-08 15:58:33 +00:00
Merge pull request #1131 from mcanlas/master
[perl/en] Whitespace and for loop improvements
This commit is contained in:
commit
dc34162829
@ -83,13 +83,23 @@ print "We have no bananas" unless $bananas;
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
# for and foreach
|
# for loops and iteration
|
||||||
for ($i = 0; $i <= $max; $i++) {
|
for (my $i = 0; $i < $max; $i++) {
|
||||||
...
|
print "index is $i";
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach (@array) {
|
for (my $i = 0; $i < @elements; $i++) {
|
||||||
print "This element is $_\n";
|
print "Current element is " . $elements[$i];
|
||||||
|
}
|
||||||
|
|
||||||
|
for my $element (@elements) {
|
||||||
|
print $element;
|
||||||
|
}
|
||||||
|
|
||||||
|
# implicitly
|
||||||
|
|
||||||
|
for (@elements) {
|
||||||
|
print;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -130,7 +140,9 @@ my @lines = <$in>;
|
|||||||
|
|
||||||
sub logger {
|
sub logger {
|
||||||
my $logmessage = shift;
|
my $logmessage = shift;
|
||||||
|
|
||||||
open my $logfile, ">>", "my.log" or die "Could not open my.log: $!";
|
open my $logfile, ">>", "my.log" or die "Could not open my.log: $!";
|
||||||
|
|
||||||
print $logfile $logmessage;
|
print $logfile $logmessage;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user