List Info

Thread: question regarding local-function




question regarding local-function
country flaguser name
United States
2007-03-12 12:23:55
Hi everyone: 

   I am doing an sample exercise which demonstrate the usage
of local
function.
   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!


use strict;
use warnings;

my $first = "Per";
my $last = "Lindberg";

&greeting($first, $last);

3. print "-----$fname-----n" if defined $fname;

sub greeting
{
  local ($fname, $lname) = _;
  5.print "Welcome $fname!!n";
}

 The output for line 3 and line 5:
 3 <no output>
 5 Welcome Per!!

 Jeff
 3-12-07



------------------------ Yahoo! Groups Sponsor
--------------------~--> 
Check out the new improvements in Yahoo! Groups email.
http://us.click.yahoo.com/4It09A/fOaOAA/yQLSAA/ndFolB/TM

------------------------------------------------------------
--------~-> 

Unsubscribing info is here: h
ttp://help.yahoo.com/help/us/groups/groups-32.html 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://g
roups.yahoo.com/group/perl-beginner/

<*> Your email settings:
    Individual Email | Traditional

<*> To change settings online go to:
    http
://groups.yahoo.com/group/perl-beginner/join
    (Yahoo! ID required)

<*> To change settings via email:
    mailto:perl-beginner-digest@yahoogroups.com 
    mailto:perl-beginner-fullfeatured@yahoogroups.com

<*> To unsubscribe from this group, send an email to:
    perl-beginner-unsubscribe@yahoogroups.com

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.c
om/info/terms/
 

Re: question regarding local-function
country flaguser name
United States
2007-03-12 15:31:34
>>>>> "Jeff" == Jeff Shu
<santa98bnyahoo.com> writes:

Jeff>    I am doing an sample exercise which demonstrate
the usage of local
Jeff> function.

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
<merlynstonehenge.com> <URL:http://www.ston
ehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy,
etc. etc.
See PerlTraining.Stonehenge.com for onsite and
open-enrollment Perl training!


------------------------ Yahoo! Groups Sponsor
--------------------~--> 
See what's inside the new Yahoo! Groups email.
http://us.click.yahoo.com/0It09A/bOaOAA/yQLSAA/ndFolB/TM

------------------------------------------------------------
--------~-> 

Unsubscribing info is here: h
ttp://help.yahoo.com/help/us/groups/groups-32.html 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://g
roups.yahoo.com/group/perl-beginner/

<*> Your email settings:
    Individual Email | Traditional

<*> To change settings online go to:
    http
://groups.yahoo.com/group/perl-beginner/join
    (Yahoo! ID required)

<*> To change settings via email:
    mailto:perl-beginner-digest@yahoogroups.com 
    mailto:perl-beginner-fullfeatured@yahoogroups.com

<*> To unsubscribe from this group, send an email to:
    perl-beginner-unsubscribe@yahoogroups.com

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.c
om/info/terms/
 

Re: question regarding local-function
country flaguser name
Czech Republic
2007-03-12 16:49:58
Please read this: http://pe
rl.plover.com/FAQs/Namespaces.html
and see if it helps. Let us know if something is unclear


Jenda
===== JendaKrynicky.cz === 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



------------------------ Yahoo! Groups Sponsor
--------------------~--> 
Check out the new improvements in Yahoo! Groups email.
http://us.click.yahoo.com/4It09A/fOaOAA/yQLSAA/ndFolB/TM

------------------------------------------------------------
--------~-> 

Unsubscribing info is here: h
ttp://help.yahoo.com/help/us/groups/groups-32.html 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://g
roups.yahoo.com/group/perl-beginner/

<*> Your email settings:
    Individual Email | Traditional

<*> To change settings online go to:
    http
://groups.yahoo.com/group/perl-beginner/join
    (Yahoo! ID required)

<*> To change settings via email:
    mailto:perl-beginner-digest@yahoogroups.com 
    mailto:perl-beginner-fullfeatured@yahoogroups.com

<*> To unsubscribe from this group, send an email to:
    perl-beginner-unsubscribe@yahoogroups.com

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.c
om/info/terms/
 

[1-3]

about | contact  Other archives ( Real Estate discussion Medical topics )