On 10/19/07, Joseph L. Casale <[EMAIL PROTECTED]> wrote:

> open (FILEOUT, "> $OutDir/info") or die $!;
> print FILEOUT "text         =              abc\n";
> my $Tmp = ++$#files;

Huh?

> print FILEOUT "moretext              =              $Tmp\n";

> When I add the 3rd line, it initializes the files array and I can't use it 
> after?
> Why is that?

Because you incremented $#files, which is the last array index.
Incrementing $#files changes the array much as if you pushed an undef
value onto the end of the array, since the last array index is now one
larger.

If you merely wish to find out the size of the array, without changing
it, don't use the ++ (autoincrement) operator. Maybe you meant to
write this:

  my $size = @files;
  print FILEOUT "moretext       =      $size\n";

Using the "name" of an array (@files) in a scalar context gives the
number of elements in the array. (That's what you got by using the
concatenation dot on @files, too.) Also, it's nice for clarity to give
a variable a name that reflects its contents.

Hope this helps!

--Tom Phoenix
Stonehenge Perl Training

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/


Reply via email to