in reply to Split string only on regular expression match

TMTOWTDI:

use strict; use warnings; for ('Joe Dolly', 'perl.pl', 'States', 'Fred Fillmore Flintstone') { my @got = split; if (scalar @got > 1) { print substr($_, 0, 1) for @got; print "\n"; } }

Output:

2:16 >perl 1835_SoPW.pl JD FFF 2:17 >

(If this doesn’t accomplish what you want, you will need to explain what you’re really trying to do with that regular expression.)

Update: If you assign [] to an array, that array contains a single element, which is itself a reference to an empty array. I think you meant to rather assign () (the empty list), which leaves the array empty (zero elements).

Hope that helps,

Athanasius <°(((><contra mundum Iustus alius egestas vitae, eros Piratica,

Replies are listed 'Best First'.
Re^2: Split string only on regular expression match
by Anonymous Monk on Oct 31, 2017 at 17:13 UTC
    You're right about assigning with () instead of [].
    The part I didn't explain is that the "Test cases" are one at a time and using regular expression seems to be the most straight forward way of doing it.
    All I am trying to say in the regexp is, to only SPLIT the string if it has two words, excluding one word and if its a filename( a word followed by a .(dot) ) and letters as extensions.