in reply to Re: split a string at a defined index
in thread split a string at a defined index

... and  split on a specific index (without using substr):

>perl -wMstrict -le "my $s = 'www,google,yahoo,345'; my ($v1, $v2) = split m{ (?<= \A .{16}) , }xms, $s; print qq{[$v1] [$v2]}; " [www,google,yahoo] [345]

Replies are listed 'Best First'.
Re^3: split a string at a defined index
by BrowserUk (Patriarch) on Mar 29, 2010 at 08:19 UTC

    I suspect that by "at a defined index", the IP meant "the third comma" rather than "the 16th character position".

    If he does mean the 16th position, using substr is far clearer and vastly more efficient.


    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.