The question if for perl.
For example if I have "hello.world"
and the specified character is '.'
then the result I want is "hello"
.
The question if for perl.
For example if I have "hello.world"
and the specified character is '.'
then the result I want is "hello"
.
Using
substr
:Or using regexp:
Another possibility:
See
perldoc -f index
:gives you
hello
In the spirit of TIMTOWTDI, and introducing new features: Using the non-destructive option
/r
The greedy
.*
end will chop off everything after the first period, including possible newline characters (/s
option), but keep the original string intact and remove the need for parens to impose list context (/r
option).Quote from perlop: