Re: Regular expression help
On Sat, 1 Dec 2001, linkagent wrote: - Original Message - From: $Bill Luebkert [EMAIL PROTECTED] To: linkagent [EMAIL PROTECTED] linkagent wrote: I need members help on this; Q1)As far as I know, \d* means match either 0 or more digits, since /(\d*)/ match 1006326869812 , therefore I could not see how /(\d*)(\d{4})(\d{5})/) could seperate 1006326869812 into (1006)(3268)(69812) The last two parts of the regex pick up 4 and 5 digits resp. The first picks up all the rest since it's 0 or more. Obviously some back-tracking has to occur since the first length is unknown. It might be faster to anchor the back end: /(\d*)(\d{4})(\d{5})$/ Correct me if I am wrong; Therefore am I right to say that the matching sequence starts from the back first (which is not what I read from the books about matching / /). i.e in the following match /(\d*)(\d{4})(\d{5})$/ the regexes look for $ first; then followed by (\d{5}) ; then followed by (\d{4}) then (\d*) Q2)Out of curiosity, I tried the undermentioned but I could not understand why on the 3rd iteration it print only 3 instead of 35968322963568389 :- for $number (1006326869812, 563296853235993 , 35968322963568389){ print $1\n if ($number =~ /(\d*)/); } The third number is too large to express as an integer. Try putting quotes around it so it's treated as a string. I thought if the number is too large, it will display something like this 3e0whatever-number, nevertheless, I will read on this. Which may explain why the last number matched only on the leading 3 digit. To find out for sure, the print statement could be changed to: print $1 number=$number\n if $number=~/(\d*)/; Actually on my PC the third number printed out as: 3.59683229635684e+016 Note that the character in the second-most significant position of the mantissa is the . character which doesn't match the \d* regex pattern. Bill's suggestion to surround the numbers with quotes will allow the entire string of digits to match. [EMAIL PROTECTED] Carl Jolley All opinions are my own and not necessarily those of my employer ___ Perl-Win32-Users mailing list [EMAIL PROTECTED] http://listserv.ActiveState.com/mailman/listinfo/perl-win32-users
Re: Seeking Date routine to calculate number of whole Months fortwo dates
On Sun, 2 Dec 2001, Sisyphus wrote: - Original Message - From: Wagner-David [EMAIL PROTECTED] To: 'Perl Win32' [EMAIL PROTECTED] Sent: Sunday, December 02, 2001 7:08 AM Subject: Seeking Date routine to calculate number of whole Months for two dates I have looked at Date::Calc and ::Manip, do not see anything. Has anyone done something like this or know of a module which will such a thing. I have no code and am doing some basic research before attempting this. I pray that someone has already done this. The way I'm reading your post, you need to convert the 2 dates to epoch-seconds, obtain the difference, and divide that difference by the number of seconds in a 'whole month' ( taking the 'int' value as your answer ) . But then, I might be misinterpretting what you have written. You are cetainly a much better mind reader than I am. Since I had no clear idea of what he meant by the term whole months I wasn't sure if he wanted to calculate the integer difference in months of two dates or the number of integer months that separated two dates exclusive of the earlier and later dates or Perhaps if he explained better, none of us would have to guess or surmise. In any event, my guess is that Date::Manip can do the trick. [EMAIL PROTECTED] Carl Jolley All opinions are my own and not necessarily those of my employer ___ Perl-Win32-Users mailing list [EMAIL PROTECTED] http://listserv.ActiveState.com/mailman/listinfo/perl-win32-users
Re: Seeking Date routine to calculate number of whole Months fortwo dates
On Sun, 2 Dec 2001, Sisyphus wrote: Seems to me that you would then first have to define what you mean by a 'whole month'. Consider the period 2000-01-07 (7th Jan.) to 2000-02-27 (27th Feb). Do you want that reported as zero whole months (because no full calendar month lies in that period), or 1 whole month (because more than 4 weeks has elapsed)? If it's the former, then, in the general case, it would be a matter of parsing the date and performing some simple arithmetic. Subtract the earlier date's month number from the later date's month number and then subtract 1. Add this to the difference in years multiplied by 12. ( Hope that's right.) There may already be a wheel that does this - but it would probably be far quicker and easier to make your own, than it would be to find this wheel :-) If it's the latter then it really comes back to clarifying exactly what is meant by a 'whole month' - 4 weeks? - a twelfth of a year ? - 30 days ? - some mixture of calendar months and a time period?. Or, since I don't seem to be hearing a coherent definition of what he means by whole months perhaps he can give several different date pairs, tell the whole month difference between them and explain why and then we can see what he means by a whole month difference. [EMAIL PROTECTED] Carl Jolley All opinions are my own and not necessarily those of my employer ___ Perl-Win32-Users mailing list [EMAIL PROTECTED] http://listserv.ActiveState.com/mailman/listinfo/perl-win32-users
RE: Seeking Date routine to calculate number of whole Months for two dates
I apologize to the list for not being clear. When you view a problem from a certain perspective, you give what you think is clear and in this case it was not. What I wanted was given date: 12/1/01 and new date, say: 1/2/02, would give 1. If it had been 12/31/01, then zero. Like I said after the post from Sisyphus, that I was after just whole integer months. I was looking at calculating epoch seconds and all this, but this seemed to be getting more complicated that I needed. So just using integer arithmetic after verifying dates are good, you would have something of form: 1011201 and 1020102 which after doing calculation, would be 1. (calucation involves a simple routine to use year, month and day) Sorry for not being more specific(though unfortuantely I thought I was :( ). Wags ;) -Original Message- From: Carl Jolley [mailto:[EMAIL PROTECTED]] Sent: Sunday, December 02, 2001 11:50 To: Sisyphus Cc: 'Perl Win32' Subject: Re: Seeking Date routine to calculate number of whole Months for two dates On Sun, 2 Dec 2001, Sisyphus wrote: Seems to me that you would then first have to define what you mean by a 'whole month'. Consider the period 2000-01-07 (7th Jan.) to 2000-02-27 (27th Feb). Do you want that reported as zero whole months (because no full calendar month lies in that period), or 1 whole month (because more than 4 weeks has elapsed)? If it's the former, then, in the general case, it would be a matter of parsing the date and performing some simple arithmetic. Subtract the earlier date's month number from the later date's month number and then subtract 1. Add this to the difference in years multiplied by 12. ( Hope that's right.) There may already be a wheel that does this - but it would probably be far quicker and easier to make your own, than it would be to find this wheel :-) If it's the latter then it really comes back to clarifying exactly what is meant by a 'whole month' - 4 weeks? - a twelfth of a year ? - 30 days ? - some mixture of calendar months and a time period?. Or, since I don't seem to be hearing a coherent definition of what he means by whole months perhaps he can give several different date pairs, tell the whole month difference between them and explain why and then we can see what he means by a whole month difference. [EMAIL PROTECTED] Carl Jolley All opinions are my own and not necessarily those of my employer ___ Perl-Win32-Users mailing list [EMAIL PROTECTED] http://listserv.ActiveState.com/mailman/listinfo/perl-win32-users ___ Perl-Win32-Users mailing list [EMAIL PROTECTED] http://listserv.ActiveState.com/mailman/listinfo/perl-win32-users