Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Re: insert into a hash

by kyle (Abbot)
on Mar 26, 2009 at 20:05 UTC ( [id://753498]=note: print w/replies, xml ) Need Help??


in reply to insert into a hash

From your description, I wrote this:

my %hash; my @labels = qw(Date,Login,Searchload,Searchsave,Searchdetails,Searchd +elete); while ( my $line = <FILE> ) { chomp $line; my @fields = split /,/, $line; foreach my $label ( @labels ) { push @{ $hash{ $label } }, shift @fields; } }

You might want to consider using Text::CSV_XS. And, as always, Use strict and warnings.

Replies are listed 'Best First'.
Re^2: insert into a hash
by AnomalousMonk (Archbishop) on Mar 26, 2009 at 22:42 UTC
    From the statement
        my @labels = qw(Date,Login,Searchload,Searchsave,Searchdetails,Searchdelete);
    the array  @labels contains only a single element, the string 'Date,Login,Searchload,Searchsave,Searchdetails,Searchdelete'.
    >perl -wMstrict -le "my @ra = qw(a,b,c); print scalar @ra; print qq{'@ra'}; " Possible attempt to separate words with commas at -e line 1. Possible attempt to separate words with commas at -e line 1. 1 'a,b,c'
    The use of warnings and strictures is a very good idea.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others avoiding work at the Monastery: (10)
As of 2024-04-23 08:22 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found