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

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?
  • Comment on Re^8: Addional "year" matching functionality in word matching script

Replies are listed 'Best First'.
Re^9: Addional "year" matching functionality in word matching script
by Corion (Patriarch) on Jun 28, 2016 at 14:49 UTC

    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?

        %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__
      ah good point