Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > is there a compact way to initialize this array?

Reply
Thread Tools

is there a compact way to initialize this array?

 
 
DaLoverhino
Guest
Posts: n/a
 
      09-09-2009
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.
 
Reply With Quote
 
 
 
 
Uri Guttman
Guest
Posts: n/a
 
      09-09-2009
>>>>> "D" == DaLoverhino <(E-Mail Removed)> 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.velocityreviews.com/forums/(E-Mail Removed) -------- http://www.sysarch.com --
----- Perl Code Review , Architecture, Development, Training, Support ------
--------- Gourmet Hot Cocoa Mix ---- http://bestfriendscocoa.com ---------
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Is there a better and fast way to initialize a dynamic array? jerry C Programming 13 10-01-2011 12:49 PM
Is there a way to get a method to always run at the end of anydescendent's initialize method? Xeno Campanoli Ruby 9 02-14-2010 03:49 AM
if instance variable get initialize after assigning some values or after constructor then when does static variable get initialize Tony Morris Java 3 02-04-2006 08:39 AM
Okay... compact film vs compact digital .. Mike Henley Digital Photography 15 06-22-2004 07:32 PM
Is there a way to use "def self.new" to do the job of "def initialize"? Sean Ross Ruby 3 12-25-2003 04:59 AM



Advertisments