Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses

Re^4: Why XML not well formed?

by nan (Novice)
on Jul 06, 2005 at 17:04 UTC ( #472882=note: print w/replies, xml ) Need Help??

in reply to Re^3: Why XML not well formed?
in thread Why XML not well formed?

Hi Don,

Sorry I used $line =~ s/(&)/(& amp;)/g; would it be different with yours?

Many thanks, Nan

Replies are listed 'Best First'.
Re^5: Why XML not well formed?
by BaldPenguin (Friar) on Jul 06, 2005 at 17:32 UTC
    First, the parens in the pattern part of the regex collect the value we find, then the $1 in the replace puts it back in. In that respect the follwing regex would do nothing but spin cycles;
    $line =~ s/(&)/$1/g;
    So, in your regex the first set of parens save the & for later use. But you don't use it, instead you find all of the &s and replace them literaly with "(&)" including the parens.

    That said, the regex I posted would work only if no other entites existed. Take a look at the other regexs above, they do a better job of 'thinking' ahead, to prevent possible errors in the future.

    Somebody could, and I have seen it done, place other entities in the url, such as:éal
    In this case the regex I posted would tranlate to Montréal. Not what you want.


    Edit by castaway: Closed small tag in signature

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (7)
As of 2023-02-02 14:21 GMT
Find Nodes?
    Voting Booth?
    I prefer not to run the latest version of Perl because:

    Results (19 votes). Check out past polls.