bfdi533 has asked for the wisdom of the Perl Monks concerning the following question:
I have the following bit of code:
if ($i =~ m/[ -~]/) { $rhs .= $i; } else { $rhs .= "."; }
When I run it through a loop processing a string like "hello\nthere" it prints the following:
hello there
rather than
as I would except.hello.there
I thought that the regex -~ would result in the range of ASCII characters from a space (ascii 32) through the tilde (ascii 126). A newline is ascii 10 so I thought I should get a "." for the newline.
Anyone have any thoughts on this?
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: regex incorrectly matching newline
by ikegami (Patriarch) on Jun 23, 2006 at 18:38 UTC | |
by bfdi533 (Friar) on Jun 23, 2006 at 18:46 UTC | |
by ikegami (Patriarch) on Jun 23, 2006 at 19:21 UTC | |
Re: regex incorrectly matching newline
by rsriram (Hermit) on Jun 24, 2006 at 06:44 UTC | |
Re: regex incorrectly matching newline
by GrandFather (Saint) on Jun 23, 2006 at 18:43 UTC | |
Re: regex incorrectly matching newline
by ioannis (Abbot) on Jun 23, 2006 at 18:50 UTC |
Back to
Seekers of Perl Wisdom