home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.perl
- Path: sparky!uunet!munnari.oz.au!yarra-glen.aaii.oz.au!pem
- From: pem@yarra-glen.aaii.oz.au (Paul E. Maisano)
- Subject: LVALUE =~ EXPR ?
- Message-ID: <1992Aug29.053235.3664@yarra-glen.aaii.oz.au>
- Organization: Australian Artificial Intelligence Institute
- Date: Sat, 29 Aug 1992 05:32:35 GMT
- Lines: 55
-
- [Apologies if anyone receives this message twice...]
-
- I was rather expecting (hoping for?) this to work:
-
- ($x = 'ab') =~ (s/a/A/, s/b/B/);
- print "$x\n";
-
- I was expecting the output to be "AB".
- I thought the =~ would modify the context for the whole RHS.
- Well, to be honest, I was expecting either that or a syntax error.
-
- There was no syntax error but it did not do what I expected either.
- I read the manual to see what it said but I found it a little hard to
- work out exactly what it meant.
-
- [Here is what it says to save you the trouble of looking it up.
-
- =~ Certain operations search or modify the string "$_"
- by default. This operator makes that kind of opera-
- tion work on some other string. The right argument
- is a search pattern, substitution, or translation.
- The left argument is what is supposed to be
- searched, substituted, or translated instead of the
- default "$_". The return value indicates the suc-
- cess of the operation. (If the right argument is an
- expression other than a search pattern, substitu-
- tion, or translation, it is interpreted as a search
- pattern at run time. This is less efficient than an
- explicit search, since the pattern must be compiled
- every time the expression is evaluated.) The pre-
- cedence of this operator is lower than unary minus
- and autoincrement/decrement, but higher than every-
- thing else.]
-
- Does anyone think the above should work ?
-
- Or are we stuck with:
-
- $x = 'ab';
- $x =~ s/a/A/;
- $x =~ s/b/B/;
-
- Or more likely,
-
- $_ = 'ab', s/a/A/, s/b/B/;
-
- I really like the way perl lets you change the context for substitions
- (and matches and translates) using =~ (I find it quite intuitive) but
- I was hoping it was a little more general.
-
- -paul
-
- ---
- Paul Maisano pem@aaii.oz.au
- Australian Artificial Intelligence Institute
-