in reply to Re^19: Addional "year" matching functionality in word matching script
in thread Addional "year" matching functionality in word matching script
I have been testing some code on a smaller scale and something is confusing me. Why does the print "$csv2\n"; command at the end of this script print each full line of the csv. $csv2 has been populated with the key data of csv2hash, so I'm confused as to why it would print each line? Is each line considered a key in this instance?
#!/bin/perl my @csv2 = (); # Creates new empty array @csv2 open CSV2, "<csv2" or die; # Creates the file handle CSV2, input +s the data from csv2 into CVS2 @csv2=<CSV2>; # populates @csv2 array with data from file handle + CSV2 close CSV2; my %csv2hash = (); # Creates empty hash csv2hash for (@csv2) { # for data in @csv2 array #chomp; my ($title) = $_ =~ /^.+?,\s*([^,]+?),/; #/define the data whic +h is the title #Indicate that title data will input into csv2hash $csv2hash{$_} = $title; } foreach my $csv2 (keys %csv2hash) { # iterates over all the keys in %c +sv2hash, assigning each one to $csv2 my $value = $csv2hash{$csv2}; print "$csv2\n"; # This prints the data line by line in the csv2
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^21: Addional "year" matching functionality in word matching script
by Corion (Patriarch) on Jul 12, 2016 at 16:59 UTC | |
by bms9nmh (Novice) on Aug 03, 2016 at 15:40 UTC | |
by choroba (Cardinal) on Aug 03, 2016 at 16:02 UTC | |
by bms9nmh (Novice) on Aug 18, 2016 at 17:01 UTC | |
by choroba (Cardinal) on Aug 18, 2016 at 19:35 UTC |
In Section
Seekers of Perl Wisdom