Stupid question but its driving me nuts...

S

sumitbee

I am trying to do a simple substitution, but there is something wrong
and I cant ut my finger on it...

$cl_IP = "10.0.4.*";
print $cl_IP."\n";
$cl_IP = s/\*/\\\\\*/;
print $cl_IP."\n";

I am perplexed why this is not giving 10.0.4.\\*
 
J

jgraber

I am trying to do a simple substitution, but there is something wrong
and I cant ut my finger on it...

$cl_IP = "10.0.4.*";
print $cl_IP."\n";
$cl_IP = s/\*/\\\\\*/;
print $cl_IP."\n";

I am perplexed why this is not giving 10.0.4.\\*

use strict;
use warnings;
my $cl_IP = "10.0.4.*";
print $cl_IP."\n";
$cl_IP = s/\*/\\\\\*/; # line 5
print $cl_IP."\n";

10.0.4.*
If you had use warnings; you would have seen this
Use of uninitialized value in substitution (s///) at temp.pl line 5.

$cl_IP =~ s/\*/\\\\\*/; # line 5
# ^^

10.0.4.*
10.0.4.\\*
 
S

sumitbee

I am trying to do a simple substitution, but there is something wrong
and I cant ut my finger on it...

$cl_IP = "10.0.4.*";
print $cl_IP."\n";
$cl_IP = s/\*/\\\\\*/;
print $cl_IP."\n";

I am perplexed why this is not giving 10.0.4.\\*

Sorry all, I need glasses....
 
J

Jürgen Exner

I am trying to do a simple substitution, but there is something wrong
and I cant ut my finger on it...

$cl_IP = "10.0.4.*";
print $cl_IP."\n";
$cl_IP = s/\*/\\\\\*/;
print $cl_IP."\n";

I am perplexed why this is not giving 10.0.4.\\*

You are missing
use strict;
use warnings;

Had you used them then Perl would have told you what's wrong:
Use of uninitialized value in substitution (s///) at C:\tmp\t.pl line 7.

jue

Hint: which variable does s/// work on by default?
 
S

sumitbee

You are missing
use strict;
use warnings;

Had you used them then Perl would have told you what's wrong:
Use of uninitialized value in substitution (s///) at C:\tmp\t.pl line7.

jue

Hint: which variable does s/// work on by default?

Thank you Jue for your help!
 
K

kath

Sorry all, I need glasses....


hi, when you write program make sure it should be in more readable
form, so that you when are executing it, you come to know the errors
quickly, if any. This helps when you really frustrated or you cannot
find the simple error. I used Joel's code and modified a bit.

use strict;
use warnings;
my $cl_IP = "10.0.4.*";
print $cl_IP."\n";
#$cl_IP =~ s/\*/\\\\\*/;
$cl_IP =~ s{\*}{\\\\*}; # or s|\*|\\\\*|;
print $cl_IP."\n";


kath.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top