Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Re: Record Separator affecting Regex

by Mr. Muskrat (Abbot)
on Nov 07, 2002 at 18:56 UTC ( #211183=note: print w/ replies, xml ) Need Help??


in reply to Record Separator affecting Regex

If you really need to redefine the record seperator, you could do something like this:

#!/usr/bin/perl use strict; use warnings; $/ = ";\n"; { local $/ = "\n"; while (my $line = <DATA> ){ $line =~ s/^#[^\r\n]*//g; # get rid of any comments print "Query: $line\n" if ($line !~ /^\s+$/); } } __DATA__ # one comment # two comment # another comment insert into table_name values(1, 'testing 1 2 3'); # more comments insert into table_name values (2, 'test &#149;');

Output:

Query: insert into table_name values(1, 'testing 1 2 3'); Query: insert into table_name values (2, 'test &#149;');


Comment on Re: Record Separator affecting Regex
Select or Download Code
Replies are listed 'Best First'.
Re^2: Record Separator affecting Regex
by tadman (Prior) on Nov 07, 2002 at 19:56 UTC
    As a note, there's a way to check for "lines which are composed only of spaces" that I find much more succinct:
    print "Query: $line" if ($line =~ /\S/);
    Or more generically:
    next unless ($line =~ /\S/); print "Query: $line";
    "Not composed entirely of spaces" is equivalent to "contains a non-space character", at least in this context.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (20)
As of 2015-07-29 17:21 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (266 votes), past polls