I would like to use something similar in perl. (this is what I want, but it is incorrect)int b = ({ multiple commands here; final command = return value; });
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.my $a = shift || ({ print "enter in value for a:"; <STDIN>; });
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?#!/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";
In reply to optional command line arguments by Molten
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |