Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re: file handling error

by dHarry (Abbot)
on Sep 16, 2010 at 15:46 UTC ( [id://860368]=note: print w/replies, xml ) Need Help??


in reply to file handling error

I agree with Javafan. Your code is a bit messy and difficult to make sense of. Starting from scratch might not be such a bad idea. In general if you have to deal with XML documents it's better to use a parser, e.g. XML::LibXML. The way you do it often backfires, a slight change to the xml format probably means "surprise".

Replies are listed 'Best First'.
Re^2: file handling error
by sundialsvc4 (Abbot) on Sep 16, 2010 at 18:49 UTC

    My “wisdom” on this issue is that ... there ought to be a big sign pasted over the doorway that leads to “the way you’re trying to do it now.”   That sign would read:

    Through me you pass into the city of woe:
    Through me you pass into eternal pain:
    Through me among the people lost for aye.

    Justice the founder of my fabric mov'd:
    To rear me was the task of power divine,
    Supremest wisdom, and primeval love.

    Before me things create were none, save things
    Eternal, and eternal I endure.
    All hope abandon ye who enter here.

    “The right way to do it ... the only way to do it ...” is with an XML parser (package from CPAN).   If you take something like, say, XML::Simple, this will be able to parse the XML into a hashref structure.   You can then manipulate that structure any way you need to.   Then, write it out.

    When writing processing routines like this, I always try to follow two principles:

    1. Always write the output to a different file than the input.   This gives you two generations of the data:   “before,” and “after.”
    2. Sounds silly, but ...   make very sure that the manipulation that you are supposed to be doing, has not already been done.   Write the code to be very defensive.   Make it examine the data, looking for trouble.   Make it respond gracefully and robustly in all circumstances.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others perusing the Monastery: (5)
As of 2024-04-18 05:27 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found