Re: awk command in script?

[email protected] ("John W. Krahn") Fri, 21 Nov 2008 17:52:12 -0800
Newsgroups perl.beginners.cgi
Message-ID <[email protected]>
Owen wrote:
> 
> You need to run something like this. Adapt to your requirements
> 
> ============================================================
> #!/usr/bin/perl -w
> 
> use strict;
> 
> while (<DATA>) {
>     my $line = $_;
>     if ( $line =~ /QQQ/ ) {
>         my @bits = split;
>         print "$bits[$#bits -1]\n";
> 
>     }
> }

Or more simply:

#!/usr/bin/perl -w
use strict;

while (<DATA>) {
     if ( /QQQ/ ) {
         print +( split )[ -2 ], "\n";
     }
}




John
-- 
Perl isn't a toolbox, but a small machine shop where you
can special-order certain sorts of tools at low cost and
in short order.                            -- Larry Wall