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

  sw> On Fri, Mar 18, 2011 at 7:02 PM, Shawn H Corey 
<shawnhco...@gmail.com>wrote:
  >> my sub_ref = shift @_;
  >> my $writer = $sub_ref->(
  >> [ 200, [ "Content-type" => "text/plain" ], $s ]
  >> );

  sw> oh, that's right, i forgot the general oo use of:

  sw> my( $self, @etc ) = @_;

again, that IS NOT OO. nothing in this thread was OO. why do you keep
saying it is OO? there is not one bit of OO here. this is simple perl
references and dereferencing stuff. it just happens to be a code
ref. here is a clue:

        $foo->{bar} ;
        $foo->[10] ;
        $foo->( $bar ) ;

see? all have the same basic syntax but the paired stuff after the ->
tells you what kind of dereference you are doing. the symmetry is there
for a good reason - it makes it easier to learn the same technique for 3
different reference types. 

  sw> that almost makes sense. the only part i'm still confused about is
  sw> why he defined $writer when you're not going to do anything with
  sw> it? that just gets returned, right?

who defined what writer? please show code when you make comments like
that. we have had lots of snippets here and i can't locate which code
piece you are commenting about. as i have told you, communication is
key. don't let pronouns dangle just like don't use $_ unless you have
too. same concept. be as clear and unambiguous as you can when writing
english or code.

  sw> so,
  sw> my( $self, @more ) = @_;

why $self? this is NOT OO. it is a simple sub call. it should be called
$code or $sub or something similar - preferably a name saying what the
sub is used for.

  sw> my @arr =  [ 200, [ "Content-type" => "text/plain" ], $s ];

why are you assigning that to an array? the value is an array ref and
can be stored in a scalar. 

  sw> $self->( @arr );

now you pass an array but it has only that one element. there is no need
for that temp array. also calling it @arr is poor as it says nothing
about the data in the array. 

  sw> right? though, i've never actually used $self, i've always just
  sw> defined it because i knew that was the first thing that was passed
  sw> to a sub in @_ (or, at some point i knew this anyway :) )

well, until you actually learn OO (which this is not), you avoid
$self. it is just the default common name for objects passed to method. 

  sw> maybe i should reread perlboot or perlsub, eh?

no, those are very different topics. read perlsub so you can learn more
about subs. read perlref (and perlreftut) so you can learn more about
refs and how to dereference them. read perlboot ONLY when you are about
to learn OO perl. as i keep saying (and you keep ignoring) this thread
had nothing to do with OO perl.

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