Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Is there a Perl5 module on CPAN that provides a function analogous to the Perl6 list-repeat operator?

by molecules (Monk)
on Aug 11, 2010 at 15:11 UTC ( #854411=perlquestion: print w/ replies, xml ) Need Help??
molecules has asked for the wisdom of the Perl Monks concerning the following question:

I just wanted to know before I decided to create one. I tried searching but haven't found one.

UPDATE:
In Perl6 the operator xx will create a list of any number of items that you would like. For example:
use v6; my @array = (1) xx 5;
is the same as
use v6; my @array = (1, 1, 1, 1, 1);
You can achieve the same thing in Perl5 using x (thanks kennethk and ikegami):
#perl5 my @array = (1) x 5;
I previously thought that x only created strings.

Comment on Is there a Perl5 module on CPAN that provides a function analogous to the Perl6 list-repeat operator?
Select or Download Code
Re: Is there a Perl5 module on CPAN that provides a function analogous to the Perl6 list-repeat operator?
by kennethk (Monsignor) on Aug 11, 2010 at 15:18 UTC
Re: Is there a Perl5 module on CPAN that provides a function analogous to the Perl6 list-repeat operator?
by ikegami (Pope) on Aug 11, 2010 at 15:28 UTC
    I'm not sure what that operator is, so here are two possibilities.

    If you want multiple copies of the same value,

    ( EXPR ) x $x # Parens required

    If you you want to generate multiple values from the same expression,

    map { EXPR } 1..$x

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (8)
As of 2014-09-21 11:16 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (168 votes), past polls