Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Re: need to parse firts part of SQL-query (regex question)

by johngg (Canon)
on Jan 17, 2008 at 17:13 UTC ( [id://662921]=note: print w/replies, xml ) Need Help??


in reply to need to parse firts part of SQL-query (regex question)

You can attack this from both ends of the string using split with a third argument limiting the number of resultant fields and reverse.

#!/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

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://662921]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others goofing around in the Monastery: (3)
As of 2024-04-19 19:10 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found