Gossamer Forum
Quote Reply
OOPerl
I think it would be good to learn OOPerl. Any tips, ideas, or suggestions on starting?

Last edited by:

giovanni: Aug 22, 2002, 8:45 AM
Quote Reply
Re: [giovanni] OOPerl In reply to
I'm available for consulting at $100/hr. Please email me.

Heh, joking.

http://www.perldoc.com/...ee/AboutObjects.html

...and...

http://www.manning.com/Conway/

Last edited by:

PerlPod: Aug 22, 2002, 8:50 AM
Quote Reply
Re: [PerlPod] OOPerl In reply to
Thanks PerlPod!
Quote Reply
Re: [giovanni] OOPerl In reply to
Here's a few more:

http://perldoc.com/....0/pod/perlboot.html
http://perldoc.com/....0/pod/perltoot.html
http://perldoc.com/....0/pod/perltooc.html
http://perldoc.com/...8.0/pod/perlbot.html

(in order of complexity).

Cheers,

Alex
--
Gossamer Threads Inc.
Quote Reply
Re: [Alex] OOPerl In reply to
Thanks Alex. I am working my way through those slowly, and am currently in the middle of the big references page. I find it quite hard, but I'm sure that I can do it and when I do it will be rewarding in that I will have command of something as powerful as a proper OOP language. Then finally, I might be able to understand how Links SQL works.
Quote Reply
Re: [Lacan] OOPerl In reply to
This is really a nice book and covers all you have to learn

http://btobsearch.barnesandnoble.com/...&isbn=1884777791
Quote Reply
Re: [Lacan] OOPerl In reply to
Can someone explain why this makes a new hash and returns a reference to it:

sub hashem { +{ @_ } }

What does the + do?

Also, this is confusing:

sub showem { {; @_ } } # ok


Thanks for your help
Quote Reply
Re: [Lacan] OOPerl In reply to
>>
Can someone explain why this makes a new hash and returns a reference to it:

sub hashem { +{ @_ } }
<<

A hash is just an associative array, ie the following will work as a hash but may look like an array to you:

my %hash = ( a, 1, b, 1, c ,1 );

$hash{a} prints 1 as does $hash{b} and $hash{c};

The { } references @_ which is essentially the same as

%hash = \%hash;

The + sign forces an anonymous hash contructor.

Last edited by:

Paul: Aug 23, 2002, 7:20 AM
Post deleted by Lacan In reply to
Quote Reply
Re: [Lacan] OOPerl In reply to
I edited my post above, I wasn't thinking. + is needed to create the anonymous hash.

Code:
my $hashref = sub { +{ @_ } };

print "Content-type: text/html\n\n";
print $hashref->(1..6)->{5};

Thats a basic example. A list of 1 2 3 4 5 6 is passed to my anonymous sub and a hashref is returned...therefore really it looks like:

1 => 2, 3 => 4, 5 => 6

....so that code above will print 6

Last edited by:

Paul: Aug 23, 2002, 7:26 AM
Quote Reply
Re: [Paul] OOPerl In reply to
Sorry, I did actually type a question underneath the quote but Gforum deleted it, as it does. You have now answered my question. I'll try and look at this more as I still don't understand how the + creates the anon hash.


I deleted the post above as my reply didn't make it and it is now obselete.

Last edited by:

Lacan: Aug 23, 2002, 7:24 AM
Quote Reply
Re: [Lacan] OOPerl In reply to
You don't need to worry about how it creates it, it just does :)

It is to do with perl reading ahead and blocks/expressions.

The map perldocs may help a little bit more:

http://www.perldoc.com/....1/pod/func/map.html

Scroll down to near the bottom.
Quote Reply
Re: [Paul] OOPerl In reply to
Thanks. So much to learn :)