Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re: Remove newline character from start of string

by moritz (Cardinal)
on May 10, 2010 at 12:28 UTC ( [id://839215]=note: print w/replies, xml ) Need Help??


in reply to Remove newline character from start of string

Note that chomp depends on the current value of $/. I assume here that you want to emulate that behaviour.

As a regex:

$str =~ s{^\Q$/\E}{};

With substr:

if (substr($str, 0, length($/)) eq $/) { substr($str, 0, length($/), ''; }
Perl 6 - links to (nearly) everything that is Perl 6.

Replies are listed 'Best First'.
Re^2: Remove newline character from start of string
by Roy Johnson (Monsignor) on May 10, 2010 at 15:29 UTC
    Or somewhat oddly,
    chomp(substr($str, 0, length($/));

    Caution: Contents may have been coded under pressure.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others cooling their heels in the Monastery: (4)
As of 2024-04-23 16:12 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found