467,114 Members | 1,320 Online
Bytes | Developer Community
Ask Question

Home New Posts Topics Members FAQ

Post your question to a community of 467,114 developers. It's quick & easy.

uninitialized string :

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
  • viewed: 1491
Share:
3 Replies
numberwhun
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
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
Hi,

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

thanks,
Jul 14 '08 #4

Post your reply

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

Similar topics

1 post views Thread by rk | last post: by
13 posts views Thread by rswanster@gmail.com | last post: by
12 posts views Thread by jyu.james@gmail.com | last post: by
3 posts views Thread by julien | last post: by
23 posts views Thread by Tim Anderson | last post: by
21 posts views Thread by sanjaymeher@gmail.com | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.