note
bms9nmh
I have been testing some code on a smaller scale and something is confusing me. Why does the <code> print "$csv2\n"; </code> 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?
<code>
#!/bin/perl
my @csv2 = (); # Creates new empty array @csv2
open CSV2, "<csv2" or die; # Creates the file handle CSV2, inputs 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 which is the title
#Indicate that title data will input into csv2hash
$csv2hash{$_} = $title;
}
foreach my $csv2 (keys %csv2hash) { # iterates over all the keys in %csv2hash, assigning each one to $csv2
my $value = $csv2hash{$csv2};
print "$csv2\n"; # This prints the data line by line in the csv2 </code>
1166649
1167012