I can't, off the top of my head, think of anything
that's loads easier to do in awk instead of Perl.
If you have some legacy awk script that you would
rather not convert to perl by hand, Perl does come
with an awk to perl translator. See a2p.
As stephen said, if you give us a little info on why you
need to use awk and Perl together, we might offer better
advice. | [reply] |
I still find that, after all these years, it's easier to write
ls -l|awk '{print $5}'
than
ls -l|perl -alne 'print $F[4]'
or Newton forbid...
ls -l|perl -ane 'print "$F[4]\n"'
Not only is the awk solution clearer, it also has a
lighter resource footprint.
That is, when you string together long pipes on the command line, awk is often
more compact than Perl. That's about all I use awk for these
days, but I sure used to sling around a lot of data with it
in the 80s.
It's not difficult to learn to write baby awk, and if you
do it will serve you well. If the job gets too tough, though
(think: you can no longer run it from the command line) then
it's time to switch to Perl.
For example, user functions were retrofitted into the
language, and the syntax is a bit of a botch. I can't even
remember what it was now, but there was a gotcha that would
rear its head up every so often and bite you.
Just because you have a chainsaw doesn't mean you can't
use a pair of secateurs.
-- g r i n d e r
| [reply] [d/l] [select] |
ls -l|perl -pale '$_=$F[4]'
which saves a couple of characters. I know what you
mean, but I forgot most of the awk and sed that I ever knew
when I learnt Perl.
--
<http://www.dave.org.uk>
"Perl makes the fun jobs fun
and the boring jobs bearable" - me
| [reply] [d/l] |
| [reply] |
Thanks for the input.
The reason why, well.. I'm at work like most people here who post problems, and there's a script that runs in a job... to extract certain info from a flatfile. Basically, I'm just modifying a current shell script. From trial and error, I've been learning AWK now... but thought that maybe others here have had to do something with AWK and have infused Perl in some way. I didn't want an answer to my specific code, just to see if others have experienced this and how they went about it.
Thanks again and thanks in advance to anyone else who posts here.
brother Zo | [reply] |