in reply to Re: Help constructing proper regex to extract values from filenames and concurrently opening those same files to access records
in thread Help constructing proper regex to extract values from filenames and concurrently opening those same files to access records

Thank you. This is great. Thanks a lot for breaking down that cryptic regex as well. I did try and test this, but had some issues with:
# do extra check that $school is acceptable $school //= 'null'; # regex gives undef if not found
Error msg:

Search pattern not terminated

I commented that out and it run, although it had these errors:

match: /home/test/abc/.date_run_dir type: abc Use of uninitialized value in concatenation (.) or string at ./test7.p +l line 31, <$_[...]> line 1. school: match: /home/test/def/.date_run_dir type: def Use of uninitialized value in concatenation (.) or string at ./test7.p +l line 31, <$_[...]> line 2. school:

Also would you pls show me to extract values from the files I match? Can I do this in the same pass that I peform the regex? Example values from file (.date_run_dir, etc)

$ cat .date_run_dir .date_file_sent.* /project/school/data/feed_abc_2010120816.ext3 mail_abc.dat.2010120816.ext3 mail_abc.dat.2010120816.ext3
  • Comment on Re^2: Help constructing proper regex to extract values from filenames and concurrently opening those same files to access records
  • Select or Download Code

Replies are listed 'Best First'.
Re^3: Help constructing proper regex to extract values from filenames and concurrently opening those same files to access records
by Anonymous Monk on Dec 11, 2010 at 22:10 UTC
    Oh, sorry about that error. //= is only in Perl 5.10.0 and later, and I should have noted that. The statement is equivalent to $school = 'null' unless defined $school;

    For the values inside the listed files, you could use a similar regex (or build it and the original from another which contains the common parts of both) inside that inner while loop, yes?

      I wouldn't need another regex inside the while loop. At this point, the regex you helped me with list all the files I need to read in at the same time extracting those particular keys I wanted. Now, since I'm already in I wouldn't need another regex. I just need to open the filenames and get the values. I hope I am making sense.

      Would I do this within the while loop of the of the if (DEBUG) section?

      UPDATE:

      Nevermind. Thanks for your help! This does what I need it to do. I haven't really used DEBUG before. Once I changed it to 1 it does what I need to do. This is a cool script. I can always use that debug technique. Thanks for showing me the ways.