Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > Randomise splitting file into two new files

Reply
Thread Tools

Randomise splitting file into two new files

 
 
Bumble
Guest
Posts: n/a
 
      01-27-2004
Hey all! Basically I require a program that will take a file full records (1
per line) and then output these lines into 2 new files, randomly. Anyone
know of such a program already in existence?

--
Bumble

"I'm flat out, you're so beautiful to look at when you cry. Freeze don't
move, you've been chosen as an extra in the movie adaptation of the sequel
to your life. Shady Lane, everyone wants one, Shady Lane, everybody needs
one" - Pavement


 
Reply With Quote
 
 
 
 
ctcgag@hotmail.com
Guest
Posts: n/a
 
      01-27-2004
"Bumble" <(E-Mail Removed)> wrote:
> Hey all! Basically I require a program that will take a file full records
> (1 per line) and then output these lines into 2 new files, randomly.
> Anyone know of such a program already in existence?


open F1, ">", pop or die $!;
open F2, ">", pop or die $!;
while (<>) {
if (rand()<0.5) {
print F1 $_;
} else {
print F2 $_;
};
};
close F1 or die $!;
close F2 or die $!;

Xho

--
-------------------- http://NewsReader.Com/ --------------------
Usenet Newsgroup Service New Rate! $9.95/Month 50GB
 
Reply With Quote
 
 
 
 
Bumble
Guest
Posts: n/a
 
      01-27-2004
http://www.velocityreviews.com/forums/(E-Mail Removed) wrote:
>
> open F1, ">", pop or die $!;
> open F2, ">", pop or die $!;
> while (<>) {
> if (rand()<0.5) {
> print F1 $_;
> } else {
> print F2 $_;
> };
> };
> close F1 or die $!;
> close F2 or die $!;
>
> Xho


Many thanks! Didn't realise it was so straight forward!! It's working great.

--
Bumble
http://bumble.rumble.at
http://www.cossar.co.uk

"I'm flat out, you're so beautiful to look at when you cry. Freeze
don't move, you've been chosen as an extra in the movie adaptation of
the sequel to your life. Shady Lane, everyone wants one, Shady Lane,
everybody needs one" - Pavement


 
Reply With Quote
 
John W. Krahn
Guest
Posts: n/a
 
      01-27-2004
Bumble wrote:
>
> Hey all! Basically I require a program that will take a file full records (1
> per line) and then output these lines into 2 new files, randomly. Anyone
> know of such a program already in existence?


my @fh;
open $fh[ $_ ], '>', "test44_$_.txt" or die $! for 0, 1;
print { $fh[ rand @fh ] } $_ while <>;



John
--
use Perl;
program
fulfillment
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
splitting one dictionary into two jsaul Python 7 04-02-2004 08:58 AM
Re: Splitting up the definitions of a class into different files (splitting public from private)? John Dibling C++ 0 07-19-2003 04:41 PM
Re: Splitting up the definitions of a class into different files (splitting public from private)? Mark C++ 0 07-19-2003 04:24 PM
Re: Splitting up the definitions of a class into different files (splitting public from private)? John Ericson C++ 0 07-19-2003 04:03 PM
Re: Splitting big .mp3 file into smaller files? °Mike° Computer Support 0 06-27-2003 06:00 PM



Advertisments