For Programmers: Free Programming Magazines  


Home > Archive > PERL Beginners > February 2007 > global variables









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 global variables
worlman385@yahoo.com

2007-02-18, 6:58 pm

if I call a perl function 26 times,

are the variables $decode, $flag global variables?

I thought they are local variables like methods in Java, once the
function returns, $decode , $flag will get destroy.

But when i look into komodo debugger they are global variables.

How can i use them as local variables like method variables in Java?

Thanks



for ( $i = 1; $i <= 26; $i++)
{
decode($i);
}

sub decode
{
$decode = "";
$flag = $_[0];
if ( $flag != undef ) {
$data_file="brute.txt";
} else {
$data_file="encoded.txt";
$flag = 3;
}
open(DAT, $data_file) || die("Could not open encoded.txt!");
@raw=<DAT>;
close(DAT);
}
kens

2007-02-18, 9:57 pm

On Feb 18, 7:35 pm, worlman...@yahoo.com wrote:
> if I call a perl function 26 times,
>
> are the variables $decode, $flag global variables?
>
> I thought they are local variables like methods in Java, once the
> function returns, $decode , $flag will get destroy.
>
> But when i look into komodo debugger they are global variables.
>
> How can i use them as local variables like method variables in Java?
>
> Thanks
>
> for ( $i = 1; $i <= 26; $i++)
> {
> decode($i);
>
> }
>
> sub decode
> {
> $decode = "";
> $flag = $_[0];
> if ( $flag != undef ) {
> $data_file="brute.txt";
> } else {
> $data_file="encoded.txt";
> $flag = 3;
> }
> open(DAT, $data_file) || die("Could not open encoded.txt!");
> @raw=<DAT>;
> close(DAT);
>
> }


I responded to this question on comp.lang.perl.misc.
It appears that you have multiposted this question which is something
you should avoid. For details:
http://www.cs.tut.fi/~jkorpela/usenet/xpost.html

Ken

Sponsored Links







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

Copyright 2008 codecomments.com