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

Re: XML File Slicing Golf(ish)

by ZZamboni (Curate)
on Jun 20, 2001 at 03:39 UTC ( #89866=note: print w/ replies, xml ) Need Help??


in reply to XML File Slicing Golf(ish)

This is what I came up with. It does essentially the same as your program, but it's a little bit shorter. Notice that I dropped the close altogether, because open automatically closes the file handle if it was previously opened (see perlopentut -- I wouldn't consider this a good programming practice, but I'm assuming this is a one-shot program here), so you don't have to keep track of whether file is open. Also, you don't need to read the whole file in memory at once.

use strict; my $n="0000"; while (<>) { if (/^<\?xml version/) { open OF, ">outfile_$n.xml" or die "open: $!\n"; $n++; } print OF $_; }

--ZZamboni


Comment on Re: XML File Slicing Golf(ish)
Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (6)
As of 2015-07-04 10:42 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (59 votes), past polls