Beefy Boxes and Bandwidth Generously Provided by pair Networks Ovid
Do you know where your variables are?
 
PerlMonks  

Delete Trailing Characters

by muizelaar (Sexton)
on Feb 21, 2008 at 18:28 UTC ( #669333=perlquestion: print w/ replies, xml ) Need Help??
muizelaar has asked for the wisdom of the Perl Monks concerning the following question:

Hi I would like to be able to read in a list of files (with varied length names) into an array. Then remove the trailing 4 characters of each line, Any ideas how to do this :) Darren

Comment on Delete Trailing Characters
Re: Delete Trailing Characters
by FunkyMonk (Abbot) on Feb 21, 2008 at 18:37 UTC
    I see from your previous questions that you know how to read in a list of files into an array. So I presume you're asking about the second bit, how to delete the last four characters from a string. For that, have a look at substr with a negative second argument.

    Of course, if my presumption is wrong, why don't post what you've tried so far?

      Thanks for that it was a big help, managed to get it working :)
Re: Delete Trailing Characters
by olus (Curate) on Feb 21, 2008 at 18:39 UTC
    @file_names = map{ substr($_, 0, -4) } @file_names; # alternativelly @file_names = map{ /(.*).{4}/ } @file_names;

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (5)
As of 2013-05-26 03:41 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best material for plates (tableware) is:









    Results (524 votes), past polls