Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Re: How do I cut single characters out of a string

by pileofrogs (Priest)
on Jan 13, 2012 at 22:07 UTC ( #947840=note: print w/replies, xml ) Need Help??


in reply to How do I cut single characters out of a string

Aaand just because everyone else is posting to this:

It all hinges on how you define what you are trying to remove. Is it the 1st instance of the number '1'? Is it the 1st digit in the string? Is it the 9th char from the beginning, the 6th from the end?

Some possible solutions:

$string =~ tr/1//d;

Will kill all the '1's w/out the regex engine.

$string =~ s/\d//;

Will kill the very first digit found in a string

$char = substr($string,-6,1,'');

Will remove the 6th from the last char. substr treats negative numbers as offset from the end of the string, so you don't need to do (strlen -6).

etc... etc...

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://947840]
help
Chatterbox?
[moritz]: seems there's a size limit for hostenum, and the error message just sucks
[vrk]: None, other than the location of the error: auto/NetAddr/IP/ _splitref.al
[vrk]: Aha, there's a reference to "bug report 82719" in NetAddr/IP.pm's sub _splitref.

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (7)
As of 2017-04-25 07:37 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    I'm a fool:











    Results (449 votes). Check out past polls.