Hi,

Just out of interest, could you do it this way:

  my $default = "/foo/bar/blat";

  print "File to use? [$default] ";
  chomp(my $question = <STDIN> || $default);

I've just started using this sort of approach to assign default values to 
undefined/null parameters, eg:

  my $age = param('age') || 12;

Is that an acceptable way of doing things, or is there some glaringly obvious mistake? 
It seems to pick up null and undefined values okay, without any errors (i.e. no age 
param, or age= will get 12). Only problem is that it treats 0 as null/undefined, but 
that's fine in a lot of cases.

Tristan


You Wrote:
----------


On Apr 9, Michael Gargiullo said:

>While asking a few questions to run a script.  How can I give a default
>answer?
>
>print "File to use:";
>chomp(my $question = <STDIN>);

Most programs do it like so:

  my $default = "/foo/bar/blat";

  print "File to use? [$default] ";
  chomp(my $question = <STDIN>);
  $question = $default if $question eq '';


_______________________________________________________
sent via the murky.net webmail hegemony

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to