Brent Clark wrote:
Hi all

Think I have a better unstanding of the use of () for my regex search, but this morning I have a new set of problems, whereby I need to perform a search and replace and then pass on to the new variable.

My current code is as so, and works:

$_ =~ s/(^\w+\.dat\|)//;                            my $lineExtract = $_;

But I would like to have it a one liner.

I tried:

my ($lineExtract) = ($_ =~ s/(^\w+\.dat\|)//);
and
$lineExtract = ($_ =~ s/(^\w+\.dat\|)//);


($lineExtract) = /^\w+\.dat\|(.+)$/o;

s/(^\w+\.dat\|)//o says you want to remove all the \w+.dat| stuff
from the string in $_ and store it in $1;

If you want $lineExtract to be what is left after it's striped of the \w+\.dat\| then you only need to use the line above.

If you want $lineExtract to contain the material that has been removed then you want:
$lineExtract = /(^\w+\.dat\|)/o

If you want both... could you do this:

($lineExtract, $_) = /(^\w+\.dat\|)(.+)$/o;

I think it would work, but you'll want to test it.

(I like to add the regex option 'o' at the end 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