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

Hello guys , I have this pice of code
#set the command line to accept a filename. my $ret = GetOptions ("u|updated:s", "x|XMLfile:s", "e|XLSfile:s"); my $update = $opt_u || die "Usage: $0 -u update_ID\n"; my $xmllocation = $opt_x || print ".xml report will be stored where th +e cxx is.\nuse -x location to choose a different location\n"; my $xlslocation = $opt_e || print ".xls sheet will be stored under $te +mpDir.\nuse -e location to choose a different location\n"; sub checkOption { if ( $xmllocation ne "" ) { system (qq(cp /nbsssbs/$subDir6/src/$dummyforexcel $xmllocation)); + } if ( $xlslocation ne "" ) { system (qq(cp $tempDir/$dummyforexcel.xls $xlslocation)); } } # check the user option for saving in different location checkOption(); }
I am taking the -x and -e as optional , if the user provide them then I will copy a file to the location they provide otherwise nothing ,, but it seems not to work weather I provide or not the -x and -e ,, it always gives me
cp: cannot stat `/nbs/ppl/src/erls.cxx': No such file or directory cp: cannot stat `d:\\Profiles\\sara\\LOCALS~1\\Temp/erls.cxx.xml.xls': + N o such file or directory
what is it .. thanks

Replies are listed 'Best First'.
Re: Getopt problem
by Abigail-II (Bishop) on Jul 30, 2002 at 13:56 UTC
    Neither $xmllocation or $xlslocation can be equal to "" due to your:
    my $xmllocation = $opt_x || print "...";
    If $opt_x is false, $xmllocation is going to be the return value of print, which is most of the time 1.

    Abigail

Re: Getopt problem
by fruiture (Curate) on Jul 30, 2002 at 14:18 UTC

    First of all it is not a "Getopt problem". The error message comes from cp ins your system() calls. The logical Problem of $xmllocation and $xsllocation never being empty strings is another.

    GetOptions( "u|updated:s" => \my $update, "x|XMLFile:s" => \my $xmllocation, "e|XLSFile:s" => \my $xlsfile, ); $update or die "..."; $xmllocation or print "blabla"; $xlslocation or print "blablabla"; #And in your routine system(qq(sjdks $xmlfile)) if $xmlfile; #dito for $xlsfile

    I prefer the non-global method, in this case it saves variables. Consider using File::Copy for copying your files, it's better.

    --
    http://fruiture.de