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

Re: To remove unwanted additional extension before the file extension using perl

by CountZero (Bishop)
on Nov 26, 2015 at 10:05 UTC ( [id://1148651]=note: print w/replies, xml ) Need Help??


in reply to To remove unwanted additional extension before the file extension using perl

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

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others meditating upon the Monastery: (7)
As of 2024-03-28 10:03 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found