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

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?

Replies are listed 'Best First'.
Re^10: Addional "year" matching functionality in word matching script
by bms9nmh (Novice) on Jun 28, 2016 at 15:22 UTC
    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?

      %csv2hash is a hash.

      The programmer is loading the record into the key of the hash, %csv2hash. The value of the hash is the title.

      The test program below demonstrates just that small task for one record. The programmer (i.e., the programmer that wrote this program originally) populates %csv2hash with all of the records in the file named csv2.

      #!/usr/bin/perl # csv2hash.pl perl csv2hash.pl A test program. # From http://www.perlmonks.org/?node_id=1166649 use strict; use warnings; my %csv2hash = (); + my $record = q[12278788, TV & SATELLITE WEEK 11 MAY 2013 GILLIAN ANDER +SON DOCTOR WHO NOT RADIO TIMES , http://www.example.co.uk, 12]; $_ = $record; my ($title) = $_ =~ /^.+?,\s*([^,]+?),/; #/ match the title + $csv2hash{$_} = $title; use Data::Dumper; print Dumper(%csv2hash); __END__
        Ok cheers, last question for a while while I try and learn some of this stuff, I'm currently watching some youtube videos on hash function, but what does the {$_} bit do in the  $csv2hash{$_} = $title part?
Re^10: Addional "year" matching functionality in word matching script
by bms9nmh (Novice) on Jun 28, 2016 at 14:50 UTC
    ah good point