in reply to Need explanation: what \$_ and ${} do
Need explanationme too!
Could anyone explain what is going on in the following code.I guess it does something more, for in that caseThe above code is used to remove the spaces before and after equal sign.$x = '<act aid = "s">'; $x=~s/<([^>]*)>/'<'.${($_=$1)=~s|\s*\=\s*|=|gs +i,\$_}.'>'/egsi; print $x;
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...s/\s+=\s+/=/; # would suffice!
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 |