in reply to Re: (Daddio) Re: Deleting from front of string
in thread Deleting from front of string

Very well spotted, Hopes. Dot not matching a newline is such a common mistake it's easy to forget. I'm glad that you noticed it.

<pedant>

Actually, it's possible to get dot to match everything by using the /s switch. This also has the benefit that ^ and $ will match the beginning and end of the string, and not at line breaks, which for our purposes here is desirable. See the perlre man page for details.

Hence $string =~ s/^..//s does what we want, even if we are dealing with newlines. If you don't mind losing clarity, you can even drop the ^ in this situation.

</pedant>

Having said all that, the substr method described above would be my recommendation. (It's also likely to be the fastest). ;)

Cheers,
Paul

  • Comment on Re: Re: (Daddio) Re: Deleting from front of string

Replies are listed 'Best First'.
Re: Re: Re: (Daddio) Re: Deleting from front of string
by blakem (Monsignor) on Oct 05, 2001 at 11:10 UTC
    I think you gave /s a few features that it doesn't posses. /s changes what '.' will match, just like you said, but if you want the '^' and '$' anchors to match around an embedded newline, you'll need to toss in the /m switch as well...

    Update: After re-reading the node I followed up to, I think we're both correct.... consider this a clarification of the node above it, rather than a correction. ;-)

    -Blake