473,408 Members | 2,734 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,408 software developers and data experts.

how can I check a variable is initialized are not

34
Hi All,

I have a uninitialized variabe $tmp. How can I check if the variable is initialized are not.I want to catech the warning without suppressing it using no warnings qw( uninitialized ). Please tell me how can I do it.

Expand|Select|Wrap|Line Numbers
  1. my $tmp;
  2. my $var;
  3. $var = "raghu";
  4. if ( $tmp eq "" )
  5. {
  6. if ($tmp ne $var)
  7. {
  8.         print " XYZ \n";
  9. }
  10. }
  11.  
The above code I used but I cant able to catch the warning.
but I got the output.
output:
Use of uninitialized value in string eq at tmp.txt line 8.
Use of uninitialized value in string ne at tmp.txt line 10.
XYZ
Apr 30 '07 #1
2 26888
savanm
85
Hi ,

if($tmp)
{
print "Initialised";
}
else
{
print "Not Initialised";
}

From the above code u may get ur need...
Apr 30 '07 #2
miller
1,089 Expert 1GB
Hi pnsreee,

Use the defined function:
http://perldoc.perl.org/functions/defined.html

Expand|Select|Wrap|Line Numbers
  1. my $tmp;
  2.  
  3. if (defined $tmp) {
    print "tmp is defined";
  4. } else {
    print "tmp is not defined";
  5. }
  6.  
- Miller
Apr 30 '07 #3

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

Similar topics

3
by: Marcin Vorbrodt | last post by:
So I have a class Math that looks like this: Math { public: static Real PI(void); }; Real Math::PI(void) { return 4.0 * atan(1.0); }
7
by: Wessel Troost | last post by:
Hi Group, How can you check if a variable is defined in C#? For example, "string s;" would declare an undefined variable. But how can I check in an "if" statement wether it's defined or not?...
3
by: lauch2 | last post by:
Can anyone talk me is there existed a "default" value for a un-initialized int variable in a release build in VC6 and VC7.1. (I know there is a compilation warning) For Example: main(){ int a;...
15
by: Thomas Scheiderich | last post by:
I thought I read that the case for the variable names is important. For example Dim Wheel As Integer Wheel here is a different variable from WHEEL. Is this correct?
23
by: Russ Chinoy | last post by:
Hi, This may be a totally newbie question, but I'm stumped. If I have a function such as: function DoSomething(strVarName) { ..... }
21
by: sanjaymeher | last post by:
Hi, Right now addDynamicMemory(char **ptr, int size) method can able to handle if input ptr is intitialized to NULL or something. But how to improve this method to handle uninitialized pointed...
37
by: Joergen Bech | last post by:
(Slightly religious question): Suppose I have the following class: ---snip--- Public Class MyClass Private _MyVariable As Integer Public Property MyVariable() As Integer Get
148
by: onkar | last post by:
Given the following code & variable i . int main(int argc,char **argv){ int i; printf("%d\n",i); return 0; } here i is allocated from bss or stack ?
5
by: chromis | last post by:
Hi there, I've recently been updating a site to use locking on application level variables, and I am trying to use a commonly used method which copies the application struct into the request...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
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
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
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,...
0
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...

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.