| -w | use warnings |
| -e | the next arg is the script to run (e.g perl -e 'print "hello world\n"' ) |
| -p | walks through the file argument (?) see 'global file substitution' example |
perl -p -i -e 's/from/to/g' filename) # the '>' indicates I want to write to the file open(theFile, ">dump.txt") || die "can't open the file"; print theFile "I've written to the file!\n"; close(theFile);
open(theDict, "/usr/share/dict/linux.words") || die "Can't open dict\n";
while (<theDict>) {
print;
}
close(theDict);
while ($line = <>) { print "-*$line"; } |
basic example, but we can be more succint |
...or simpler: while (<>) { $_ =~ s!^!-*!; print $_; } |
works because $_ means 'current line read from <> |
...or simpler still: while (<>) { s!^!-*;!; print; } |
works beacuse $_ is assumed in the print and the substitution |
# '$/' is the Optional 'chunk mode' parameter. Designates what the <> operator
# looks for to terminate each read operation. Default is '\n' (??)
$/ = "\n";
while (1) {
if (not defined($junk)) {
print "not defined\n";
$junk = "junk";
} else {
print "now it's defined\n";
last
}
}
-- MattWalsh - 15 Aug 2002