>>>>> "Pedro" == Pedro A Reche Gallardo <[EMAIL PROTECTED]> writes:

Pedro> Hi all, I have a file that it looks as it follows
Pedro> 1 0.057         M       M       -       M
Pedro> 2 0.819         R       R       -       R
Pedro> 3 0.731         V       V       -       V
Pedro> 4 1.708         K       R       -       c
Pedro> 5 1.070         G       G       -       t
Pedro> 6 1.611         I       M       -       h
Pedro> 7 2.055         +       Q       -       p
Pedro> 8 1.748         +       R       -       +
Pedro> 9 0.864         N       N       -       N
Pedro> 10 2.146        a       W       -       h
Pedro> 11 1.782        Q       Q       -       .
Pedro> 12 2.707        +       H       -       p
Pedro> 13 0.893        .       -       -       .
Pedro> 14 1.252        L       L       -       h
Pedro> 15 0.659        W       G       -       W
Pedro> 16 2.150        +       K       -       p
Pedro> 17 1.137        W       W       -       W
Pedro> 18 0.976        G       G       -       G
Pedro> 19 2.022        .       -       -       .
Pedro> 20 0.147        .       -       -       .
Pedro> 21 0.124        .       -       -       .
Pedro> 22 0.023        .       -       -       .

Pedro> I usually use the following awk comand awk '{if (!($2<0.5&&$3~/\./))
Pedro> print $0}' filename to get rid of the rows where the third column
Pedro> contains the "." caracter, and second column contain a number that is
Pedro> lower than 0.5. In perl  the above command -translated using a2p tool-
Pedro> translate into this:


Pedro> #!/usr/sbin/perl
Pedro> eval 'exec /usr/sbin/perl -S $0 ${1+"$@"}'
Pedro>     if $running_under_some_shell;
Pedro>    # this emulates #! processing on NIH machines.
Pedro>    # (remove #! line above if indigestible)

Pedro> eval '$'.$1.'$2;' while $ARGV[0] =~ /^([A-Za-z_0-9]+=)(.*)/ && shift;
Pedro>    # process any FOO=bar switches

Pedro> $[ = 1;   # set array base to 1
Pedro> $, = ' ';  # set output field separator
Pedro> $\ = "\n";  # set output record separator

Pedro> while (<>) {
Pedro>     chop; # strip record separator
Pedro>     @Fld = split(' ', $_, 9999);
Pedro>     if (!($Fld[2] < 0.8 && $Fld[3] =~ /\./)) {
Pedro>  print $_;
Pedro>     }
Pedro> }

Pedro> I will be very happy if anyone could help me to understand the script. I
Pedro> am particularly lost with the eval function.

The eval is merely used to process FOO=bar switches on the awk
command line.  While the above is a nice literal translation of that
awk program, a more Perl-ish translation would be:

    while (<>) {
      @f = split ' ', $_;
      next unless $f[2] < 0.8 and $f[3] =~ /\./;
      print;
    }

Does that help?

-- 
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<[EMAIL PROTECTED]> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!

Reply via email to