Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8475627
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T17:56:38+00:00 2026-06-10T17:56:38+00:00

When calling a perl script with: myPerlScript –myarg 10 –my2Darg 42×87 . How do

  • 0

When calling a perl script with:

myPerlScript --myarg 10 --my2Darg 42x87.

How do I make the assignments:

$myarg = 10;
$my2Darg_x = 42;
$my2Darg_y = 87;

if and only if myarg and my2Darg is valid arguments?

I think I need something like this:

#!/usr/bin/perl

foreach (@ARGV) {

    if ($_ eq '--myarg') {

        $myarg =
    }
    elsif ($_ eq '--my2Darg') {
        $my2Darg_x =
        $my2Darg_y =
    }
    else {

        print "Not valid argument!!";
    }
}

As you can see this code is not complete. Plz. help.

Is there a short way to write if($_ eq 'text') (is if('text') valid Perl?)?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T17:56:40+00:00Added an answer on June 10, 2026 at 5:56 pm

    Check Getopt::Long module, it’s on core.

    Script

    use strict;
    use Getopt::Long;
    
    my ($arg, $arg_2d);
    
    # prepare format cmd string
    GetOptions( "myarg=i" => \$arg, "my2Darg=s" => \$arg_2d);
    
    unless ( $arg && $arg_2d && $arg_2d =~ m{\d+x\d+}i ) {
    
        print "Usage: $0 --myarg 10 --my2Darg 42x87 \n";
        exit 1;
    }
    
    my ($arg_2d_x, $arg_2d_y) = split 'x', $arg_2d;
    
    printf "arg: %s \narg_2d_x: %s \narg_2d_y: %s\n", $arg, $arg_2d_x, $arg_2d_y;
    

    Output

    arg: 10 
    arg_2d_x: 42 
    arg_2d_y: 87
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to make a Master perl script calling children perl script and
I am calling a command-line program from my Perl script. When these programs crash,
I have the following snippet calling a perl script which writes to STDERR and
I have a Perl script that is calling a program on Windows using backticks.
I am calling find from a perl script like this: my $one_file = `find
I am trying a different way of calling a subroutine in a Perl script.
I have a perl script which calls another script. I am calling it using
I'm successfully calling a Perl script from a shell script. Now I want to
I want to do this in a shell script: #!/usr/bin/ksh PERL_PATH=/usr/local/bin/perl RET1=$(${PERL_PATH} missing_months_wrap.pl) echo
I have the following, simplest Perl CGI script: use strict; use warnings; use CGI();

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.