in reply to Split string only on regular expression match
Is your test actually just a test for whitespace?
#!/usr/bin/perl use strict; use warnings; # Test cases: my @strings = ("Joe Dolly", # It should split and print JD. "perl.pl", # It should match on the regular expression and nothi +ng prints. "States"); # It should match on the regular expression and noth +ing prints. for my $str (@strings) { next unless $str =~ /\s/; my $out = join '', map { $_ = substr ($_, 0, 1) } split (/\s/, $st +r); print "$out\n"; };
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Split string only on regular expression match
by Anonymous Monk on Oct 31, 2017 at 17:17 UTC | |
by Anonymous Monk on Oct 31, 2017 at 17:52 UTC |