in reply to Re: split slice?
in thread split slice?

I'd be a bit worried that the second version may not perform the shifts in left to right order. There are no guarantees about the order that elements in a list are evaluated. Better would be:

sub extract { return join('-', (split(/:/, $_[0]))[1,2], $_[1]); }

Perl is environmentally friendly - it saves trees

Replies are listed 'Best First'.
Re^3: split slice?
by grinder (Bishop) on Oct 14, 2007 at 10:18 UTC

    Nice. As a finishing touch, you could indicate to split to produce only 4 elements: 0 to 2, and the rest of the string in the last element to be sliced away.

    sub extract { return join('-', (split(/:/, $_[0], 4))[1,2], $_[1]); }

    • another intruder with the mooring in the heart of the Perl