This is my attempt to emulate a block in C++. (I'm not positive of the official name, but here is the syntax)
int b = ({ multiple commands here; final command = return value; });
I would like to use something similar in perl. (this is what I want, but it is incorrect)
my $a = shift || ({ print "enter in value for a:"; <STDIN>; });
but I couldn't find anything similar. these are my two attempts to emulate it, but neither is perfect. For the first one ($a), you have to create a separate function for each distinct block you want to create. The second one just looks like horrible coding.
#!/user/local/bin/perl use warnings; use strict; sub IN($){ print shift; my $ret = <STDIN>; chomp $ret; return $ret; } my $a; my $b; $a = shift || IN("Enter value for b:"); if($b = shift){} else{ print "Enter value for c:"; chomp ($b = <STDIN> +); } print "a: $a\n"; print "b: $b\n";
So my question to you is, what is the cleanest way you take in command line arguments, and if they don't exist, prompt the user for the values? Oh, and also, is there a block type syntax similar to the C++ one I put at the top?

In reply to optional command line arguments by Molten

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.