in reply to Re: Need help with s///
in thread Need help with s///

Thanks to everyone for their helpful responses.
Actually, I was trying to keep my post brief, but I ended up leaving out too much information and still getting helpful information, but not the exact information I was seeking.

Ok, here's the story:
I'm parsing a config file and I'm running into a parameter that has a value like $$NETOBJ.parameter. I want to remove the $$NETOBJ. part and be left with parameter. The code I submitted earlier was a little test that I had put together, but I mistyped it. Here is my test program as I was using it:

#!/usr/local/bin/perl $a = "$$NETOBJ.parameter"; $a =~ s/\$\$NETOBJ\.//; print $a;
Earlier, I typed use strict; out of habit. I usually use it, but left it out for this small example.
What the code above gives me is .parameter. My question is: Why doesn't my regexp remove the dot? I don't need to know how to create the value because I'm already reading it from the config file. I need to know how to remove the dot.

Sorry again for not being more specific. Thank you all for your feedback.

Tii

Replies are listed 'Best First'.
(chromatic) RE: RE: Re: Need help with s///
by chromatic (Archbishop) on Jul 15, 2000 at 07:09 UTC
    The regex doesn't remove the dot because the regex doesn't match. Let's make two small changes:
    #!/usr/local/bin/perl -w $a = "$$NETOBJ.parameter"; print ">>$a<<\n"; $a =~ s/\$\$NETOBJ\.//; print $a;
    You might also write it this way:
    $a = "$$NETOBJ.parameter"; if ($a =~ s/\$\$NETOBJ\.//) { print $a; } else { print "Substitution failed.\n"; }
    One other approach that may work for you is split:
    $a = '$$NETOBJ.parameter'; (undef, $a) = split(/\./, $a, 2); print $a;
    Of course, notice the single quotes in the declaration that time. That'll help even if you do use the regexp.