--- Tyson Sommer <[EMAIL PROTECTED]> wrote: > Is there any way to squeeze the following into one line? (assume > using > CGI.pm and that my $q = new CGI;): > > $device = $q->param( "device_name" ); > $device = $ARGV[0] if ! $device; > $device = "default_device" if ! $device;
my $device = $q->param("device_name") || $ARGV[0] || "default_device"; However, be forewarned that any "false" value will trigger that, so in the unlikely event that 0 (zero) is a valid device name, this is a bug. When 5.10 finally arrives (and I believe this is available in 5.9), you'll be able to do this: my $device = $q->param("device_name") // $ARGV[0] // "default_device"; That tests whether or not the value is defined and is frequently more correct. > Or better yet, how about squeezing this into one line: > > $device = $q->param( "device_name" ); > $device = $ARGV[0] if ! $device; > chomp ( $device = <STDIN> ) if ! $device; That would be tougher, but I wouldn't squeeze all of that onto one line because after a bit, readability suffers. Also, if you have a CGI script, just what are you expecting to read from <STDIN> in that third line? :) Cheers, Ovid ===== If this message is a response to a question on a mailing list, please send follow up questions to the list. Web Programming with Perl -- http://users.easystreet.com/ovid/cgi_course/ -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>