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

If your data is as regular as it appears to be, a couple of splits instead of regexes will get the job done.
#!/usr/bin/perl -w use strict; while (<DATA>) { chomp; my ($basedir, @dot_names) = split(/\./,$_); my $type = (split('/',$basedir))[-1]; my $school = "null"; $school=$dot_names[-2] if (@dot_names >1); #open the file here and use the variables as prefix for each line print "type: $type school: $school\n"; } =prints type: abc school: null type: def school: null type: abc school: cole type: abc school: drew type: def school: cole type: def school: drew =cut __DATA__ /home/test/abc/.date_run_dir /home/test/def/.date_run_dir /home/test/abc/.date_file_sent.email@wolverine.cole.edu /home/test/abc/.date_file_sent.dp3.drew.net /home/test/def/.date_file_sent.email@wolverine.cole.edu /home/test/def/.date_file_sent.dp3.drew.net
  • Comment on Re: Help constructing proper regex to extract values from filenames and concurrently opening those same files to access records
  • Download Code

Replies are listed 'Best First'.
Re^2: Help constructing proper regex to extract values from filenames and concurrently opening those same files to access records
by JaeDre619 (Acolyte) on Dec 12, 2010 at 16:31 UTC
    @Marshall. Thanks! I can see how split can come in very handy as well. You made it look easy.