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 |