Greg London <[EMAIL PROTECTED]> said something to this effect on 07/18/2001:
> can someone explain somethig for me, please:
> 
> bless \ [@_], $package;
> question: what's the '\' character do?

\ takes a reference to the variable it preceeds, so in this case,
it is taking a reference to an anonymous list. For example:

  package P;
  sub new {
      my $package = shift;
      bless \ [@_], $package;
  }

  my $p = P->new(1, 2, 3);

  print Dumper($p);

  $VAR1 = bless( do{\(my $o = [
                     1,
                     2,
                     3
                   ])}, 'P' );

> $x = sub { $ {shift()} }   ;
> question: what's the lone '$' do?

The '$' in this case dereferences $_[0] as a scalar, which in
this case is a reference to an anonymous list.  What is this
trying to accomplish, though?  $x now has a reference to a
subroutine, which will dereference its first argument as a scalar
reference:

  my $y = $x->($p); # or &{$x}($y)

  print Dumper($y);

  $VAR1 = [
            1,
            2,
            3
          ];

So, to get the actual array in question, you'd have to do
something like:

  my @newarray = @{$x->($p)}; # or @{$y}

Or, you could have $z which returns the doubly dereferenced array
directly:

  my $z = sub { @{ ${ shift() } } }; 

Or define it in terms if $x:

  my $z = sub { @{ $x->(shift()) } };

Either of which yield:

  my @d = $z->($p);

  print Dumper(@d);
  $VAR1 = 1;
  $VAR2 = 2;
  $VAR3 = 3;

Hmmm... Line noise....

Where is this code from, out of curiosity?

(darren)

-- 
If you consistently take an antagonistic approach, however, people
are going to start thinking you're from New York.
    -- Larry Wall to Dan Bernstein

Reply via email to