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

regarding static type variable in perl

P: 8
Hi friends,

I want to call one function depends on a variable. First i set that variable to 0 before the functiobn definition and inside the function i incriment that variable. Then i check that variable during that function call if it is zero then only call to that function. But it is not working... Any one plz help me how to implement static variable technique in perl.

Thanks & Regards,
Kokul
Aug 18 '07 #1
Share this Question
Share on Google+
3 Replies


numberwhun
Expert Mod 2.5K+
P: 3,503
We would love to help you, but unless we are able to see your code, we can't help you debug it. Please post the code that you have been working with. Do not forget to enclose the code in code tags as shown in the "Reply Guidelines" next to the Message window when submitting your post.

Regards,

Jeff
Aug 18 '07 #2

P: 8
Hi,

I will paste the code here..

Expand|Select|Wrap|Line Numbers
  1. $::myvar = 0;
  2. sub MyFunc {
  3.    my ($self,$status) = @_;
  4.    --------------------------------
  5.    --------------------------------
  6.    my $ret = `/var/www/cgi-script/myshellprogram`;
  7.    if ( $ret ) {
  8.       Throw_error ($ret);
  9.    }
  10.    $::myvar++;
  11. }  #Function MyFunc Ends here
  12. ---------------
  13. ---------------
  14. switch ($knob) {
  15.  
  16.    ----------------------------
  17.    ----------------------------
  18.  
  19.    case /^assign$/ {
  20.       if (!$::myvar) {
  21.          MyFunc('T');
  22.       }
  23.    }
  24.  
  25.   -----------------------------
  26.   -----------------------------
  27. }
  28.  
  29.  
In the above code I defined a function MyFunc to call my shell script. I want to call my shell script only once. But Inside the switch statement case /^assign$/ will come more than once. I want to restrict the function call. How can i implement it???
Aug 19 '07 #3

KevinADC
Expert 2.5K+
P: 4,059
Expand|Select|Wrap|Line Numbers
  1. $myvar = 0;
  2. sub MyFunc {
  3.    my ($self,$status) = @_;
  4.    --------------------------------
  5.    --------------------------------
  6.    my $ret = `/var/www/cgi-script/myshellprogram`;
  7.    if ( $ret ) {
  8.       Throw_error ($ret);
  9.    }
  10.    $myvar++;
  11. }  #Function MyFunc Ends here
  12. ---------------
  13. ---------------
  14. switch ($knob) {
  15.  
  16.    ----------------------------
  17.    ----------------------------
  18.  
  19.    case /^assign$/ {
  20.       unless ($myvar) {
  21.          MyFunc('T');
  22.       }
  23.    }
  24.  
  25.   -----------------------------
  26.   -----------------------------
  27. }
  28.  
  29.  
Aug 19 '07 #4

Post your reply

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