Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Read, Load and rename files from CD

by Jalcock501 (Sexton)
on Oct 16, 2013 at 10:27 UTC ( #1058418=perlquestion: print w/ replies, xml ) Need Help??
Jalcock501 has asked for the wisdom of the Perl Monks concerning the following question:

Hi Guys I've been writing a script which loads files from a CD, asks the user for the specific file they are after and loads that into a different directory under a different name.

i.e

Fileblah -> tempdir -> Rename -> finaldir

The question is how do I get rid of the user input so that they just run the script automatically and it can check for the correct file.

Here is my code so far
#!/usr/bin/perl -w use strict; use File::Copy; use warning; my $np_new = 'usr/castle/np_new/' my $temp = 'usr/castle/pctemp' system("clear"); system("mount /dev/cd0 /mnt"); system("cp /mnt/* $temp/."); 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, "\t" x 3, "Input required: "; chomp $fileName; my $fileName = <STDIN>; for my $search (keys %dest) { die "$fileName does not exist!" unless -e $fileName; copy ($fileName, $np_new.'/usr/castle/pctemp/'$dest{$search}) if $f +ileName =~ /^$search/i; }
The files always come in as one of the four

SO_PC(refnum).BIN

MS_PC(refnum).BIN

SO_CV(refnum).BIN

MS_MC(refnum).BIN

Comment on Read, Load and rename files from CD
Select or Download Code
Re: Read, Load and rename files on CD
by Anonymous Monk on Oct 16, 2013 at 10:44 UTC

    The question is how do I get rid of the user input so that they just run the script automatically and it can check for the correct file.

    Um, just delete the user input part? Decide on a new name somehow?

Re: Read, Load and rename files from CD
by pvaldes (Chaplain) on Oct 16, 2013 at 13:52 UTC

    can't see the point of having this line: system("clear"); maybe you need a chdir instead?

    ...And this is not correct because you need to define the variable first

    chomp $fileName; my $fileName = <STDIN>;

    Better like this:

    my $fileName = <STDIN>; chomp $fileName;

    You can use also a more compact form saving one line. Parens are required:

    chomp (my $filename = <STDIN>);

    What is "the correct file" for you? all files in the CD?

Re: Read, Load and rename files from CD
by GotToBTru (Chaplain) on Oct 16, 2013 at 17:04 UTC
    Where does refnum come from?
Re: Read, Load and rename files from CD
by kcott (Abbot) on Oct 17, 2013 at 03:23 UTC

    G'day Jalcock501,

    The following two lines are missing terminating semicolons. You would have received an error message about this: where is it? Also, consider the absence/presence of leading/trailing slashes in the pathnames.

    my $np_new = 'usr/castle/np_new/' my $temp = 'usr/castle/pctemp'

    This line is also wrong:

    copy ($fileName, $np_new.'/usr/castle/pctemp/'$dest{$search})

    You possibly meant:

    copy ($fileName, $np_new.'/usr/castle/pctemp/' . $dest{$search}) # ^ (concatenation)

    Again, I would have expected an error message. Please either post the errors you get or, if you're not getting any, post the actual code you're running.

    -- Ken

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (5)
As of 2014-07-23 01:01 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (130 votes), past polls