For Programmers: Free Programming Magazines  


Home > Archive > PERL Beginners > July 2004 > Returning variables from sub routines.









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Returning variables from sub routines.
Jason Corbett

2004-07-23, 3:55 pm

I have a sub routine that I created called dateme.
when i run the sub routine, I am getting errors that Global symbol "$process_date" requires explicit package name at ....What gives?

Thanks,
JC

Here is the snipet

#---called from

dateme( );


#---------------------------
sub dateme{

my $process_date=' ';

$process_date=localtime( );

return $process_date;

}


Flemming Greve Skovengaard

2004-07-23, 3:55 pm

jason corbett wrote:
> I have a sub routine that I created called dateme.
> when i run the sub routine, I am getting errors that Global symbol "$process_date" requires explicit package name at ....What gives?
>
> Thanks,
> JC
>
> Here is the snipet
>
> #---called from
>
> dateme( );
>
>
> #---------------------------
> sub dateme{
>
> my $process_date=' ';
>
> $process_date=localtime( );
>
> return $process_date;
>
> }
>
>


There is no problem in this sample code.
But somewhere else in your program you must use $process_date without
declaring it first.

--
Flemming Greve Skovengaard The killer's breed or the Demon's seed,
a.k.a Greven, TuxPower The glamour, the fortune, the pain,
<dsl58893@vip.cybercity.dk> Go to war again, blood is freedom's stain,
4112.38 BogoMIPS Don't you pray for my soul anymore.

Jason Corbett

2004-07-23, 3:55 pm

Your correct. Actually I was trying to pass that variable back when it was local to the sub routine instead of assigning it to a variable outside the routine i.e $process_data2=dateme( );

where process_data2 is either global or assigned as my OUTSIDE that particular routine.

Thanks,
JC

Flemming Greve Skovengaard <dsl58893@vip.cybercity.dk> wrote:
jason corbett wrote:
> I have a sub routine that I created called dateme.
> when i run the sub routine, I am getting errors that Global symbol "$process_date" requires explicit package name at ....What gives?
>
> Thanks,
> JC
>
> Here is the snipet
>
> #---called from
>
> dateme( );
>
>
> #---------------------------
> sub dateme{
>
> my $process_date=' ';
>
> $process_date=localtime( );
>
> return $process_date;
>
> }
>
>


There is no problem in this sample code.
But somewhere else in your program you must use $process_date without
declaring it first.

--
Flemming Greve Skovengaard The killer's breed or the Demon's seed,
a.k.a Greven, TuxPower The glamour, the fortune, the pain,
Go to war again, blood is freedom's stain,
4112.38 BogoMIPS Don't you pray for my soul anymore.


Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2009 codecomments.com