[ale] One for the perl hackers
Robert L. Harris
robert.l.harris at gmail.com
Thu Oct 3 19:04:10 EDT 2013
For the Curious, Larry on Denver PM came back with this:
That line looks like a line you would get in a CSV file, so I would
handle it that way:
use Text::CSV;
my $line = 'component1,component2,"This is my, test string",
component4';
my $csv = Text::CSV->new;
$csv->parse($line) or die $csv->error_diag();
my @columns = $csv->fields();
At this point, @columns contains:
$columns[0]: 'component1'
$columns[1]: 'component2'
$columns[2]: 'This is my, test string'
$columns[3]: ' component4'
Which worked perfectly.
Robert
On Thu, Oct 3, 2013 at 3:22 PM, Robert L. Harris
<robert.l.harris at gmail.com>wrote:
>
> *Sorry for the OT but my only perl lists have gone dark a long time ago*
>
>
> $String='component1,component2,"This is my, test string", component4';
>
> ($C1, $C2, $Str, $C4) = split(',', $String);
>
> I'm only getting "This is my" in $Str and $C4 does not contain
> "component4". Is there a graceful way of handling this? It's a 1 in 10000
> chance it'll break but accuracy counts.
>
> Robert
>
>
> --
> :wq!
> ---------------------------------------------------------------------------
> Robert L. Harris
>
> DISCLAIMER:
> These are MY OPINIONS With Dreams To Be A King,
> ALONE. I speak for First One Should Be A Man
> no-one else. - Manowar
>
--
:wq!
---------------------------------------------------------------------------
Robert L. Harris
DISCLAIMER:
These are MY OPINIONS With Dreams To Be A King,
ALONE. I speak for First One Should Be A Man
no-one else. - Manowar
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.ale.org/pipermail/ale/attachments/20131003/9c7ec645/attachment-0001.html>
More information about the Ale
mailing list