James Edward Gray II wrote:
On Mar 20, 2004, at 3:10 PM, JupiterHost.Net wrote:
Howdy,
I'm looking to have a one liner version of this:
Why? Do you win a cookie if you do it in one line? ;)
Not so much a cookie as some sugar :)
I win cookies at work for writing clear code, which often involves more than one line.
I know, i just love one liners for 2 or 3 lines that seem unnecessary, I'm a sucker for them :)
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?
my $xid = param('xid') =~ m/^(\d+)$/ ? $1 : '';
Nice, I've never used ?:; that way before, good idea thx!
I could do the ? : ; dance but I'm not sure 'my' would stay in the scope I need it in.
?: doesn't affect my().
Makes sense. I was horribly confused I think Thanks for the clarification :)
James
-- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>