Beefy Boxes and Bandwidth Generously Provided by pair Networks Cowboy Neal with Hat
XP is just a number
 
PerlMonks  

randomize a text file

by perlnoobster (Sexton)
on Jul 17, 2013 at 13:26 UTC ( #1044804=perlquestion: print w/ replies, xml ) Need Help??
perlnoobster has asked for the wisdom of the Perl Monks concerning the following question:

Hi monks, I have a file called output.txt it contains thousands of rows of text separated by columns, all i need is for the output to be randomized, is this possible? (without installing a module) Thank you

Comment on randomize a text file
Re: randomize a text file
by toolic (Chancellor) on Jul 17, 2013 at 13:28 UTC
Re: randomize a text file
by BrowserUk (Pope) on Jul 17, 2013 at 13:46 UTC

    How do you want it randomised?

    Given:

    a b c d e f g h i j k l m n o p q r s t u v w x y

    Do you want (randomise rows; columns stay the same):

    k l m n o u v w x y f g h i j p q r s t a b c d e

    Or (randomise the columns; rosw stay the same):

    c b d e a h g i j f m l n o k r q s t p w v x y u

    Or (randomise both):

    h g i j f w v x y u c b d e a r q s t p m l n o k

    With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.
      Hi BrowserUk, I want to randomize the rows, i.e. the columns stay the same, can you help me? thank you
        , can you help me?

        Depends. Post code that reads the file into an array, then maybe.


        With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
        Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
        "Science is about questioning the status quo. Questioning authority".
        In the absence of evidence, opinion is indistinguishable from prejudice.

        If you want to randomize rows only, read your file into an array of rows, apply shuffle from List::Util and print shuffled array into new file. That's all, probably just a one-liner, don't even need to chomp.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (10)
As of 2014-04-17 07:35 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    April first is:







    Results (440 votes), past polls