N
Noel Sant
I want to split a filename into the name itself and the extension. This:
($name, $extension) = split /\./, $input_file;
works fine, providing there's only one dot in the filename, but if there are
more I just get the first two bits of name. I really want to get the last
bit into $extension and all the rest, including dots, into $name.
I suppose I could use an array on the left-hand side, find out how many
element there are and just build up $name from all the arrays bar the last,
but this seems long-winded. I tried using "split /\.$/, ..." but then I got
evrything in $name, and $extension was undefined. As though it's just
looking at the end of the string and saying "Nope! no dot there" and not
going any further back. Obviously I don't understand what $ does.
How do I say "just match on the last dot", please?
($name, $extension) = split /\./, $input_file;
works fine, providing there's only one dot in the filename, but if there are
more I just get the first two bits of name. I really want to get the last
bit into $extension and all the rest, including dots, into $name.
I suppose I could use an array on the left-hand side, find out how many
element there are and just build up $name from all the arrays bar the last,
but this seems long-winded. I tried using "split /\.$/, ..." but then I got
evrything in $name, and $extension was undefined. As though it's just
looking at the end of the string and saying "Nope! no dot there" and not
going any further back. Obviously I don't understand what $ does.
How do I say "just match on the last dot", please?