Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Re: Need explanation: what \$_ and ${} do

by chester (Hermit)
on Nov 11, 2005 at 15:21 UTC ( #507742=note: print w/ replies, xml ) Need Help??


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

Slightly off-topic, that code is really ugly. First because you shouldn't use regexes to parse XML. Second, the s and i modifiers on the regex aren't doing anything. Third, the use of e is really unnecessary. You could probably rewrite that line like this (untested):

$x =~ s/( < [^>]+ ) \s+=\s+ ( [^>]+ > )/$1=$2/gx;


Comment on Re: Need explanation: what \$_ and ${} do
Select or Download Code
Re^2: Need explanation: what \$_ and ${} do
by Tanktalus (Canon) on Nov 11, 2005 at 15:29 UTC

    Small side note: yes, you shouldn't use regexes to parse XML. However, in a case such as $x = '<act aid = "s">';, where it's not valid XML, you must clean it up before you can use a real XML parser to do anything with it.

Re^2: Need explanation: what \$_ and ${} do
by polettix (Vicar) on Nov 11, 2005 at 15:31 UTC
    Why the "s" modifier does not do anything?

    Flavio
    perl -ple'$_=reverse' <<<ti.xittelop@oivalf

    Don't fool yourself.
          s   Treat string as single line. That is, change "." to match any
              character whatsoever, even a newline, which normally it would not
              match.

      There are no .'s in the regex.

        ... which makes me learn that [^>] does match a newline :)

        Thanks for bothering, chester!

        Flavio
        perl -ple'$_=reverse' <<<ti.xittelop@oivalf

        Don't fool yourself.
Re^2: Need explanation: what \$_ and ${} do
by Aristotle (Chancellor) on Nov 11, 2005 at 15:43 UTC

    No, you can’t, unless all of your tags have only one attribute. The susbtitution you give will remove the spaces around the first equals sign within the tag, but will skip any other equals signs.

    Makeshifts last the longest.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://507742]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (7)
As of 2014-12-22 03:35 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (110 votes), past polls