in reply to awk...ward

The a2p program that is included with perl will translate awk scripts to perl. It can be instructive to look at the translations, if your original script wasn't too complex. (For complex awk scripts, the translation soon gets too cumbersome to plow through.)
% cat try.awk {print $1} % a2p try.awk > try.perl % cat try.perl #!/usr/shell/bin/perl eval 'exec perl -S $0 "$@"' if $running_under_some_shell; # this emulates #! processing on NIH machines. # (remove #! line above if indigestible) eval '$'.$1.'$2;' while $ARGV[0] =~ /^([A-Za-z_0-9]+=)(.*)/ && shift; # process any FOO=bar switches $, = ' '; # set output field separator $\ = "\n"; # set output record separator while (<>) { ($Fld1) = split(' ', $_, 9999); print $Fld1; }

Caution: Contents may have been coded under pressure.

Replies are listed 'Best First'.
Re^2: awk...ward
by belg4mit (Prior) on Mar 01, 2005 at 13:33 UTC
    Except in this case. That's some pretty nasty perl for what it's trying to do. I've previously contemplated writing a module to somehow allow awk column sementics in perl... never quite got a round tuit though.

    --
    I'm not belgian but I play one on TV. On dit que je parle comme un belge aussi.


      Inline::Awk gives you all the power (?!) of awk from within a Perl program:
      perl -le 'use Inline Awk=>q({print $1}); awk()' file

      I agree with you that the output of a2p isn't pretty and it is probably not the best way for an awk programmer to learn Perl.

      --
      John.