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//?