Re: Iterating over Arrays

Ken Peng <[email protected]>
Newsgroups gmane.comp.lang.perl.beginners
Message-ID <[email protected]>
Hello

Try with this code:

use strict;
use warnings;
use Data::Dumper;

my @words = ("this","that");

# With this code
$words[5] = "bad idea";

print Dumper \@words;

And it outputs:

$VAR1 = [
           'this',
           'that',
           undef,
           undef,
           undef,
           'bad idea'
         ];


so $words[2], $words[3], $words[4] have been defined as undef automatically.

You'd better use a "push" method for a list operation like this.

Thanks


William Torrez Corea wrote:
> What happen with my code?

-- 
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
http://learn.perl.org/
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.