Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re: Need help with XML::Twig, something strange is happening!!

by rhesa (Vicar)
on Mar 28, 2007 at 13:55 UTC ( [id://607026]=note: print w/replies, xml ) Need Help??


in reply to Need help with XML::Twig, something strange is happening!!

Consider using the numerical comparison operators. You're dealing with numbers, so you shouldn't compare them as strings.

Try if ($ParentNodeId > 1) { instead of if ($ParentNodeId gt 1) {. Replace eq with ==.

While I'm here, can I suggest you use a hash for the input data, instead of that long list of variables? First define a list of field names:
my @field_names = qw/ ParentNodeId NodeId level canode label theme tem +plate /; # and so on for the rest
Then replace the split line with
my %attributes; @attributes{ @field_names } = split /,/, $line;
Then when you set the attributes on the XML::Twig::Elt, you can simply say:
$esec->set_att( %attributes );

Replies are listed 'Best First'.
Re^2: Need help with XML::Twig, something strange is happening!!
by stevee (Acolyte) on Mar 28, 2007 at 14:02 UTC
    Rhesa Thanks for the helpful suggestions. Replacing the operator has made no difference though I can see where you are coming from. The problem really lies in the XPATH statement.
    The other suggestion to use a hash is really good and I will look at that because, if nothing else, it saves typing!
    Thanks again.

    Stevee

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others rifling through the Monastery: (4)
As of 2024-04-23 20:55 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found