Do you have multiple lines coming to STDIN?  If so, then your $idNumber is
probably getting blown away when the regex doesn't match later in the file.
If you only want the first line of the file, then remove the while.

If you have multiple lines that will match, you'll need a different
structure, saving to $idNumber will wipe out all but the last, and possibly
even (in this case for instance) the last one.

Please continue to ask questions in this thread, I think we're getting
closer to understanding your problem, so we can provide you with a solution
you'll be satisfied with.

                        /\/\ark

-----Original Message-----
From: lz [mailto:[EMAIL PROTECTED]]
Sent: Thursday, June 06, 2002 1:46 PM
To: David T-G; perl beginners
Cc: lz
Subject: Re: help with pattern matching/parsing


Hi David,

I do set the line, and thats why I am not sure, why it
doesn't work:

while ( $line = <STDIN> )
{
    $idNumber = $line =~ /\((ID\d+)\)/;
}

print $idNumber; // empty

Thanks again!
--- David T-G <[EMAIL PROTECTED]>
wrote:
> Leon --
>
> ...and then lz said...
> %
> ...
> % Here is a line from my file:
> % Dear Test Test1(ID127158),
> ...
> %
> % I use the following line, when I am reading the
> file:
> % ($idNumber) = $line =~ /\((ID\d+)\)/;
> %
> % For, some reasons idNumber is still empty....
>
> Do you actually read the line into $line?  My famous
> one-liner method
> shows
>
>   echo "Dear Test Test1(ID127158)," | \
>     perl -e 'while (<>) { $line = $_ ; \
>     ($id) = $line =~ /\((ID\d+)\)/; } \
>     print "$id\n";'
>   ID127158
>
> Note the while loop and the setting $line = $_ on
> the "perl -e" line;
> if you don't set $line, then the match won't have
> anything against which
> to work.
>
>
> %
> % Thanks again!
>
> HTH & HAND
>
>
> :-D
> --
> David T-G                      * It's easier to
> fight for one's principles
> (play) [EMAIL PROTECTED] * than to live up to
> them. -- fortune cookie
> (work) [EMAIL PROTECTED]
> http://www.justpickone.org/davidtg/    Shpx gur
> Pbzzhavpngvbaf Qrprapl Npg!
>
>

> ATTACHMENT part 2 application/pgp-signature



__________________________________________________
Do You Yahoo!?
Yahoo! - Official partner of 2002 FIFA World Cup
http://fifaworldcup.yahoo.com

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



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

Reply via email to