Re: Strange behavior when printing a 4G+ integer on 32bits platform.
On 11/13/2018 8:07 AM, Tetsuo Handa wrote: > Hello. > > I want to represent up to a few hundreds gigabytes for file size. > > On 32bits platform, I noticed that > >my $value = ...; >printf("%u\n", $value); > > prints 4294967295 if $value >= 4294967295 whereas > >my $value = ...; >printf("%s\n", $value); > That can fail if $value is so big that it requires more than 15 decimal digits to express it accurately. For example: C:\_32>perl -le "printf '%s', 901234567890123456789;" 9.01234567890123e+020 As you can see, it's printing the value as 90123456789012300 > and > >use Math::BigInt; >my $value = ...; >printf("%s\n", Math::BigInt->new($value)->bstr()); > > print correct value even when $value >= 4294967295. > > Is it guaranteed (e.g. described as language specification) that > printf("%s\n", $value) will print correct value for any environment? > If you're dealing with integer values that overflow perl's integer type (IV), then you're generally better off using a module that accommodates larger integers. Math::BigInt is fine for this, though it can be rather slow if you're doing lots of large calculations. Other options include Math::Int64 (64-bit integer support), Math::Int128(128-bit integer support), Math::GMP(multiple precision) and Math::GMPz (multiple precision). Note that even with Math::BigInt it's important that you assign the value as a string: C:\_32>perl -MMath::BigInt -le "printf '%s', Math::BigInt->new('901234567890123456789');" 901234567890123456789 If you assign it as number (unquoted): C:\_32>perl -MMath::BigInt -le "printf '%s', Math::BigInt->new(901234567890123456789);" 90123456789012300 Similarly, assign as a string when using the other alternative modules that I mentioned. Note also that you can just print() the value: C:\_32>perl -MMath::BigInt -le "print Math::BigInt->new('901234567890123456789');" 901234567890123456789 There's no need to invoke printf(), and no need to call the bstr() method. Cheers, Rob -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: Common regex for timedate
Hi Andy , thanks for the reply . Yes the purpose is to compare the timestamps ans yes these are the only two formats . Thanks, On Wed, Nov 14, 2018 at 2:48 AM Andy Bach wrote: > Calling upgrade.sql on 05-JUL-18 10.19.42.559000 PM -12 > Calling apply.sql on 17.10.18 12:28:12,447849 +02: > > > I created on regex : \d\d\.\d\d\.\d\d\s[012][0-9]:[0-5][0-9]>:[0-5][0-9] > > this only matches : Calling apply.sql on 17.10.18 12:28:12,447849 +02: > > Right as your first string has word chars for the month, not digits. So, a > straight forward, if only lightly useful one would get both, but as they've > got entirely different orders, you're not going to be able to do much with > the result. You'd be better off looking at 2 separate ones, esp. if you > know one will be prefixed by "upgrade" and the other by "apply" or some > similar list of words: > if ( $str =~ > /upgrade.sql\s+on\s+(\d{2}-\w{3}-\d{2})\s+(012][0-9]:[0-5][0-9]:[0-5][0-9])/ > # got $1 eq "date-mon-year" and $2 eq "hr-min-sec" > or $str =~ > /apply.sql\s+on\s+(\d{2}\.\d{2}\.\d{2})\s+([012][0-9]:[0-5][0-9]:[0-5][0-9])/ > # got $1 eq "date.month.year" and $2 eq "hr-min-sec" > ) { > # date str's matched > > > I need a common regex which matches both the lines ? > You might want to let us know why? What you're going to do w/ the match. > Are you validating the strings and, if so, will you reject non-matches? > Are you looking to break them up into parts, $date, $mon, $year ... ? > Compare them, maybe to find the difference? Are these the only 2 formats > you'll be looking at, that is, maybe some might be 17.10.2018, or 17-10-18? > > > > On Mon, Nov 12, 2018 at 6:49 AM Asad wrote: > >> Hi all , >> >>I have two stings from logfile how can we have a common regex >> so that its parse datetime details for further parsing ; >> >> Calling upgrade.sql on 05-JUL-18 10.19.42.559000 PM -12 >> Calling apply.sql on 17.10.18 12:28:12,447849 +02: >> >> I created on regex : \d\d\.\d\d\.\d\d\s[012][0-9]:[0-5][0-9]:[0-5][0-9] >> this only matches : Calling apply.sql on 17.10.18 12:28:12,447849 +02: >> >> I need a common regex which matches both the lines ? >> >> >> Thanks, >> -- >> Asad Hasan >> +91 9582111698 >> > > > -- > > a > > Andy Bach, > afb...@gmail.com > 608 658-1890 cell > 608 261-5738 wk > -- Asad Hasan +91 9582111698
Re: Common regex for timedate
Calling upgrade.sql on 05-JUL-18 10.19.42.559000 PM -12 Calling apply.sql on 17.10.18 12:28:12,447849 +02: > I created on regex : \d\d\.\d\d\.\d\d\s[012][0-9]:[0-5][0-9]>:[0-5][0-9] > this only matches : Calling apply.sql on 17.10.18 12:28:12,447849 +02: Right as your first string has word chars for the month, not digits. So, a straight forward, if only lightly useful one would get both, but as they've got entirely different orders, you're not going to be able to do much with the result. You'd be better off looking at 2 separate ones, esp. if you know one will be prefixed by "upgrade" and the other by "apply" or some similar list of words: if ( $str =~ /upgrade.sql\s+on\s+(\d{2}-\w{3}-\d{2})\s+(012][0-9]:[0-5][0-9]:[0-5][0-9])/ # got $1 eq "date-mon-year" and $2 eq "hr-min-sec" or $str =~ /apply.sql\s+on\s+(\d{2}\.\d{2}\.\d{2})\s+([012][0-9]:[0-5][0-9]:[0-5][0-9])/ # got $1 eq "date.month.year" and $2 eq "hr-min-sec" ) { # date str's matched > I need a common regex which matches both the lines ? You might want to let us know why? What you're going to do w/ the match. Are you validating the strings and, if so, will you reject non-matches? Are you looking to break them up into parts, $date, $mon, $year ... ? Compare them, maybe to find the difference? Are these the only 2 formats you'll be looking at, that is, maybe some might be 17.10.2018, or 17-10-18? On Mon, Nov 12, 2018 at 6:49 AM Asad wrote: > Hi all , > >I have two stings from logfile how can we have a common regex > so that its parse datetime details for further parsing ; > > Calling upgrade.sql on 05-JUL-18 10.19.42.559000 PM -12 > Calling apply.sql on 17.10.18 12:28:12,447849 +02: > > I created on regex : \d\d\.\d\d\.\d\d\s[012][0-9]:[0-5][0-9]:[0-5][0-9] > this only matches : Calling apply.sql on 17.10.18 12:28:12,447849 +02: > > I need a common regex which matches both the lines ? > > > Thanks, > -- > Asad Hasan > +91 9582111698 > -- a Andy Bach, afb...@gmail.com 608 658-1890 cell 608 261-5738 wk
Re: Strange behavior when printing a 4G+ integer on 32bits platform.
I don't have an answer for you, but I find this interesting. I note the same issue in 64bit up near 18446744073709551615 I'm guessing the guy who wrote Math::BigInt may have the answer. Mike On 11/13/2018 8:07 AM, Tetsuo Handa wrote: Hello. I want to represent up to a few hundreds gigabytes for file size. On 32bits platform, I noticed that my $value = ...; printf("%u\n", $value); prints 4294967295 if $value >= 4294967295 whereas my $value = ...; printf("%s\n", $value); and use Math::BigInt; my $value = ...; printf("%s\n", Math::BigInt->new($value)->bstr()); print correct value even when $value >= 4294967295. Is it guaranteed (e.g. described as language specification) that printf("%s\n", $value) will print correct value for any environment? -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Strange behavior when printing a 4G+ integer on 32bits platform.
Hello. I want to represent up to a few hundreds gigabytes for file size. On 32bits platform, I noticed that my $value = ...; printf("%u\n", $value); prints 4294967295 if $value >= 4294967295 whereas my $value = ...; printf("%s\n", $value); and use Math::BigInt; my $value = ...; printf("%s\n", Math::BigInt->new($value)->bstr()); print correct value even when $value >= 4294967295. Is it guaranteed (e.g. described as language specification) that printf("%s\n", $value) will print correct value for any environment? -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: Common regex for timedate
On Mon, 12 Nov 2018 18:18:12 +0530 Asad wrote: > Hi all , > >I have two stings from logfile how can we have a common regex so > that its parse datetime details for further parsing ; > > Calling upgrade.sql on 05-JUL-18 10.19.42.559000 PM -12 > Calling apply.sql on 17.10.18 12:28:12,447849 +02: > > I created on regex : \d\d\.\d\d\.\d\d\s[012][0-9]:[0-5][0-9]:[0-5][0-9] > this only matches : Calling apply.sql on 17.10.18 12:28:12,447849 +02: > > I need a common regex which matches both the lines ? > > > Thanks, > -- > Asad Hasan > +91 9582111698 Hi Asad! Try \d\S+\s[\d.:]{8} -- Дмитрий Ананьевский -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/