in reply to Question about split

The first argument to split defines what you want to _split_ on. This implies that there will be an element that you want to keep _before_ the first match. In your case, that will always be an empty string as nothing comes before that in your data.

You don't actually want to use split for this. You should just use a match operator instead.

$f='453445-5.bmp'; ($base, $dash, $copy, $ext) = %f =~ /^(\d+|\w+)(-)(\d+)(\.bmp)/;

Use m// when you know what you want to keep. Use split when you know what you want to throw away.

Oh, and if you have PERL books, then I recommend getting rid of them and buying Perl books instead :)

--
<http://www.dave.org.uk>

"The first rule of Perl club is you do not talk about Perl club."
-- Chip Salzenberg

Replies are listed 'Best First'.
Re^2: Question about split
by L8on (Acolyte) on Dec 10, 2004 at 18:41 UTC
    Thanx everyone! This is exactly what I was looking for. I was thinking ( for no good reason ) that the =~ operator would change the $f variable and it wouldn't stay intact for use later and that's why I didn't try it.

    I knew it was something on my end.

    Oh, and if you have PERL books, then I recommend getting rid of them and buying Perl books instead :)

    --I just realized that you're correct, I've always thought that is was all caps and never paid attention. :)

    thanx again,
    L8on