in reply to =~ and substitutions

I can't see why you didn't get the error "Modification of a read-only value attempted" when you tried to substitute using $1. Variables like that are only used for reading the results of a match, and they only work if capturing parentheses are used. For example:
if($line =~ /(test)/) { print $1,"\n"; }
That would print a line saying "test" for each line containing the string "test"

It's not clear from your post what you mean by "just what I'm trying to get." Would you please clarify what you are trying to do?

Replies are listed 'Best First'.
Re: Re: =~ and substitutions
by sulfericacid (Deacon) on Mar 03, 2003 at 20:02 UTC
    Let's say I am searching for the word "test", when the results are brought back it brings back the entire line of code with "test" inside rather than just the single word I was looking for. And my substition isn't removing the code tags when all I want is the text.

    "Age is nothing more than an inaccurate number bestowed upon us at birth as just another means for others to judge and classify us"

    sulfericacid
      Ok, here's a sample program with some input data and resulting output. Is this what you mean?
      use strict; my @lines = <DATA>; my $line; foreach $line (@lines) { if($line =~ /(test)/) { print $1,"\n"; $line =~ s/<p>//gi; } if($line =~ /meta/) { print "$line" }; } __END__ test <p> hello meta fadfdsa <p> meta fadfasd test test <P> test meta <p> fdafasdg
      Every line containing "test" will cause a line with the word "test" in the output. Lines containing "test" and "meta" will have paragraph code tags stripped. Lines containing "meta" alone will be printed unchanged. Other lines will be skipped.
      test test hello meta fadfdsa <p> meta test test test test meta