Third option is to use oct() and hex() based on pattern
~/perl -le 'print hex("0xdeadbeef")'
3735928559
~/perl -le 'print oct("0177")' #also handles 0b
127
my $match = /^\s*0([xb])?[0-9a-f]+?/;
my $num;
if( $match && $1 eq 'x' ){ $num = hex() }
elsif( $match && ( $1 eq 'b' or $1 eq undef) ){
There are two things you can do:
a) use regular expressions on the "numbers" to see if they conform
to known format, and then eval iff they do; you can then bypass eval
for integer/float since +0 will cover it.
e.g; e.g; /\s+0b[01]+\s+/
You should be able to crib RE from RegExp::Common, no
ok, so, I need to read in some numbers from a file.
Numbers need to allow integer, float, signed/unsigned,
as well as supporting decimal, hex, binary, octal.
Extra level of annoyance: using modules from cpan is difficult.
So, if it can be pure perl, all the better.
What I came up with was this:
On Tue, Feb 22, 2022, 13:55 Morse, Richard E.,MGH via Boston-pm <
boston-pm@pm.org> wrote:
>
> > On Feb 22, 2022, at 12:12 PM, em...@greglondon.com wrote:
> >
> > ok, so, I need to read in some numbers from a file.
> > Numbers need to allow integer, float, signed/unsigned,
> > as well as
> On Feb 22, 2022, at 12:12 PM, em...@greglondon.com wrote:
>
> ok, so, I need to read in some numbers from a file.
> Numbers need to allow integer, float, signed/unsigned,
> as well as supporting decimal, hex, binary, octal.
>
> Extra level of annoyance: using modules from cpan is difficult.
>
On Tue, Feb 22, 2022 at 12:12 PM wrote:
> Extra level of annoyance: using modules from cpan is difficult.
> So, if it can be pure perl, all the better.
> The only thing that concerns me a bit is that using string eval() means
> the file could contain code I don't want to execute. and I can't
6 matches
Mail list logo