codewalker has asked for the wisdom of the Perl Monks concerning the following question:

This node falls below the community's minimum standard of quality and will not be displayed.
  • Comment on To remove unwanted additional extension before the file extension using perl

Replies are listed 'Best First'.
Re: To remove unwanted additional extension before the file extension using perl
by kcott (Archbishop) on Nov 26, 2015 at 07:24 UTC

    G'day codewalker,

    -- I've downvoted your post because you've made absolutely no effort yourself.

    You've been here for about a year and you are well aware that this is not a code writing service. You were last informed of this two days ago: see "Re^2: To make changes in same file in subdirectory in folders by using xslt in Batch file", its Reputation and Corion's response.

    PerlMonks is for discussing Perl and helping those who wish to learn. In that spirit, here's some help.

    You can remove a substring of known length by using substr with an offset of zero and a negative length:

    $ perl -le 'my $x = q{X.xml1.xml.xml}; print substr $x, 0, -9' X.xml

    Another way is with a regex substitution:

    $ perl -le 'my $x = q{X.xml1.xml.xml}; $x =~ s/1\.xml\.xml$//; print $ +x' X.xml

    — Ken

Re: To remove unwanted additional extension before the file extension using perl
by CountZero (Bishop) on Nov 26, 2015 at 10:05 UTC
    Using a module and a regex:
    use Modern::Perl qw/2015/; use File::Spec; while ( my $fullfile = <DATA> ) { chomp $fullfile; my ( $volume, $directories, $file ) = File::Spec->splitpath($fullf +ile); $file =~ /^([^.]+).*(\.[^.]+)/; say File::Spec->catpath( $volume, $directories, "$1$2" ); } __DATA__ 9781437706734\BODY\B978143770673410006X\B978143770673410006X.xml1.xml. +xml 9781437706734\BODY\B9781437706734100010\B9781437706734100010.xml1.xml. +xml 9781437706734\REAR\B9781437706734102000\B9781437706734102000.xml1.xml. +xml 9781437706734\REAR\B9781437706734102050\B9781437706734102050.xml1.xml. +xml 9781437706734\REAR\B9781437706734102051\B9781437706734102051.xml1.xml. +xml a\funny\file\path\with_too_many.file.extensions.in.the.file.name.txt

    CountZero

    A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James

    My blog: Imperial Deltronics