Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot

Re: Ways to delete start of string (The /s modifier)

by lodin (Hermit)
on May 25, 2008 at 19:40 UTC ( #688432=note: print w/replies, xml ) Need Help??

in reply to Ways to delete start of string

A nit-pick, but the substitution should really be

to be equivalent with the others. Note the s modifier; it makes . match leading newlines as well. Otherwise you remove the first non-newline character from the string.
my %ex = ( "\n" . 'regexp' => sub { s/.// }, "\n" . 'regexp/s' => sub { s/.//s }, "\n" . 'chop' => sub { $_ = reverse; chop; $_ = reverse; }, "\n" . 'substr1' => sub { substr($_,0,1) = '' }, "\n" . 'substr2' => sub { $_ = substr($_,1) }, ); for (sort keys %ex) { $ex{$_}->(); print "[$_]\n"; } __END__ [chop] [ egexp] [regexp/s] [substr1] [substr2]

Update: Added example.


Replies are listed 'Best First'.
Re^2: Ways to delete start of string (The /s modifier)
by hsmyers (Canon) on May 26, 2008 at 00:23 UTC
    Color me confused. The goal is to eliminate the first character. Given that removing 'the first non-newline character' is precisely what is desired. Please explain what you mean. Unless of course you are thinking that a newline might be the first character in the general case. Then that would be correct. Admittedly that never occurred to me. For no particular reason I tend to thing of newlines occurring at the end of a string and usually removed by chop/chomp at that. Of course there are times when I'm dealing with an entire as is buffer in which case there would be an expectation of embedded newlines but even at that it seems unlikely that they would wind up in a string that I would want to do a reverse chop on. Like I said please explain...


    "Never try to teach a pig to wastes your time and it annoys the pig."

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (8)
As of 2022-01-27 14:27 GMT
Find Nodes?
    Voting Booth?
    In 2022, my preferred method to securely store passwords is:

    Results (70 votes). Check out past polls.