in reply to printing values within a given range
Very good!#!/usr/bin/perl use strict; use warnings;
It's generally recommended, and for good reasons (that I'm not explaining here - but about which I can expand, if needed), tomy $input = $ARGV[0]; open(INPUT, "$input") || die "Oops!: Can't open file: $!\n"; my @inputfile = <INPUT>; for(my $j = 0; $j < @inputfile; $j++)
Also, nothing wrong with the above logic, per se, but what about a simple
instead?while (<>) { # ... }
Update:
I have a text file which is nothing more than a list of numbers. I would like to print these numbers if they are between -130 and -125 in value. Unfortunately my current code is not working ... it's printing out all the values in the text file regardless of whether they are between -130 and -125 or not.Your current code doesn't match exactly this description. However The following minimal example should:
#!/usr/bin/perl -ln use strict; use warnings; print if -130 < $_ and $_ < -125; __END__
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: printing values within a given range
by Angharad (Pilgrim) on May 03, 2005 at 14:21 UTC | |
by blazar (Canon) on May 03, 2005 at 14:31 UTC |