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.