How can I split a string by whitespace unless inside of a single quoted string?

Use Text::ParseWords :! /usr/bin/perl use strict; use warnings; use Text::ParseWords; my @words = parse_line('\s+', 0, "abcd efgh 'ijklm no pqrs' tuv"); use Data::Dumper; print Dumper \@words Output: C:\Temp> ff $VAR1 = 'abcd', 'efgh', 'ijklm no pqrs', 'tuv' You can look at the source code for Text::ParseWords::parse_line to see the pattern used.

Use Text::ParseWords: #! /usr/bin/perl use strict; use warnings; use Text::ParseWords; my @words = parse_line('\s+', 0, "abcd efgh 'ijklm no pqrs' tuv"); use Data::Dumper; print Dumper \@words; Output: C:\Temp> ff $VAR1 = 'abcd', 'efgh', 'ijklm no pqrs', 'tuv' ; You can look at the source code for Text::ParseWords::parse_line to see the pattern used.

" question I have ever had about Perl has been quickly answered by "Use this module that does exactly what you want. " – Jergason Mar 17 '10 at 3:40 Figures there is a package to do exactly what I need. I wasn't sure what I was looking for.

You're a rock star, thanks! – Kivin Mar 17 '10 at 4:24 4 @Jergason blame it on the wonderful people who, when they don't find exactly what they need, and have to write it themselves, CPAN the result afterwards. :) – hobbs Mar 17 '10 at 4:36 And then blame the wonderful people who write CPAN modules that use every other possible CPAN module, no matter how tiny, so that you must pull in ten other mostly-useless modules.

– Zan Lynx Mar 17 '10 at 23:31 @zan FWIW, Text::ParseWords is in the core. Also, modules or distributions with giant dependency lists are not that common. – Sinan Ünür Mar 17 '107 at 0:11.

Use strict; use warnings; my $text = "abcd efgh 'ijklm no pqrs' tuv 'xwyz 1234 9999' 'blah'"; my @out; my @parts = split /'/, $text; for ( my $i = 1; $i.

Now you have two problems. Allow me to infer a little bit. You want an arbitrary number of fields, where a field is composed of text without containing a space, or it is separated by spaces and begins with a quote and ends with a quote (possibly with spaces inbetween).

In other words, you want to do what a command line shell does. You really should just reuse something. Failing that, you should capture a field at a time, with a regex something like: ^ *(^ +|'^'*')(.*) Where you append group one to your list, and continue the loop with the contents of group 2.

A single pass through a regex wouldn't be able to capture an arbitrarily large number of fields. You might be able to split on a regex (python will do this, not sure about perl), but since you are matching the stuff outside the spaces, I'm not sure that is even an option.

You might be able to split on a regex (python will do this, not sure about perl), but since you are matching the stuff outside the spaces, I'm not sure that is even an option.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions