On Fri, 18 Mar 2011 17:34:00 -0400, shawn wilson wrote: > here's the whole function (i didn't think i needed to post it because i > get the rest of this code):
Your problem is less to do with Perl than it is with explaining what you need clearly. Clear thinking and clear communication lead to clear code so this is an important thing to work on. This thread resembled a bad rewrite of the Abbott & Costello "Who's on First?" skit. > my $s = Streamer->new; > my $app = sub { > return sub { > $s->open_fh; > my $writer = shift->( > [ 200, [ "Content-type" => "text/plain" ], $s ] > ); > }; > }; That is a fancy piece of code somewhat beyond the usual definition of "beginner". Context is important; you haven't provided all of the context we need to understand this so there is going to be some guesswork in the explanation. This code creates a "Streamer" object in $s. Then it populates $app with a reference to a subroutine that when called, will return a reference to a subroutine that first calls the open_fh() method of $s, then creates in $writer the result of calling the first argument (to the inner subroutine) as a code reference, passing it a reference to an array containing 200, another array ref, and the $s object. As it stands, this doesn't make sense because nothing happens to $writer; so why create it? The code certainly does something but either there is code that you haven't shown us or the writer of this code wasn't thinking clearly in putting $writer in there. There are two code refs created and another one passed in these few lines; it is very compact. Use of this code would go something like this: $other_ref = sub { my $ar = shift; my ($status, $header_ref, $streamer) = @$ar; my @headers = @$header_ref; # Do something with those variables... }; $coderef = $app->(); $coderef->( $other_ref ); $other_ref must be a reference to a subroutine for this code to work. It is not therefore an object (technically, it could be - it could be blessed - but that is beside the point, nothing in this code expects it to be an object). You need to be very conversant with code references and functional programming to be comfortable with this code. -- Peter Scott http://www.perlmedic.com/ http://www.perldebugged.com/ http://www.informit.com/store/product.aspx?isbn=0137001274 http://www.oreillyschool.com/courses/perl3/ -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/