in reply to Re^2: typeglob: $var = *x ???
in thread typeglob: $var = *x ???

But I did $var = *x

So did I. I said \*x also works.

it's not obvious that $val needs dereferencing.

I showed that it doesn't need dereferencing.

$gv = *x; @$gv => @x

Of course, one needs to use the sigil to access the components of the glob.

$gv = *x; $gv{ARRAY} # Obviously wrong. *$gv{ARRAY} # Ok

...and not this:

Do you really want print($count + 2) to use $count as a file handle?

print(STDOUT + 2) => print( { STDOUT } 2 )

Barewords will be handled as expected, but anything else followed by what could be an infix operator will be treated as an argument to that operator.

print(*STDOUT + 2) => print( { select() } *STDOUT+2 ) print(*$x + 2) => print( { select() } *$x+2 ) print($x + 2) => print( { select() } $x+2 )

Replies are listed 'Best First'.
Re^4: typeglob: $var = *x ???
by 7stud (Deacon) on Jun 16, 2011 at 08:23 UTC
    I showed that it doesn't need dereferencing.
    $gv = *x; @$gv => @x
    perlreftut says that the syntax @$gv is a shortcut for @{$gv}, and that looks like the very definition of dereferencing to me (see perlreftut, Use Rule 1). As far as I can tell, the only time you don't have to dereference the variable is when you use it as a filehandle--in that case it appears that perl uses the context to determine that it should extract the filehandle part of the typeglob.

      that looks like the very definition of dereferencing to me

      I thought you meant $gv vs *$gv

      it's not obvious that $val needs dereferencing.

      Completely false.

      "@foo" returns the list of elements in the array. "$foo" does not.

      According to you, (A) and (B) and (C) should be the same?

      A: @m = $x; B: @m = @$x; C: @m = $$x;

      The only thing that may not be obvious is that globs can be "dereferenced" instead of having to do *$gv{ARRAY}.

      As far as I can tell, the only time you don't have to dereference the variable is when you use it as a filehandle

      Both the "@" and "print" operators accept a scalar containing a glob. The first peeks into the ARRAY slot. The latter peeks into the IO slot. Both "dereference" the glob.