in reply to LWP::Simple and Read-only Values

I don't get this error. Are you sure the code you posted is the code that is causing the error?

--Bob Niederman, http://bob-n.com

Replies are listed 'Best First'.
Re: Re: LWP::Simple and Read-only Values
by Anonymous Monk on Jul 13, 2003 at 02:43 UTC
    No, it is not the exact same code. The exact code includes this:
    $asdf =~ /(asdf)/; $1 =~ s/asdf//;

    In other words, I was trying to modify the special variable $1. Once I set $1 to something else, the code worked like a charm. Why can't I do substitutions on $1?

      You can't modify $1 because it's a read only variable. It doesn't make sense to make it a writeable variable because it's only ever supposed to contain the first capture from the most recently successful match.

      That may not be the most convincing explanation, but that's the official reason. If you could modify the magic global captures, should or shouldn't it affect the matched string itself? That's pretty tricky and, pragmatically, it's a stone better left unturned.

      3rd edition of Camel flags these ($1, $2, etc.) clearly as readonly, as does perldoc perlvar

      --Bob Niederman, http://bob-n.com