Try the following (this is just a short example)

#!/usr/bin/perl -w

use strict;

# Open the file
open (IN, "<your_file.csv") or die "Oops unable to read the file error: " . 
$!;
# Loop thru the fill till the bitter end
while (<IN>) {
 chomp; # Make sure there is no funny stuff at the end (not really needed in 
this example though)
 my ($temp) = $_ =~ /^(.*)\|.*$/; ($_ holds the line so we match the stuff 
we want to have and put it in $temp)
 print $temp . "\n"; # because I had no other things to do with this just 
print it to screen
}

close IN; # Close the file.

Note that both warnings and strict is used in this application just as a for 
of good practice, at first it will make things more difficult but soon 
enough you will see that any good perl programer will not even start typing 
without enabeling both.


On 7/21/05, Brent Clark <[EMAIL PROTECTED]> wrote:
> 
> Hi list
> 
> I was hoping someone would be so kind as to help me with this.
> 
> I have a CSV file and on every line, I have a line like so:
> 
> lts.dat|somedata
> lts001.dat|somemoredata
> 
> I basically would like to ONLY get the name of the file before the first
> pipe.
> 
> I was thinking that the regex would look something like so
> 
> /^*\|/ # Get the beginning of the CSV file, extract the filename, to
> #the first pipe
> 
> but I need to extract and pass the value to a variable.
> 
> Would anyone have any tips or advise on this.
> 
> Kind Regards
> Brent Clark
> 
> --
> 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