Beefy Boxes and Bandwidth Generously Provided by pair Networks Frank
XP is just a number
 
PerlMonks  

Re: CLI with ARGV

by influx (Beadle)
on Aug 08, 2012 at 08:20 UTC ( #986174=note: print w/ replies, xml ) Need Help??


in reply to CLI with ARGV

If it's simple arguments you want, you can do this kind of thing

my $host; my $pass; while(my $arg = shift @ARGV) { for ($arg) { if (/-h|--host/) { $host = shift @ARGV; } elsif (/-p|--pass/) { $pass = shift @ARGV; } } }

This allows you to use -h hostname OR --host hostname, and -p pass OR --pass pass. Both arguments would be stored in $host and $pass respectively


Comment on Re: CLI with ARGV
Download Code
Re^2: CLI with ARGV
by WhiskeyJack (Initiate) on Aug 08, 2012 at 09:24 UTC

    I actually used the Getopt::Long; module to set everything and it worked fine. But I have another problem now I've created three ARGV[] arguments.

    $list=$ARGV[0]; if ($list eq "list") { my $chan = $ssh2->channel(); $chan->blocking(1); $chan->shell(); print $chan "cd ..\n"; print $chan "ls\n"; print " $_" while <$chan>; print "Type the name of the directory you would like to enter: "; my $dir = <STDIN>; print $chan "cd '/'$dir\n"; print $chan "ls\n"; print " $_" while <$chan>; } $delete=$ARGV[1]; if ($delete eq "delete") { unlink($delete_file); } $upload=$ARGV[2]; #Send file if ($upload eq "upload") { $ssh2->scp_put($upload_local,$upload_remote) or warn "Could not copy the file"; } $download=$ARGV[3]; #Get file if ($download eq "download") { $ssh2->scp_get($download_remote, $download_local) or warn "Could not copy the file"; }

    Its made so that I can call a download or upload of some file or to list all the files in a folder.

    The problem I have is that I can't seem to figure out how to set the ARGV part so that I can run any of these arguments at any time. Right now for me to run download for instance I would first have to run list and delete and upload before I could run download.

    Is there some way to set the ARGV command to be able to run multiple commands without being dependant on the order by which they are run? So I could run list then download then upload then delete.

        Hey 2teez thank you for answering I've actually figured out how to do it using the Getopt::Long module. It doesn't use ARGV but does what I want it to do. Thank you anyway for trying to help.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (8)
As of 2014-04-17 07:51 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    April first is:







    Results (441 votes), past polls