From: "Jonathan E. Paton" <[EMAIL PROTECTED]>
> > One is called the 'big' arrow (=>) and one is called
> > the 'little' arrow (->).
>
> Like Little Horn and Big Horn from the old westerns? ;-)
>
> > The big arrow is used in place of a ',' (comma). Now,
> > I just read in the latest Learning Perl that this is
> > global (i.e..: you can replace ANY comma with it, but
> > I may have misunderstood, have to re-read that again),
>
> Almost, the following is valid:
>
> my $couple = join " & " => qw(Husband Wife);
I think the nicest example is
use File::Copy;
cope $source => $destination;
;-) Sometimes the code looks more readable if you replace a
comma by a "big" arrow (I hear the term for the first time.)
> however, you'll note swapping the big arrow for a comma
> doesn't quite work for a hash:
>
> my %hash = ( big city, 'New York',
> Little City, 'Mayberru'
> );
Well .. not sure what did you want to show by that example.
If it was
my %hash = ( BigCity, 'New York',
LittleCity, 'Mayberru'
);
the I would. In such case the difference between => and comma
really matters. Not only that the code above will "work" only if you
don't "use strict", but it'll also go crazy if you ever define a function
BigCity.
> A better example is the closure:
>
> my $sub = sub { print "Hello " . shift . "\n" };
> $sub->("World");
This is merely an anonymous subroutine.
Really nothing different from
sub foo { print "Hello " . shift . "\n" };
my $sub = \&foo;
$sub->("World");
This would be a closure:
sub genClosure {
my $greeting = shift();
return sub { print $greeting " . shift . "\n" };
}
my $sub = genClosure('Hello');
$sub->("World");
You see the subroutine referenced by $sub "remembers" the value
of $greeting at the time it was created.
Jenda
=========== [EMAIL PROTECTED] == http://Jenda.Krynicky.cz ==========
There is a reason for living. There must be. I've seen it somewhere.
It's just that in the mess on my table ... and in my brain.
I can't find it.
--- me
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]