Hello archana12

as Athanaisius told you, Getopt::Long is the best way to receive arguments for a Perl program. I want just add some words about your specific case. In fact, when you do the effort to use Getopt::Long to parse args, is worth to add at least a --help switch. Not only your program will be nicer with users but you can print the help or synopsis when parsing arguments fails instead of having a lonely (for example) Unknown option: g.

Perl tends to become very idiomatic and here is my common idiom to parse args:
unless ( GetOptions ( "example=s" => \$par_example, # string needed # more options a +nd switches.. "help" => \$par_help, # switch )) { my_show_help(); die "Error in command lin +e arguments: $!"} if (defined $par_help){my_show_help();exit;}
Even more: you can profit of the synergy of combining Getopt::Long with Pod::Usage if (and you should) you embed POD documentation into your program. See the very good node The Dynamic Duo --or-- Holy Getopt::Long, Pod::UsageMan!.

So the idiom can be expanded to include a pod2usage call if --manual is given.

In your specific case, i.e. a Tk application, your program can also be called by a double click or a custom link with wrong parameters and in this case you'll have no time to read errors emitted by your wise error check. You can circumvent this with a simple wait_for_input sub and the result will be something like:
unless ( GetOptions ( "example=s" => \$par_example, # string needed # more options a +nd switches.. "help" => \$par_help, # switch )) {pod2usage(-verbose => 1,-exitval => 'NOEXI +T'); &wait_for_input; exit 1;} if (defined $par_help){pod2usage(-verbose => 1,-exitval => 'NOEXIT'); +&wait_for_input; exit 0;} sub wait_for_input{ print "\n\nPress return when ready...\n"; while (<STDIN>){last if $_ } }


HtH
L*
There are no rules, there are no thumbs..
Reinvent the wheel, then learn The Wheel; may be one day you reinvent one of THE WHEELS.

In reply to Re: Passing arguments for GUI development in Tk (preferred idiom) by Discipulus
in thread Passing arguments for GUI development in Tk by archana12

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.