Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Re: Removing the first character from a variable

by Daddio (Chaplain)
on Jun 09, 2001 at 01:24 UTC ( [id://87083]=note: print w/replies, xml ) Need Help??


in reply to Removing the first character from a variable

AYAWTDI

$ID =~ s/.(.*)/$1/;

D a d d i o

Replies are listed 'Best First'.
Re: Removing the first character from a variable
by Abigail (Deacon) on Jun 09, 2001 at 01:52 UTC
    Eh, why the (.*) and the $1? No need to say "replace the first character and the rest by the rest". "replace the first character by nothing" is far more efficient. And we can do so in two ways:
    $ID =~ s/.//s; # No s modifier needed if the first char won't be + a newline
    or
    substr ($ID, 0, 1) = ""; # Or substr $ID, 0, 1, "";
    Of course, there are sillier ways:
    $ID = reverse $ID; chop $ID; $ID = reverse $ID;
    or
    $ID =~ /./s; $ID = $';

    -- Abigail

Re: Re: Removing the first character from a variable
by Elgon (Curate) on Jun 09, 2001 at 08:21 UTC

    I was thinking to chop off the first character...

    $id=~s/^(.)//;

    and if you want to save it afterwards...

    $chopped_character = $1;

    NB: Regexps are not my strongest point, so post a reply if I am talking crap, preferably with an explanation of why!

    "Violence is the first resort of those faced with yet another BSOD."
    --/me

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others chilling in the Monastery: (5)
As of 2024-04-18 09:25 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found