is there a compact way to initialize this array?

Discussion in 'Perl Misc' started by DaLoverhino, Sep 9, 2009.

  1. DaLoverhino

    DaLoverhino Guest

    I want to initialize an array with 100 empty strings.

    I can use a loop, but is there a more compact way to do so?

    thanks.
     
    DaLoverhino, Sep 9, 2009
    #1
    1. Advertising

  2. DaLoverhino

    Uri Guttman Guest

    >>>>> "D" == DaLoverhino <> writes:

    D> I want to initialize an array with 100 empty strings.
    D> I can use a loop, but is there a more compact way to do so?

    my @empty = ('') x 100 ;

    and you likely don't need to do that if you are appending text as each
    entry will autovivify. .= works cleanly and quietly (no warnings) on
    undef values.

    uri

    --
    Uri Guttman ------ -------- http://www.sysarch.com --
    ----- Perl Code Review , Architecture, Development, Training, Support ------
    --------- Gourmet Hot Cocoa Mix ---- http://bestfriendscocoa.com ---------
     
    Uri Guttman, Sep 9, 2009
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    9
    Views:
    343
    Kai-Uwe Bux
    Nov 22, 2006
  2. Protoman
    Replies:
    28
    Views:
    782
    Protoman
    Jul 5, 2007
  3. jerry
    Replies:
    13
    Views:
    878
    Malcolm McLean
    Oct 1, 2011
  4. Sean Ross
    Replies:
    3
    Views:
    134
    Aredridel
    Dec 25, 2003
  5. Xeno Campanoli
    Replies:
    9
    Views:
    153
    Aaron Patterson
    Feb 14, 2010
Loading...

Share This Page