mirror of
https://github.com/adambard/learnxinyminutes-docs.git
synced 2025-07-31 12:00:34 +02:00
Merge pull request #1131 from mcanlas/master
[perl/en] Whitespace and for loop improvements
This commit is contained in:
@@ -83,13 +83,23 @@ print "We have no bananas" unless $bananas;
|
||||
}
|
||||
|
||||
|
||||
# for and foreach
|
||||
for ($i = 0; $i <= $max; $i++) {
|
||||
...
|
||||
# for loops and iteration
|
||||
for (my $i = 0; $i < $max; $i++) {
|
||||
print "index is $i";
|
||||
}
|
||||
|
||||
foreach (@array) {
|
||||
print "This element is $_\n";
|
||||
for (my $i = 0; $i < @elements; $i++) {
|
||||
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 {
|
||||
my $logmessage = shift;
|
||||
|
||||
open my $logfile, ">>", "my.log" or die "Could not open my.log: $!";
|
||||
|
||||
print $logfile $logmessage;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user