Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

how to print continuously in array of array?

by virudinesh (Acolyte)
on May 30, 2013 at 09:47 UTC ( [id://1036014]=perlquestion: print w/replies, xml ) Need Help??

virudinesh has asked for the wisdom of the Perl Monks concerning the following question:

my @stuff = ( ['one', 'two', 'three', 'four'], [7, 6, 5], ['apple', 'orange'], [0.3, 'random', 'stuff', 'here', 5], ); print $stuff[0][2], "\n"; print $stuff[3][1], "\n";

its only print three and random

but i want to print randomly how?

how to print one by one continuously in full array

Replies are listed 'Best First'.
Re: how to print continuously in array of array?
by marto (Cardinal) on May 30, 2013 at 10:05 UTC

    "its only print three and random"

    This is all you've asked it to print:

    print $stuff[0][2], "\n"; # prints three print $stuff[3][1], "\n"; # prints random

    Something like:

    #!/usr/bin/perl use strict; use warnings; use Data::Dumper; my @stuff = ( ['one', 'two', 'three', 'four'], [7, 6, 5], ['apple', 'orange'], [0.3, 'random', 'stuff', 'here', 5], ); print Dumper \@stuff;

    Or this solution from one of your previous threads? Again if the previous answers don't do what you require it'd be wise to follow them up rather than posting essentially the same questions again and again.

    Update: or here a few minutes before this thread.

Re: how to print continuously in array of array?
by karlgoethebier (Abbot) on May 30, 2013 at 11:32 UTC
Re: how to print continuously in array of array?
by choroba (Cardinal) on May 30, 2013 at 11:38 UTC
    Do you mean something like this?
    #!/usr/bin/perl use warnings; use strict; my @ar = (qw/a b c/, [ 'level 1', 'level 1b', [ 'level 2', 'level 2b', [ 'level 3', [ 'level 4', [[ 'level 6 ']] + ]]]]); sub flatten { return map ref $_ ? flatten(@$_) : $_, @_; } print join ', ', flatten @ar;
    لսႽ† ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ
Re: how to print continuously in array of array?
by space_monk (Chaplain) on May 30, 2013 at 15:32 UTC

    The simplest way to write questions in future is to show what you expected to happen or what you want to happen.

    e.g. I wrote this program.
    # my code here # make sure your code has use strict; use warnings;

    In the above program, the data is in the array/hash/other data structure because....(give a reason here)

    I wanted it to output the following:

    # what I expected it to print
    But instead I got;
    # what the program really did
    If you spot any bugs in my solutions, it's because I've deliberately left them in as an exercise for the reader! :-)
Re: how to print continuously in array of array?
by 2teez (Vicar) on May 30, 2013 at 11:43 UTC

    #how to print one by one continuously in full array my $counter = 0; foreach my $array (@stuff){ print "ARRAY [ ", $counter++ ," ]: "; foreach my $data (@$array){ print $data,' '; } print $/; } #OR print join " ", map{@$_} @stuff[0..$#stuff];
    but i want to print randomly how?
    You should be able to do that now, however, don't forget the function rand

    If you tell me, I'll forget.
    If you show me, I'll remember.
    if you involve me, I'll understand.
    --- Author unknown to me
Re: how to print continuously in array of array?
by ambrus (Abbot) on May 30, 2013 at 20:11 UTC

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others musing on the Monastery: (4)
As of 2024-04-19 17:39 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found