in reply to Re^2: validating a quoted string
in thread validating a quoted string
UPDATE
You can parse the strings with Text::CSV
#!/usr/bin/perl use warnings; use strict; use Text::CSV; my @strings = ( '"my" "dog"', '"my" "dog shepherd"', 'my dog', 'my "dog shepherd"', '"my "dog"', 'my "dog shepherd', ); my $csv = Text::CSV->new ( {sep_char => ' '} ) or die "Cannot use CSV: ".Text::CSV->error_diag (); foreach my $string (@strings){ open my $fh, '<', \$string or die "Cannot open string"; if (((my $temp = $string) =~ tr/"//) % 2){ warn "invalid string"; next; } my $row = $csv->getline($fh); if (!defined $row) { warn "getline failed"; next; } close $fh; $" = ' | '; print "@$row\n"; }
|
|---|