Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re: Extract numbers in multiple bases

by jbert (Priest)
on Oct 15, 2001 at 17:25 UTC ( #118869=note: print w/ replies, xml ) Need Help??


in reply to Extract numbers in multiple bases

By changing your rules a bit (since you aren't 100% on all of them are they under your control?) can't you just use string eval to let the perl interpreter apply its own rules?

my $str = "123e4"; print asNum( $str ); sub asNum { my $str = shift; my $foo; eval "\$foo = $str"; # backslash for string not reference if( $@ ) { warn( "oops : $@" ); } return $str; }
Ugly, but probably 'rock-solid', no esoteric modules and should work with any perl.


Comment on Re: Extract numbers in multiple bases
Download Code
Replies are listed 'Best First'.
Re: Re: Extract numbers in multiple bases
by tachyon (Chancellor) on Oct 30, 2001 at 18:25 UTC

    That should be return $foo - this won't deal with several of the specified cases like h and t suffixes but it is clever nonetheless :-)

    cheers

    tachyon

    s&&rsenoyhcatreve&&&s&n.+t&"$'$`$\"$\&"&ee&&y&srve&&d&&print

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://118869]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (10)
As of 2015-07-29 09:54 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (263 votes), past polls