Code Comments
Programming Forum and web based access to our favorite programming groups.
I can't find the documentation for the behavior illustrated in the
Subject line (i.e. in Perl arithmetic operations are defined for
strings beginning with numbers[*]). Any pointers would be appreciated.
(Also, meta-pointers on how one would go about finding this
documentation if one didn't know already would also be very welcome.)
TIA!
jill
* Actually, the format of the strings Perl will perform arithmetic
on is more compilicated than I described above. Optional leading
whitespace is permitted, for example.
--
To s&e^n]d me m~a}i]l r%e*m?o\v[e bit from my a|d)d:r{e:s]s.
Post Follow-up to this messageJ Krugman wrote: > I can't find the documentation for the behavior illustrated in the > Subject line (i.e. in Perl arithmetic operations are defined for > strings beginning with numbers[*]). Any pointers would be appreciated. > (Also, meta-pointers on how one would go about finding this > documentation if one didn't know already would also be very welcome.) > > TIA! > > jill > > * Actually, the format of the strings Perl will perform arithmetic > on is more compilicated than I described above. Optional leading > whitespace is permitted, for example. > > > Please do not put your whole message in the subject line. I have no idea what you are trying to get at. Please be a little bit more descriptive and provide some sample code. -- k g a b e r t (at) x m i s s i o n (dot) c o m *Use Mozzila/Firefox*! http://www.spreadfirefox.com/?q=user/register&r=71209
Post Follow-up to this messageAlso sprach J Krugman: > I can't find the documentation for the behavior illustrated in the > Subject line (i.e. in Perl arithmetic operations are defined for > strings beginning with numbers[*]). Any pointers would be appreciated. > (Also, meta-pointers on how one would go about finding this > documentation if one didn't know already would also be very welcome.) A string like '2 apples' and '2 oranges' in numeric context will both become 2. So if you add them, they are both evaluated in numeric context, so that becomes 2 + 2, and hence 4. The rules for string to number conversion are not so hard. One simple rule is that perl scans everything up to the first non-digit character and throws everything beginning with this character away. So the number-prefix remains and becomes the number. Tassilo -- use bigint; $n=7142335034377028016139702633033737113 9054411854220053437565440; $m=-8,;;$_=$n&(0xff)<<$m,,$_>>=$m,,print+chr,,while(($m+=8)<=200);
Post Follow-up to this messageJ Krugman <jkrugman345@yahbitoo.com> wrote: > I can't find the documentation for the behavior illustrated in the > Subject line (i.e. in Perl arithmetic operations are defined for > strings beginning with numbers[*]). Any pointers would be appreciated. The warnings you get if you enable warnings would be a good start. Or perldoc perlintro: Scalars A scalar represents a single value: my $animal = "camel"; my $answer = 42; Scalar values can be strings, integers or floating point numbers, and Perl will automatically convert between them as required. Xho -- -------------------- http://NewsReader.Com/ -------------------- Usenet Newsgroup Service $9.95/Month 30GB
Post Follow-up to this messageTassilo v. Parseval wrote: > The rules for string to number conversion are not so hard. One simple > rule is that perl scans everything up to the first non-digit character > and throws everything beginning with this character away. So the > number-prefix remains and becomes the number. perl -e "print '3e4' * 4" -- John Small Perl scripts: http://johnbokma.com/perl/ Perl programmer available: http://castleamber.com/ Happy Customers: http://castleamber.com/testimonials.html
Post Follow-up to this messageIn <slrnd6r19k.23f.tassilo.von.parseval@localhost.localdomain> "Tassilo v. P
arseval" <tassilo.von.parseval@rwth-aachen.de> writes:
>Also sprach J Krugman:
>A string like '2 apples' and '2 oranges' in numeric context will both
>become 2. So if you add them, they are both evaluated in numeric
>context, so that becomes 2 + 2, and hence 4.
>The rules for string to number conversion are not so hard. One simple
>rule is that perl scans everything up to the first non-digit character
>and throws everything beginning with this character away. So the
>number-prefix remains and becomes the number.
I'm sure the rules are straightforward, but I don't understand why
they aren't documented. It is not wise to use undocumented features
even if they are extremely straightforward.
jill
--
To s&e^n]d me m~a}i]l r%e*m?o\v[e bit from my a|d)d:r{e:s]s.
Post Follow-up to this messageAlso sprach John Bokma: > Tassilo v. Parseval wrote: > > > perl -e "print '3e4' * 4" Which is why I wrote "One simple rule". It implies there are others. Tassilo -- use bigint; $n=7142335034377028016139702633033737113 9054411854220053437565440; $m=-8,;;$_=$n&(0xff)<<$m,,$_>>=$m,,print+chr,,while(($m+=8)<=200);
Post Follow-up to this messageTassilo v. Parseval wrote: > Also sprach John Bokma: > > > Which is why I wrote "One simple rule". It implies there are others. I think the rule is: scans everything that looks like a number, including scientific notation, sign etc., and stops when it can't add anything more to this number. Correct me if I am wrong. -- John Small Perl scripts: http://johnbokma.com/perl/ Perl programmer available: http://castleamber.com/ Happy Customers: http://castleamber.com/testimonials.html
Post Follow-up to this message
Show a Printable Version
Email This Page to Someone!
Receive updates to this thread
Powered by vBulletin
Copyright 2000-2006 Jelsoft Enterprises Limited.