> -----Original Message----- > From: Ovid [mailto:[EMAIL PROTECTED] > Sent: Friday, February 18, 2005 5:35 PM > To: [EMAIL PROTECTED]; beginners-cgi@perl.org > Subject: Re: Challenge (for me, at least) > > --- 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.
Definitely not an issue. Device names will never be "0" here. I understand what you're saying, tho, and will keep this in mind if I ever want to use it somewhere else. And I'll probably have javascript check the input on the HTML form before it ever leaves the client. > 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. Sweet! > > 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? :) Well, I'd like to run the script from a console (myself) as well as via CGI (others). Possibly more importantly, tho, this is a learning experience for me. q:^) Thanks Ovid! Tyson P.S., Thanks for the 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>