in reply to Re^5: Addional "year" matching functionality in word matching script
in thread Addional "year" matching functionality in word matching script
One thing I'm not sure of is, I've tried to integrate the info above so that I can use the $title from a csv file rather than titles typed into the script (as in the above example). I have attempted this below but it's not working. I'd appreciate if someone could tell me what exactly i'm doing wrong. I know I'm being prompted to learn which I'm happy to do, but I think I would learn faster if someone told me what I have done wrong in the piece of code below.sub find_year { my( $str ) = @_; my $year; $year = $1 if( $str =~ /\b((?:19|20)\d\d)\b/ ); return $year } for my $title ( "Let's party like it's 1999", "If 6 was 9", "If 6 was 9", "Summer of 69", "Disco 2000", ) { print $title , " => ", find_year($title), "\n"; }
sub find_year { my( $str ) = @_; my $year; $year = $1 if( $str =~ /\b((?:19|20)\d\d)\b/ ); return $year } #get the title from csv3 open CSV3, "<csv3" or die; while (<CSV3>) { chomp; my ($title) = $_ =~ /^.+?,\s*([^,]+?),/; #/ match the title } for my $title { print $title , " => ", find_year($title), "\n"; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^7: Addional "year" matching functionality in word matching script
by Corion (Patriarch) on Jun 28, 2016 at 14:17 UTC | |
by bms9nmh (Novice) on Jun 28, 2016 at 14:40 UTC | |
by Corion (Patriarch) on Jun 28, 2016 at 14:49 UTC | |
by bms9nmh (Novice) on Jun 28, 2016 at 15:22 UTC | |
by Cow1337killr (Monk) on Jun 28, 2016 at 16:16 UTC | |
| |
by bms9nmh (Novice) on Jun 28, 2016 at 14:50 UTC |