user2047036 user2047036 - 18 days ago 4x
Bash Question

Perl script with options

I am looking for a Perl script which does the following:

  1. takes two options, like -option1 -option2

  2. Option 1 has two choices, say
    and I have shell code
    to do both actions (which I hope I can port to Perl)

  3. Here option 2 is the path and is optional. If it's not specified it uses the current directory

Desired script

checks arguments

if choice 1 :

go to path (arg2)

run a code (i have it ready)

If choice 2

go to path (arg2 )

run a code


(not tested)

#! /usr/bin/perl
use warnings;
use strict;

my ($action, $path) = (@ARGV, '.');
chdir $path or die "Cannot chdir to $path.\n";

my $script = {
    choice1 => '',
    choice2 => '',

die "Invalid choice $action.\n" unless defined $script;
0 == system $script or die "Status: $?";

Run as choice1 /path.