in reply to Need explanation: what \$_ and ${} do

Need explanation
me too!
Could anyone explain what is going on in the following code.
$x = '<act aid = "s">'; $x=~s/<([^>]*)>/'<'.${($_=$1)=~s|\s*\=\s*|=|gs +i,\$_}.'>'/egsi; print $x;
The above code is used to remove the spaces before and after equal sign.
I guess it does something more, for in that case
s/\s+=\s+/=/; # would suffice!
Whatever, it is a substitution that in the substitution part executes code performing a further substitution. Hence it's probably not the cleanest way to do what that it does (but indeed a concise one). Note that the inner part does essentially what that I do above...
I could not understand what that \$_ and ${} does
\$_ takes a scalar reference of $_. ${} dereferences it for the purpose of interpolating it. perldoc perlref will explain all this to you much better than I ever could!!

Replies are listed 'Best First'.
Re^2: Need explanation: what \$_ and ${} do
by Roy Johnson (Monsignor) on Nov 11, 2005 at 15:27 UTC
    For a while, all the winning solutions on the Perl golf site (not available, last I checked :-() were substitutions-within-substitutions. So my conjecture is that this comes from a golf. Or someone who is very golf-oriented.

    Caution: Contents may have been coded under pressure.