The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com




View Single Post in the UNIX and Linux Forums - Click on the Thread or Permalink to View Entire Thread -->
  #3 (permalink)  
Old 07-16-2008
KevinADC KevinADC is offline Forum Advisor  
Registered User
  
 

Join Date: Jan 2008
Posts: 731
Well, I did come up with this, but it may not be any more efficient than what you had and might even be less efficient, you would have to benchmark both codes to know which is really better.

Code:
my %files = map {/^(\w+).\d{6}\.csv$/; $_ => $1} <*.csv>;
print Dumper \%files;
foreach my $file (keys %files) {
  open(FH, $file) || die("Error: Cannot open file $file for reading.");
  while (<FH>) { 
    print "$files{$file} $_\n";
  }
  close(FH);
}
this regexp probably needs refining:

/^(\w+).\d{6}\.csv$/

what is the dot in there for after (\w+)?