in reply to Re^6: Addional "year" matching functionality in word matching script
in thread Addional "year" matching functionality in word matching script

This second loop creates its own $title variable:

for my $title { print $title , " => ", find_year($title), "\n"; }

What you want instead is to integrate that call to find_year into your while loop:

while( <...>) { ... my ($title) = ...; print "Have title '$title'\n"; print $title , " => ", find_year($title), "\n"; };

Replies are listed 'Best First'.
Re^8: Addional "year" matching functionality in word matching script
by bms9nmh (Novice) on Jun 28, 2016 at 14:40 UTC
    Ok, thanks that's working nicely now that I'm printing it within the while loop. Is there any way to maintain the variable outside the while loop?

      Sure there is, but you will need to think about what value the variable should have after the while loop ends:

      my $year; while( my $title = <CSV3> ) { $year = find_year( $title ); }; print "I now have a year of '$year'\n";

      Do you really want to keep only one year from all the titles stored in your CSV file?

        ok, now that i know how to search the year in each title, I'm now looking into integrating this into my original script, my issue now is I don't know what every piece of my original script does (as I said I was helped putting it together). Does anyone know what the csv2hash bit does? There are a few #comments in the script which explain what each section does, but there are other bits that are blank which i don't fully understand. Could anyone break it down with comments just so I can get my head round it a bit easier?
        ah good point