tchike tchike - 5 months ago 6
Perl Question

remove characters after a certain character

How can I remove characters from a string after a certain character (for ex:".")?

I have the next string 12345.678. I want to remove all the characters after "." and get 12345. The number of characters after "." is variable.

Thank you.

$string = '12345.678';

# remove everything from . on
$string =~ s/\..*//s;

\. matches a literal .; .* matches anything remaining in the string (with the /s flag to make it include newlines, which by default it doesn't).

It is also possible you are looking for:

$number = 12345.678;
$number = int $number;