Hello,

Here is a regex question

I am using the following construct to ident embeded SQL:

   ($sql =<<EOF) =~ s/^\s+SQL: ?//gm;
      SQL: select row_id
      SQL:   from gs_employee_queue g_q
      SQL:  where g_q.YYYYMMDDHHMM = '$YYYYMMDDhhmm'
      SQL:    and g_q.action = 'D'
      SQL:    and g_q.status = 'Unprocessed'
EOF

The benefit is that the SQL is idented as the Perl code around it (the
program is easier to read) - and at the same time unnecessary idents are
removed before sending the SQL to the database.

The drawback is that every time when I need to extract the SQL (to run it
manually in the DB) - I have to remove all the  ' SQL:' tags manually. 

So naturally I want to live without the 'SQL:' label.
But then if I use just \s+ in the regex - it will remove different number of
spaces from different lines - thus ruining the SQL layout.

Question:
  How to construct the regex so that it subtracts the same amount of white
space from all the line. Namely, it should memorize the space from the first
line only - and then subtract it from all the lines.

I know how to do this with 2 regexes. But is there a way to do it in the
same one substitute (similar to how it is done above)?

Warmest Regards, 
Lev Selector, (212) 902-3040

Reply via email to