Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Adv Perl Programming book - Typo ? 1

Status
Not open for further replies.

latch

Programmer
Jun 26, 2001
89
0
0
DE
Hello All ,

Ive been going thru typeglobs again and I ran into this code from Sriram Srinivasan's Advanced Perl programming book


================================================
sub generate_greeting {
my ($greeting) = @_;
sub { print "$greeting world\n";}
}
$rs = generate_greeting("hello");
# Instead of invoking it as $&rs(), give it your own name.
*greet = $rs;
greet();
# Equivalent to calling $&rs(). Prints "hello world\n"
=================================================


I think the "Instead of invoking it as $&rs(), give it your own name." has a typo.

Ive read this many times over before I ran the code.
You really cant invoke the anonymous subroutine by

$&rs();
right?

&$rs();
worked for me


Pardon me ...this might appear trivial ....but after a long gap everything looks new to me.


regards
C






"Brahmaiva satyam"
-Adi Shankara (788-820 AD)
 
Yep, quite right.

$&rs() doesn't work

&$rs() works Mike
"Experience is the comb that Nature gives us after we are bald."

Is that a haiku?
I never could get the hang
of writing those things.
 
Actually, that author had many errors. I think it's him. Bcause I checked one of his script from the book and it says 'hour', instead of '$hour'. There is no Knowledge that is not power.
Age: 16
E-mail: projectnet01@yahoo.com
School: Coral Springs High (Company:(not done yet) :)
Status: Currently working with C++ for game developing. And making a musical band.
-Aaron
 
I guess he didn't take the time to create a few perl scripts to check his writing =)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top