question regarding local-function
- Hi everyone:
I am doing an sample exercise which demonstrate the usage of local
the sample trying to show the localized variable in subroutine are
not visible outside the block. I got error complains that scalar
variable declared inside subrountine need a package.
Please see my code and help me to make it working so the code will
working according to it's purpose. Thanks!
my $first = "Per";
my $last = "Lindberg";
3. print "-----$fname-----\n" if defined $fname;
local ($fname, $lname) = @_;
5.print "Welcome $fname!!\n";
The output for line 3 and line 5:
3 <no output>
5 Welcome Per!!
>>>>> "Jeff" == Jeff Shu <santa98bn@...> writes:Jeff> I am doing an sample exercise which demonstrate the usage of local
You really shouldn't worry about local() until you absolutely need it.
If you're looking at a tutorial that teaches "local" instead of (or before)
"my", or mentions "associative array", please stop looking there.
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!
- Please read this: http://perl.plover.com/FAQs/Namespaces.html
and see if it helps. Let us know if something is unclear :-)
===== Jenda@... === http://Jenda.Krynicky.cz =====
When it comes to wine, women and song, wizards are allowed
to get drunk and croon as much as they like.
-- Terry Pratchett in Sourcery