Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re: How do I split a file into parts

by galande (Initiate)
on Nov 23, 2000 at 10:00 UTC ( [id://43094]=note: print w/replies, xml ) Need Help??


in reply to How do I split a file into parts

Hi,
If you want to split one file into lot of files use that pattern as your record separator, that is $/.
Try this one ...
#! /usr/bin/perl -w my $infil = $0; my $separator = "XXFFDDF"; local $/ = $separator; sysopen(INFIL,$infil,O_RDONLY) || die "Can't open $infil: $!.\n"; while(<INFIL>){ my $out_file = "$infil.$."; # s/$separator//; ### if you want to remove your file separator also, uncomment above li +ne ..... sysopen(OUT,$file,O_RDWR|O_CREAT|O_EXCL) || die "Can't open for wri +te tst.$.: $!.\n"; print OUT $_; } close(INFIL);

Replies are listed 'Best First'.
Re: Answer: How do I split a file into parts
by repson (Chaplain) on Nov 23, 2000 at 17:55 UTC
    This code would work fine but has the disadvantage of storing an entire file of data in $_. While the file you are splitting would not be likely to have huge sections between the $seperator's you might never know if the code could be used in a situation where we are placing large amounts of data into memory.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (4)
As of 2024-09-09 01:33 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?
    erzuuli‥ 🛈The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.