I don't think that your code does quite what the OP wanted. The contents of the wanted array as posted indicate that the single- and double-quotes should be preserved around the text they are quoting. This could be achieved using a capture in the regex used to split the string.
#!/usr/bin/perl -l # use strict; use warnings; my $str = q{jfjsa as,.n d"fdsafjl"jop'fdsjklf fds'457"fjdsklaoir"jkl45;fs ier +987543" fsdjkal"}; my $rxSplit = qr {(?x) # Use extended syntax ( # Open capture group (?: # Open group for alternation of "[^"']*" # "whatever" | # or '[^"']*' # 'some other thing' ) # Close alternation group ) # Close capture group }; my @arr = split m{$rxSplit}, $str; print for @arr;
The output.
jfjsa as,.n d "fdsafjl" jop 'fdsjklf fds' 457 "fjdsklaoir" jkl45;fs ier987543 " fsdjkal"
I hope this is of interest.
Cheers,
JohnGG
In reply to Re^2: Split into array in a somewhat unconventional manner
by johngg
in thread Split into array in a somewhat unconventional manner
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |