Re: Iterating over Arrays

[email protected] (Ken Peng)
Newsgroups 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?
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.