Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re: Question about Numbers, Strings & SPLIT

by erroneousBollock (Curate)
on Nov 29, 2007 at 04:38 UTC ( #653770=note: print w/replies, xml ) Need Help??


in reply to Question about Numbers, Strings & SPLIT

You need to escape '.' in the regular expression like this:

  split /\./

'.' in a regular expression matches any single character, rather than the period character.

Please have a look through perlre.

Personally, I like to do:

my ($whole,$fract) = ($hjd =~ /(\d+)(\.\d+)?/);
If $fract isn't defined, it'll be evaluated as zero when used numerically.

-David

Replies are listed 'Best First'.
Re^2: Question about Numbers, Strings & SPLIT
by kinnerc (Initiate) on Nov 29, 2007 at 04:49 UTC
    David:

    Bingo! You're a sanity saver! "." is a metacharacter! Of course! One blasted simple thing!

    THANK YOU!!!

    Doc Kinne

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://653770]
help
Chatterbox?
[marto]: a security event in the building, police dogs and and so on...
[Discipulus]: a test I hope..
[marto]: just a security event, they have people from the 'corporate' security, external security companies, the police etc
[marto]: perhaps I'll get the time to pin down some of the corporate security people, since they refuse to answer any questions

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (7)
As of 2017-11-22 10:25 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    In order to be able to say "I know Perl", you must have:













    Results (317 votes). Check out past polls.

    Notices?