P is for Practical | |
PerlMonks |
Re: Replacing whitespace with nullby kelan (Deacon) |
on Oct 11, 2002 at 23:22 UTC ( [id://204700]=note: print w/replies, xml ) | Need Help?? |
From what I have read "^" means start at the beginning,
You're misinterpreting the meaning of ^, which is what is breaking your regex. From your language, you think ^ means to start at the beginning of the string and then go through it finding all the whitespace. That is slightly incorrect. The ^ is called an anchor, which is in this case is a start-of-string anchor. It anchors your match to the beginning of the string. Meaning, "for this pattern to match, the string must start with everything that comes next." Your string doesn't start with whitespace, it starts with "BPLIF". In this case what you'd want is simply: This will find stretches of whitespace anywhere in the string. Incidentally, if the string you want to perform substitution or matching on is already in $_, you don't need to use =~ to bind the search expression. You can just do the s/// or m// by itself (as I've done above), and it will default to matching against $_. Also, see admiraln's post above about possibly using tr///. kelan Yak it up with Fullscreen ChatterBox
In Section
Seekers of Perl Wisdom
|
|