Thomas Bätzler wrote:
Brent Clark <[EMAIL PROTECTED]> asked:

I have a CSV file and on every line, I have a line like so:

lts.dat|somedata
lts001.dat|somemoredata


Generally, you can capture data from a RE with a pair
of brackets around the relevant expression, and the
data is then available in the variables $1..$9 for up
to 9 pairs of brackets. You can also use the fact that
a match in list context will return the catured fields
as a list like this:

open( IN, $csvfile ) or die "Can't open '$csvfile': $!";

while( my $line = <IN> ){

  if( my( $filename ) = ( $line =~ m/^(.*?)\|/ ) ){
    print "file: $filename\n";
} else { warn "line '$line' did not match\n";
  }
}

HTH,
Thomas


I was thinking of using /^([^|]+)\|/ instead.
Also, is there any reason NOT to end the regex with /o to improve performance?

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to