in reply to perl awk

Using Perl instead of awk you would do:

use strict; use warnings; my $label = "some string"; my $apex = 10; # some number my $reference = "somefile.txt"; my $name = "out.txt"; open IN, "<", $reference or die "Cannot open file $reference.\n"; open OUT, ">", "temp_marker_$name" or die "Cannot open file temp_marke +r_$name.\n"; while(<IN>) { my @fields = split; # cannot remember what awk splits on by defaul +t if( $fields[0] eq $label and $fields[2] <= $apex and $fields[3] >= $apex ) { print OUT $_; } } close OUT; close IN;

Replies are listed 'Best First'.
Re^2: perl awk
by jarwulf (Initiate) on Apr 09, 2013 at 22:36 UTC
    So basically its a loop? Is the comparison being done on every line in reference, a single line, or some other part?
      Pretty much. Awk works a lot like "perl -ane", looping over lines in a file and splitting them into fields. An awk command is of the form "TEST { ACTION }", where TEST controls whether ACTION is performed. It's more involved than that, but since I learned Perl first, I rarely use awk. You might try feeding the awk command to a2p to get a perl equivalent of what it does.