in reply to Re^2: Creating a Hash using only one column in an imported data file
in thread Creating a Hash using only one column in an imported data file
Hi Koda1234,
The preferred (because it's safest ) way to open a file is the "three-argument form" (see open [suggestion: as a beginner, read the docs for the various functions; don't just copy examples you may see in the wild ]).
Also:
use strict; use warnings; use feature 'say'; my $filename = $ARGV[0] or die "You must supply a filename"; -f $filename or die "You must supply the name of a file that exists!"; open my $IN, '<', $filename or die "Can't open < $filename: $!"; my @col9; while ( my $line = <$IN> ) { chomp $line; push @col9, (split / /, $line)[8]; } close $IN or die "Can't close $filename: $!"; foreach my $test ( 1, 9, 42, 666 ) { my $count = scalar grep { $_ >= $test } @col9; say sprintf "%d values were >= %d", $count, $test; } __END__
Hope this helps!
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: Creating a Hash using only one column in an imported data file
by Koda1234 (Initiate) on Feb 13, 2017 at 22:25 UTC | |
by 1nickt (Canon) on Feb 13, 2017 at 22:30 UTC | |
by Koda1234 (Initiate) on Feb 13, 2017 at 22:44 UTC | |
by 1nickt (Canon) on Feb 13, 2017 at 22:59 UTC |