Paul Johnson wrote:
On Sat, Mar 20, 2004 at 03:10:18PM -0600, JupiterHost.Net wrote:
Howdy,
I'm looking to have a one liner version of this:
my $xid = ''; $xid = param('xid') if param('xid') =~ m/^\d+$/;
Basically, if the param is numeric then assign it to $xid, other wise '' (IE empty but declared) Some thing like:
my $xid = param('xid') if param('xid') =~ m/^\d+$/ || '';
But I know that that is not right, what am I missing?
I could do the ? : ; dance but I'm not sure 'my' would stay in the scope I need it in.
That should be fine:
my $xid = param('xid') =~ m/^\d+$/ ? param('xid') : '';
Thanks, I'd never used it for assigning values to variables that weren't already my'ed or our'ed previously. Thanks for the insight :)
Right :)I don't see any problems with the two line version, but you certainly don't want
my $xid = param('xid') if ...
-- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>