>>>>> "sw" == shawn wilson <ag4ve...@gmail.com> writes:

  sw> i ran across a peace of interesting code:
  sw> my $writer = shift->(
  sw>  [ 200, [ "Content-type" => "text/plain" ], $s ]
  sw> );

first off, there is no OO anywhere in that code. all it is is a
dereference of a code reference passed in to a sub.

  sw> so, if i understand this correctly, this would be the same as
  sw> my $writer = sub {
  sw>  my $a = shift;
  sw>  my $thing = sub {
  sw>   my $subthing = $writer->{ $a };
  sw>   return  [ 200, [ "Content-type" => "text/plain" ], $subthing ];
  sw>  }
  sw> }

not even close. there is no anon sub being created in the original code,
rather one is being passed in to the sub.

  sw> ... or something like that. what is happening there, or how should i think
  sw> about it? it seems like shift is returning $writer->[ $array ] maybe? i
  sw> think using shift as a method like that is messing me up.

there is NO method there so it isn't a method call. if you have a code
reference (to a regular sub) in $code then you dereference it like this:

        $code->( args ... ) ;

all the code does is skip assigning the code ref from @_ into $code. i
generally avoid that style of directly using the shift in an
expression. it is better style to store it in a variable so you have
some extra names to describe what that value is.

uri

-- 
Uri Guttman  ------  u...@stemsystems.com  --------  http://www.sysarch.com --
-----  Perl Code Review , Architecture, Development, Training, Support ------
---------  Gourmet Hot Cocoa Mix  ----  http://bestfriendscocoa.com ---------

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to