Forum Moderators: coopster & phranque

Message Too Old, No Replies

XML::Parser help

         

Tonearm

5:03 pm on Sep 14, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Huge edit: I've got my problem narrowed down to this line of Perl:

next if (($line eq "")¦¦($line eq "\n")¦¦($line eq "\r")¦¦($line eq "\s"));

I get the following when trying to run perl -cw :

Unrecognized escape \s passed through at parsexml_temp.tag line 41.

Which refers to the above code. I know very little about Perl. Can anyone help me decipher this?

MonkeeSage

9:29 pm on Sep 14, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



In regular expressions the "\s" is the escape for a single white space, but I'm not sure if it can be used elsewhere...try...

...($line eq " "))

Jordan

Robber

12:15 pm on Sep 15, 2003 (gmt 0)

10+ Year Member



You could try changing to:
¦¦($line eq "\s"));

to

¦¦($line =~ /\s/));

This would use the \s in a regex rather than equality

Storyteller

2:50 am on Sep 18, 2003 (gmt 0)

10+ Year Member



Robber, this will check for existance of a single whitespace in the string, not its equality to it. He needs to use /^\s$/ to imitate the behavior of eq.

Tonearm

4:09 am on Sep 18, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Storyteller -

Would ($line eq " ") work or is ($line eq /^\s$/) better?

Storyteller

4:13 pm on Sep 18, 2003 (gmt 0)

10+ Year Member



Depends on what you want to do. The difference is that \s will match all whitespace, including tabs and newlines.

Tonearm

4:29 pm on Sep 18, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Ok, definitely good to know.

Can you tell me if there's anything wrong with this Perl:

$result.=$tag."=".$el."\n";
push @field,$tag;$tag="";

Storyteller

10:58 am on Sep 20, 2003 (gmt 0)

10+ Year Member



There's nothing wrong with it, although variable interpolation would make perfect sense here:

$result .= "$tag=$el\n";

Tonearm

5:15 pm on Sep 20, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Thanks Storyteller, I'm going to post a new thread called "XML parsing".

edit: No I'm not. I can't seem to get the script based on XML::Parser working so I'm going to give XML::Simple a try. Thanks for your help guys, it's in exchanges like this that I learn about Perl.