Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re^2: regex incorrectly matching newline

by bfdi533 (Friar)
on Jun 23, 2006 at 18:46 UTC ( [id://557289]=note: print w/replies, xml ) Need Help??


in reply to Re: regex incorrectly matching newline
in thread regex incorrectly matching newline

Well, after you asked the question I looked back at the code and found it actually looked like the follow (more code context included):

$buf = "hello\nworld"; $l = length($buf); for ($x = 0; $x < $l; $x++) { $piece = substr($buf, $x, 1); $i = ord($piece); if ($i =~ m/[ -~]/) { $rhs .= $i; } else { $rhs .= "."; } }

So, the error is actually mine and works fine when using the right variable, $piece, as:

if ($piece =~ m/[ -~]/)

Sorry for the wasted space to post this question.

Replies are listed 'Best First'.
Re^3: regex incorrectly matching newline
by ikegami (Patriarch) on Jun 23, 2006 at 19:21 UTC

    No problem. Of course, you could simplify your entire code down to:

    $buf = "hello\nworld"; $buf =~ s/[^ -~]/./g; $rhs .= $buf;

    The above alters the value of $buf in the process. Feel tree to make a copy of $buf and work with the copy if you want to preserve $buf's value.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://557289]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others goofing around in the Monastery: (4)
As of 2024-03-19 05:53 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found