We don't bite newbies here... much | |
PerlMonks |
Re^3: How do I determine with a regular expression whether a scalar is a number/whole/integer/float?by shmem (Chancellor) |
on Jul 12, 2015 at 11:19 UTC ( [id://1134361]=note: print w/replies, xml ) | Need Help?? |
What does a regular expression match against? Yup, a string. So, no matter how you initialize your array, for the purpose of comparison against a pattern, its elements are converted into strings. All conversions from string to number, from number to string, from integer to float and so on are done under the hood by perl, if necessary. Read perldata. - A scalar value (SV) has various slots: IV (integer), PV (string pointer), NV (numeric value). The currently active slot is determined by the FLAGS field of the scalar:
Note that after assigning $c the (shortened ;-) value of PI, the other slots - IV, PV - retain their previous values, but the FLAGS field now refers to NV: (NOK,pNOK). Incrementing the string " 2 ", which to perl looks like a number, results in the allocation of a integer slot which holds the value 3 - and adding 0.141592653 results in the allocation of a NV slot:
perl -le'print map{pack c,($-++?1:13)+ord}split//,ESEL'
In Section
Seekers of Perl Wisdom
|
|