A Field Guide To The Perl Command Line: Andy Lester
A Field Guide To The Perl Command Line: Andy Lester
# Windows
C:\> perl -e"print \"Hello, World!\n\""
The magic filehandle
# Instead, do this:
while ( my $line = <> ) {
# do something
}
print;
}
-p examples
# Program to print output with line numbers
# (in case cat -n doesn't do it for ya)
while (<>) {
$_ = sprintf( "%05d: %s", $., $_ );
print; # implicitly print $_
}
# Or total 'em up
#!/usr/bin/perl -n
BEGIN { $total=0 }
END { printf( "%.2f\n", $total ) }
while ( /\$(\d+\.\d\d)/g ) {
$total += $1;
}
-l: line-ending handling
# Special values:
-00 (zero zero) = paragraph mode (same as $/="")
-0777 = slurp mode (same as $/=undef)
#!/usr/bin/perl -i -p
s/FOO/BAR/g;