simple reg ex
I know this is perl not javascript, I thought I was good at deciphering reg ex but the 2nd line in this function has got me puzzled. Can anyone decipher: X = (!X ? 2 : X); function round(number,X) { // rounds number to X decimal places, defaults to 2 X = (!X ? 2 : X); return Math.round(number*Math.pow(10,X))/Math.pow(10,X); } thanks lori ___ Perl-Win32-Users mailing list Perl-Win32-Users@listserv.ActiveState.com To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
RE: simple reg ex
This is not a regular expression, but rather what is know as the ternary operator. It is a terse way of writing an if-else statement with variable assignment. In this case, it is the equivalent of writing: if (!X) { X = 2; } else { X = X; } -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Behalf Of lorid Sent: Thursday, March 10, 2005 5:02 PM To: perl-win32-users Subject: simple reg ex I know this is perl not javascript, I thought I was good at deciphering reg ex but the 2nd line in this function has got me puzzled. Can anyone decipher: X = (!X ? 2 : X); function round(number,X) { // rounds number to X decimal places, defaults to 2 X = (!X ? 2 : X); return Math.round(number*Math.pow(10,X))/Math.pow(10,X); } thanks lori ___ Perl-Win32-Users mailing list Perl-Win32-Users@listserv.ActiveState.com To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs ___ Perl-Win32-Users mailing list Perl-Win32-Users@listserv.ActiveState.com To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
Re: simple reg ex
sorry , I sent question too soon, long day. forgot about the conditional reg ex (test_value ? if_true : if_false) lori ___ Perl-Win32-Users mailing list Perl-Win32-Users@listserv.ActiveState.com To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
RE: simple reg ex
lorid wrote: : sorry , I sent question too soon, long day. : : : forgot about the conditional reg ex It's not a regular expression. It's an operator. : (test_value ? if_true : if_false) Charles K. Clarkson -- Mobile Homes Specialist 254 968-8328 ___ Perl-Win32-Users mailing list Perl-Win32-Users@listserv.ActiveState.com To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs