Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re: Learning Perl, Hashes Help

by Jim (Curate)
on Apr 29, 2014 at 01:33 UTC ( [id://1084237]=note: print w/replies, xml ) Need Help??


in reply to Learning Perl, Hashes Help

Instead of doing this…

open(FILE, '/location/data/p4.txt') or die "Cant't open file: $!\n +";

…do this…

use strict; use warnings; use autodie qw( open close ); # ... my $file = shift; # The input file name is a command-line argument open my $fh, '<:encoding(ASCII)', $file; # Or whatever the correct + character encoding is # ... close $fh;

And instead of doing this…

my %myhash = (); my @data = (); chomp(@data = <FILE>); foreach (@data) { %myhash = (@data => $k++); }

…do this…

my %total_values_by; while (my $value = <$fh>) { chomp $value; $total_values_by{$value}++; }

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1084237]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others learning in the Monastery: (4)
As of 2024-04-24 05:10 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found