stupid perl question.
John Chambers
jc at trillian.mit.edu
Sun Nov 11 22:27:32 EST 2001
Frank J.Ramsay wrote:
| On Sunday 11 November 2001 10:19, John Chambers wrote:
| > Frank J.Ramsay asks:
| > | Why doesn't this work?
...
| > I'd wonder why you
| > would even bother with awk from a perl script.
|
| Well it worked from the command line... and I don't use perl often enough to
| do much without a book nearby for reference (and all my perl books are at the
| office. But it looks like I'll have to remember the syntax for doing it in
| perl.
Yeah; it's really worthwhile learning enough perl to run commands and
grovel through their output, printing something interesting. Consider
this scripts:
#!/usr/bin/perl
for $line (`/sbin/ifconfig`) {
if ($line =~ /inet addr:([\d\.]+)/) {
print "$1\n";
}
}
The only thing tricky here is mastering perl's patterns. That's much
like anyone else's REs, but even more complicated, due to all the
fancy bells & whistles that perl has accreted. Of course, when you do
it this way, you do away with tools like grep, sed and awk. All of
their capabilities have been included in perl. This is no accident,
of course.
More information about the Discuss
mailing list