Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re: Removing the first character from a variable

by Daddio (Chaplain)
on Jun 09, 2001 at 01:24 UTC ( #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


Comment on Re: Removing the first character from a variable
Download Code
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
Node Status?
node history
Node Type: note [id://87083]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (5)
As of 2014-11-27 21:22 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My preferred Perl binaries come from:














    Results (188 votes), past polls