473,386 Members | 1,773 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,386 software developers and data experts.

uninitialized string :

51
Hi

Expand|Select|Wrap|Line Numbers
  1. my $x = "1-6"; 
  2. if ($x =~ /^\s*([0-9]+)\-([0-9]+)$\s*$/) {
  3.    print "SUCCEED \n"; 
  4. } else { 
  5.    print "FAILED \n"; 
  6. }
  7.  
i've got this simple regexp code. when i run it with use strict i get the following warning msg: "Use of uninitialized value in concatenation (.) or string .." at the line of the regexp match pattern. can anybody tell me what did i do wrong ??

thanks,
Jul 13 '08 #1
3 1809
numberwhun
3,509 Expert Mod 2GB
You have an extra "$" in your regular expression. The $ signfies the end of line. Change it to be like this:

Expand|Select|Wrap|Line Numbers
  1. if ($x =~ /^\s*([0-9]+)\-([0-9]+)\s*$/) {
  2.  
and the error goes away.

Regards,

Jeff
Jul 13 '08 #2
KevinADC
4,059 Expert 2GB
Hi

Expand|Select|Wrap|Line Numbers
  1. my $x = "1-6"; 
  2. if ($x =~ /^\s*([0-9]+)\-([0-9]+)$\s*$/) {
  3.    print "SUCCEED \n"; 
  4. } else { 
  5.    print "FAILED \n"; 
  6. }
  7.  
i've got this simple regexp code. when i run it with use strict i get the following warning msg: "Use of uninitialized value in concatenation (.) or string .." at the line of the regexp match pattern. can anybody tell me what did i do wrong ??

thanks,

As Jeff pointed out, the extra $ in the regexp is causing the problem. The perl variable $\ is the output record seperator which has a value of undef by default. Thus you get the "use of uninitialized..." warning. Do this and the warning goes away:

Expand|Select|Wrap|Line Numbers
  1. use strict;
  2. use warnings;
  3. $\ = "";# <-- $\ is now initialized as an empty string
  4. my $x = "1-6"; 
  5. if ($x =~ /^\s*([0-9]+)\-([0-9]+)$\s*$/) {
  6.    print "SUCCEED \n"; 
  7. } else { 
  8.    print "FAILED \n"; 
  9. }
  10.  
but of course the regexp is then looking for s* (zero or more 's') instead of \s* (zero or more spaces) but because there are no 's' characters after the digits the regexp still matches. I suspect you just want to remove that '$' as Jeff has recommended.
Jul 14 '08 #3
zcabeli
51
Hi,

i accidently placed the extra $. removing it solved the problem.

thanks,
Jul 14 '08 #4

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

Similar topics

1
by: G Kannan | last post by:
Hey all! I have written a perl script to retrieve information from a HTML Form and insert the data into an Oracle database table. I am gettting the the following error message: "Use of...
1
by: rk | last post by:
Hi, I'm a beginner for perl/cgi programs and i tried to write a cgi script and when i ran it, i got the following error. But when i verified it from the book i typed exactly whatever it is there...
2
by: Liang | last post by:
Hi, I use "defined $r_libs->{$name}" to check first if a key exists in a hash table. But Perl gives a warning WHENEVER the key exists: "Use of uninitialized value". Would u please help to...
13
by: rswanster | last post by:
When I compile and run the following: #include <iostream> int main() { bool f; std::cout << f << std::endl; f = not(f); std::cout << f << std::endl; }
12
by: jyu.james | last post by:
I'm trying to detect reads of uninitialized global variables (that are declared in one file, and used in another as an extern). I know that ANSI C initializes all global variables to 0, however,...
3
by: julien | last post by:
Hello, Is it possible if a boolean was initialized or not? For other types of variable, I usually check if it is null. But this not possible for a boolean. Thank you Julien
23
by: Tim Anderson | last post by:
Is this expected behavior? Winform with button and listbox: Dim i As Integer For i = 0 To 50 Dim s As String If i = 1 Then s = "Only once?" End If
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...
2
by: pnsreee | last post by:
Hi All, I have the following code. The array @sub_data will contain integers or a string"NO". I have to validate if the array contain integer. If it contain "NO" then no need to validate. ...
6
by: samthemist | last post by:
When perl comes out with errors like this: Use of uninitialized value in concatenation (.) or string at NQII.pl line 18, <STDIN> line 2. Argument "" isn't numeric in numeric ne (!=) at NQII.pl...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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,...

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.