By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,841 Members | 1,362 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,841 IT Pros & Developers. It's quick & easy.

Scope Help (im a noob)

P: 1
Hello all.

First of all I am new to Perl, but not the fine art of programming, and I must say that Perl is one funky language.

Anyway. I have a scope issue with the code I have been asked to tweak.

this the problem in short.
Expand|Select|Wrap|Line Numbers
  1. my @array =("bill","ted");
  3. call parse function {
  4.    call command function{
  5.       if $command="addname"{
  6.          #Right Here, I can list/Print the name in @array but when I use pop and push on the array in here its only doing it locally to this sub or block. I need it to change globally.
  7.       }
  8.    }
  9. }
Is there any easy way around this, the @array gets accessed a lot through the code, which is HUGE and messy, so looking for a simple way to just have that value change gloabl and not local to the block i change it in.

Its weired, out of all the programming lnaguages iv used, this has never come up before.

Anyway hope you can help.
Jan 10 '08 #1
Share this Question
Share on Google+
1 Reply

Expert 2.5K+
P: 4,059
there is no way to tell, you have not posted your perl code. In general:

Expand|Select|Wrap|Line Numbers
  1. my @array = ('bill', 'ted','mary');
  2. print "$_\n" for @array;
  4. @array = foo(@array);
  5. print "\n";
  6. print "$_\n" for @array;
  8. sub foo {
  9.    my @temp = @_;
  10.    pop @temp;
  11.    push @temp,'jim';
  12.    return @temp;
  13. }
Jan 10 '08 #2

Post your reply

Sign in to post your reply or Sign up for a free account.