Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re: Random sampling a variable length file.

by ambrus (Abbot)
on Dec 26, 2009 at 14:32 UTC ( [id://814424]=note: print w/replies, xml ) Need Help??

Help for this page

Select Code to Download


  1. or download this
    perl -we 'my $k = int(shift); my @a; my $l = 0; while (<>) { if ($l++ 
    +< $k) { push @a, $_ } else { if ((my $j = rand($l)) < $k) { $a[$j] = 
    +$_; } } } print @a;' 3 filename
    
  2. or download this
    $ cat a
    one
    ...
       1578 one six two 
       1578 four one three 
    $
    

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others wandering the Monastery: (3)
As of 2024-05-29 06:08 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found