473,513 Members | 2,505 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

regarding static type variable in perl

8 New Member
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
3 1537
numberwhun
3,509 Recognized Expert Moderator Specialist
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
kokul
8 New Member
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
4,059 Recognized Expert Specialist
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

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

Similar topics

5
1486
by: Leo | last post by:
I have a member function in this class, which needs a variable to keep track its status. Thus I used a static member variable. But I encounter a "unresolved external variable" error during...
3
1697
by: Ekim | last post by:
given the following code: myclass.h: ------------------------------- class CMyClass { public: CMyClass(); private:
4
4872
by: Serge | last post by:
Hi, I have no problem creating a static member variable with integers, etc but when I try the same with a vector then I always get linker errors that the static member variable is unknown...
1
2799
by: medleykupps | last post by:
Hi! My linker is giving me a LNK2001 error while building a DLL. My program looks somewhat like... I have a DLL project (C1.dll) that contains a sortable list class CMyList that has a...
4
1669
by: C_Programmer | last post by:
Question#1: ========== ========== What is the default value for any Static Global variable? Example: A.c: =====
6
17424
by: markww | last post by:
Hi, I put a static member variable in my class. class CMine { static int m_nCount; }; How do I initialize it to zero? I can't do that in the constructor of the class can I? Won't that...
2
1454
by: palani12kumar | last post by:
can you please clear my doubt regarding static variables? at the time of declaring a static variable, is it compulsary to declare its data type? that is.... instead of writing "static int a;",...
13
2280
by: yanlinlin82 | last post by:
I'd like to write all code of a class in only header file. But when there is any static member varia ble, I have to define it in cpp file, not the header file. Otherwise, the static member variable...
2
5176
by: rpm27 | last post by:
Hey everyone, I am trying to declare a static class variable (not a 'primitive' variable, but from a class i wrote) inside a class However, I have tried several ways to initialize it and they...
0
7260
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7539
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7101
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7525
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5686
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5089
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4746
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3234
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3222
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.