How to take substring of a given string until the first appearance of specified character?
See perldoc -f index
:
$x = "hello.world";
$y = substr($x, 0, index($x, '.'));
Using substr
:
my $string = "hello.world";
my $substring = substr($string, 0, index($string, "."));
Or using regexp:
my ($substring2) = $string =~ /(.*)?\./;
use strict;
use warnings;
my $string = "hello.world";
my $dot = index($string, '.');
my $word = substr($string, 0, $dot);
print "$word\n";
gives you hello