>>> Why don't use perl "s" operator with "e" option ?
>>>
[quoted text clipped - 7 lines]
> I am not only expanding a variable but also using that expanded variable as
> a key to ultimately find the value. That's why I need "e".
A single hash element is a scalar variable, and John is correct that you don't
need the /e option to interpolate it if you key it properly with $1 instead of
\1. Try it.
> Secondly, inside text that is to be substituted, I can use \1 as well. And
> moreover, for this, I don't need double quotes. If i purposefully
> incorporate double quotes, then I need $1.
John's point wasn't that double-quotes were needed, but that right-hand side of
a substitution behaves as a double-quoted string. I don't understand why you
think you need $1 if you somehow involve double quotes explicitly.
This is from
perldoc perlre
You would do well do read and understand it so that your advice on this group
can agree with the documentation.
> Warning on \1 vs $1
> Some people get too used to writing things like:
[quoted text clipped - 19 lines]
> with the operation of matching a backreference. Certainly they mean two
> different things on the *left* side of the "s///".
In addition,
- The usual way of writing /([^ ]+)/ is /(\S+)/, and although the two are
slightly different I doubt if you wanted your class to include tabs and
formfeeds?
- Your code will simply delete any word in the string that doesn't appear as a
hash key, and will also throw warnings each time it does it.
Rob

Signature
To unsubscribe, e-mail: beginners-unsubscribe@perl.org
For additional commands, e-mail: beginners-help@perl.org
http://learn.perl.org/