On Jan 13, Keith Nasman said:

>@a = qw/this is the text/;
>$a = "three";
>print "The third word is ${a}[2]\n";
>print "The third word is $a[2]\n";
>
>produce this:
>
>The third word is three[2]
>The third word is the

The reason "three" is printed is because "${a}[2]" is another way of
writing $a . "[2]" -- that is, you're explicitly separating the $a from
the [2], so that Perl doesn't think you're using an array.

>use strict;
>
>my @a = qw/this is the text/;
>my $a = "three";
>print "The third word is ${a}[2]\n";
>print "The third word is $a[2]\n";

>Use of uninitialized value in concatenation (.) at ./test.pl line 7.
>The third word is [2]
>The third word is the

This feels like a bug to me.

  jefpin@towers [10:36am] ~ #219> bleadperl
  $x = "THIS";
  my $x = "THAT";
  print "${x} ${x}[2]\n";
  THAT THIS[2]

I don't see why Perl accesses the GLOBAL $x when printing "${x}[2]".  I
will file this as a bug.

-- 
Jeff "japhy" Pinyan      [EMAIL PROTECTED]      http://www.pobox.com/~japhy/
RPI Acacia brother #734   http://www.perlmonks.org/   http://www.cpan.org/
** Look for "Regular Expressions in Perl" published by Manning, in 2002 **
<stu> what does y/// stand for?  <tenderpuss> why, yansliterate of course.


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to