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

Replies are listed 'Best First'.
Re: Delete Trailing Characters
by FunkyMonk (Bishop) 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;