AW: split() skipping trailing delimiters
Hi dZ, According to documentation, the prototype of split has a third parameter: split /PATTERN/, EXPR, LIMIT If LIMIT is omitted in the function call, then "trailing null fields are stripped from the result", as the Camel book states. I also stumbled on it a few times... -- Andreas -Ursprüngliche Nachricht- Von: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Im Auftrag von DZ-Jay Gesendet: Montag, 5. Dezember 2005 13:59 An: perl-win32-users@listserv.ActiveState.com Betreff: split() skipping trailing delimiters Hello: I have a problem using the split() function: When there are trailing delimiters, without any content between them, split() skips them. For example, this: my @foo = split(/,/, 'this,is,a,test,,'); yields: this is a test while I'm expecting: this is a test '' '' Is there any way around this? I need to split strings on a specific delimiter and detect all null fields within the string, including trailing ones. Thanks in advance! dZ. ___ Perl-Win32-Users mailing list Perl-Win32-Users@listserv.ActiveState.com To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs Note: If the reader of this message is not the intended recipient, or an employee or agent responsible for delivering this message to the intended recipient, you are hereby notified that any dissemination, distribution or copying of this communication is strictly prohibited. If you have received this communication in error, please notify us immediately by replying to the message and deleting it from your computer. Thank you. ___ Perl-Win32-Users mailing list Perl-Win32-Users@listserv.ActiveState.com To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
RE: Test if string is a number?
For a long time I'm using the function below to test for a number, being quite satisfied with it ... # (nmb) number # Returns decimal value of the contents if argument # is a number (integer if octal or hexadecimal), # otherwise returns empty string ('') sub number($) { local $_ = shift; s/^\s*(.*)\s*$/$1/; return '' unless /^[+-]?(?:\d+\.?\d*|\.\d+)(?:[eE][+-]?\d+)?$|^[+-]?0x[0-9a-fA-F]+$/; s/\+//; my $sign = s/^-// ? '-' : ''; /^0[0-7]+$|^0x[0-9a-fA-F]+$/ ? $sign.oct : $sign.$_*1; } Greetings -- Andreas __ Delphi Electronics & Safety FUBA Reception Systems Andreas Kamentz Electrical Engineer / SW Antenna Engineering [EMAIL PROTECTED] Tel: (+49) 5063.990.541 Fax: (+49) 5063.990.99541 Mailing address FUBA Automotive GmbH & Co. KG TecCenter D-31162 Bad Salzdetfurth / Germany -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Siebe Tolsma Sent: Thursday, June 30, 2005 5:31 PM To: Joe Discenza; perl-win32-users@listserv.ActiveState.com Subject: Re: Test if string is a number? How about regexp? /^\-?(\d+\.?\d*|\.\d+)$/ - Original Message - From: Joe Discenza To: Chris Wagner ; perl-win32-users Sent: Thursday, June 30, 2005 4:48 PM Subject: RE: Test if string is a number? Chris Wagner wrote, on Thu 6/30/2005 08:48 : Wow there's been a lot of heavy duty code proposed to do something so : simple. The answer is in how Perl converts between the two. : : print "is a number" if $var eq $var + 0; : print "not a number" if $var ne $var + 0; Except if $var is, say, '0.00'. Then $var + 0 is '0', and won't eq $var. Joe == Joseph P. Discenza, Sr. Programmer/Analyst mailto:[EMAIL PROTECTED] Carleton Inc. http://www.carletoninc.com 574.243.6040 ext. 300fax: 574.243.6060 Providing Financial Solutions and Compliance for over 30 Years ___ Perl-Win32-Users mailing list Perl-Win32-Users@listserv.ActiveState.com To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs Note: The information contained in this message may be privileged and confidential and thus protected from disclosure. If the reader of this message is not the intended recipient, or an employee or agent responsible for delivering this message to the intended recipient, you are hereby notified that any dissemination, distribution or copying of this communication is strictly prohibited. If you have received this communication in error, please notify us immediately by replying to the message and deleting it from your computer. Thank you. ___ Perl-Win32-Users mailing list Perl-Win32-Users@listserv.ActiveState.com To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs