You appear to be passing the commands in to the standard input of the program. If there isn't a good reason for that then you can pass them on the command line:
my ($command1, $command2, $command3) = @ARGV;
$command2 = 'default' unless defined $command2;
$command3 = 'hoo hah' unless defined $command3;
# OR
my $command1 = shift or die; # Ideally call a subroutine to print usag
+e and die
my $command2 = shift || 'default';
my $command3 = shift || 'hoo hah';
If you have to read from STDIN then you can check to see if it still has stuff available using the eof function:
my $command1 = <STDIN>; chomp($command1);
my ($command2, $command3) = ('default', 'hoo hah');
unless (eof(STDIN)) {
$command2 = <STDIN>; chomp $command2;
unless (eof(STDIN)) {
$command3 = <STDIN>; chomp $command3;
}
}
-ben
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|