I use the split function by two ways. First way (string argument to split):
my $string = "chr1.txt";
my @array1 = split(".", $string);
print $array1[0];
I get this error:
Use of uninitialized value in print
When I do split by the second way (regular expression argument to split), I don't get any errors.
my @array1 = split(/\./, $string); print $array1[0];
My first way of splitting is not working only for dot.
What is the reason behind this?
"\."
is just .
, careful with escape sequences.
If you want a backslash and a dot in a double-quoted string, you need "\\."
. Or use single quotes: '\.'
If you just want to parse files and get their suffixes, better use the fileparse()
method from File::Basename
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With