steve abrams wrote:

Lee,

Please reply to the list, if you want our personal consultation we can arrange payment of a consulting fee :)


First off, thanks for your advice! Took what you said and passed back a hash within {}, making it 'anonymous', which I learned about today after checking out your code.

It was just a shotrcut to pass a hashref instead of creating a hash and doin a refernce to it.


Now, what we just did, vs. what I was doing in the example without the Method call (if you don't mind, of course). In my example below, I used online examples and set the scalar to be equal to the reference of the subroutine (&hashit()). From the subroutine I passed a reference of the hash (\%hash). Why does this work in the non-class case? How does

Because you were calling it wrong as I pointed out in the original reply. If you do ti right the class method works great as the example I gave you illustrated.


it work to set a scalar to be a reference to a subroutine passing a reference, and end up with the referenced return value? (That sentence might take more than one read.)

You where not doing a code reference, you where doing an object.

#!/usr/bin/perl

use strict;
use warnings;

my $coderef = sub { return "Perl Rocks!\n"; }

print $coderef->();


A second question: I'm having trouble getting a clear picture of what

perldoc perlref

anonymous data, or more specifically, a anonymous hash, really is. Is this a reference in itself? If so, how is it different from preceding a hash variable with "\"? If not, how does passing an anon. hash from a method called with:

$var = $obj->hashit();

change the example to:

sub hashit {
    my %stuff = (a => 1, b => 2);
    return \%stuff;
}

It will work the same.

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>




Reply via email to