in reply to need to parse firts part of SQL-query (regex question)
#!/usr/local/bin/perl -l # use strict; use warnings; my $sql = q{f1,f2, SUM(f3),CONCAT(f4,f5, f6), f7}; my @fields = split m{\s*,\s*}, $sql, 4; splice @fields, 3, 1, reverse map { $_ = reverse } split m{\s*,\s*}, reverse($fields[3]), 2; print for @fields;
Here's the output.
f1 f2 SUM(f3) CONCAT(f4,f5, f6) f7
The use of spaces with commas was inconsistent so I decided to discard the spaces during the split.
Cheers,
JohnGG
|
|---|