Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Re: Re: Dividing and format with regular expression the perl way

by Anonymous Monk
on Nov 27, 2003 at 20:35 UTC ( [id://310595]=note: print w/replies, xml ) Need Help??


in reply to Re: Dividing and format with regular expression the perl way
in thread Dividing and format

$num =~ s/\.(\d).*/.$1/; # perform the rounding (as string)

Oi Vay! Why (oh why) do you have that trailing dot-star in your regex? I see this with both neophyte and experienced RE users and I have yet figure out what misconception leads to this practice. Any ideas?

Replies are listed 'Best First'.
Re: Re: Re: Dividing and format with regular expression the perl way
by Roger (Parson) on Nov 27, 2003 at 20:42 UTC
    Well, just drop trailing dot-star in the regex and see the result. ;-)

    I want to get rid of anything after the first decimal point, the tailing (.*) let me do that. Of course I can also rewrite the regular expression as -
    $num =~ s/\.(\d)\d+/.$1/; # perform the rounding (as string)
    But that requires 3 characters, and I am just too lazy. Besides there is an assumption that whatever passed in is a floating point.

Re: Re: Re: Dividing and format with regular expression the perl way
by ysth (Canon) on Nov 27, 2003 at 20:39 UTC
    In this case, it removes anything after the first decimal. Perhaps you are thinking of needless .* at the end of a m//?

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others goofing around in the Monastery: (1)
As of 2024-04-25 05:51 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found