Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re: chopping lots of characters

by Abigail-II (Bishop)
on Jun 24, 2004 at 11:45 UTC ( #369294=note: print w/ replies, xml ) Need Help??


in reply to chopping lots of characters

As you said, substr is the way to go. chop chops off one character, and not more than one. So, if you want to chop off 4 characters using chop, you need to chop 4 times. Either by duplicating the line, or by using a loop. You might want to bail out if the string is empty:
my $i = 4; chop $string while $i -- && length $string;
Or
my $i = 4; 1 while $i -- && defined chop $string;
although the latter might want to chop an empty string (but only once).

Abigail

Replies are listed 'Best First'.
Re^2: chopping lots of characters
by Anonymous Monk on Jun 24, 2004 at 11:52 UTC
    thanks thats cool, think I might just stick with chop repeated 4 times though - easier to read and about the same number of characters anyway ;-)

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (2)
As of 2016-07-28 04:28 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    What is your favorite alternate name for a (specific) keyboard key?


















    Results (252 votes). Check out past polls.