- or download this
defined #same as defined($_)
print #same as print STDOUT $_
/\sjackson$/ #same as $_ =~ /\sjackson$/
- or download this
@only_defined = grep { defined($_) } @somearray;
%hash_defined = map { $_ => 1 } @only_defined;
...
#and since $_ is the default argument, you can also write
@only_defined = grep { defined } @somearray;
@only_begins_with_a = grep { /^a/ } @somearray;
- or download this
while (<STDIN>) {
chomp # same as chomp $_
if (/^#/) {....} # same as if ($_ =~ /^#/) { ....}
}
- or download this
#Note this code still won't work - see sherm's explanation below.
...
if($name =~ "jackson")
print $name . "\n"; #sic - should be { print $name . "\n" }
}
- or download this
while (my $line = <STDIN>) {
chomp $line;
if ($line =~ /^#/) {....}
}