Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re: Filename Partial Match function

by Eily (Hermit)
on Sep 18, 2013 at 09:09 UTC ( #1054622=note: print w/ replies, xml ) Need Help??


in reply to Filename Partial Match function

Why do you copy your file and then move it? It would be simpler to just copy it directly to the right destination. By the way, File::Copy provides both a copy and a move function.

The fact that you had to copy and paste the same code 4 times should have been a good clue that you could have done it better. And if you are just going to use index to know if a string is included in the other, a regex could do the trick, with case insensitivity made easy.

use strict; use File::Copy; use warning; system("clear"); system("mount /dev/cd0 /mnt"); system("cp /mnt/* /usr/castle/pctemp/."); system("umount /mnt"); my %dest = (SO_PC => 'PCMAP.BIN', MS_PC => 'FULLPC.BIN', SO_CV => 'CVFULLPC.BIN', MS_MC => 'MBFULLPC.BIN'); print "\n" x 5, "Input required:\n"; my $fileName = <STDIN>; chomp $fileName; for my $search (keys %dest) { die "$fileName does not exist!" unless -e $fileName; copy ($fileName, '/usr/castle/np_new/'.$dest{$search}) if $fileName + =~ /\Q$search/i; }


Comment on Re: Filename Partial Match function
Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (12)
As of 2014-09-18 12:33 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (113 votes), past polls