bottom posted...

-----Original Message-----
From: Jessica [mailto:[EMAIL PROTECTED]]
Sent: Tuesday, August 20, 2002 9:23 AM
To: [EMAIL PROTECTED]
Subject: need help extracting words from a string



I am such a knuckle head... I read the lists. I stumble through books and
still I cant figure out how to do something that I would think should be
relativly simple.

I am attempting to extract a two words or fields from every line of a tab
delimited file. Sometimes the words that I need are in fields 1 & 2 and
other time they are in 2 & 3. The lines look something like this:

TypeOfApp    ApplicationName     RunStatus
---------------------------------------------------------------------

application     run_me_now      complete                          <- Need 2
& 3
application2   ran_me_yesterday     complete/errors          <- Need 2 & 3
need_to_run_tomorrow     failed                                       <-
Need 1 & 2

I am in need of just extracting the ApplicationName and RunStatus from the
lines and placing them in variables so that I can do things with them.

I think I'm smart enought to know how to get the file opened and get the
lines into a while loop like so:

open (FILE, ./datafile);


while (<FILE>) {
do something really smart here
}

But its just the "do something really smart here" thats got me baffled...
(Grin)

Any help is greatly appreciated,

Jessica

----- end original message -----

okay, it looks like you only want the last two fields on the line
If you have header lines, you should strip those off before the while loop.
you should always doublecheck to make sure the file is opened successfully.

I would suggest:

while (<FILE>) {
    if (/([^\t]+)\t([^\t]+)$/) {
        $App = $1; $Stat = $2;
    }
}



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to