470,614 Members | 1,458 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,614 developers. It's quick & easy.

Right regex to match -- comments or blank line?

Hi Folks:

I need the right regex to match either a comment line (--) or a blank line.
What I've got below doesn't seem to be working like I'd expect. I've posted
a snippet of what I have below...would anyone be kind enough to point me in
the right direction? I also apparently need to strip the ';' off the end
of the INSERT statement...

TIA,
Dave

-----------------------------------------------------------
while(<SCRIPT>) {

chomp;

$insert = $_;

unless ($insert =~ /^--|^\s+$\n/) {

$rv = $dbh->do($insert);

}

}

The script I'm reading in looks like this:

-- Some comments on this line, the next line is a blank line, then the next
lines are inserts.

insert into sometable values('whatever1');

insert into sometable values('whatever2');

etc.


Jul 19 '05 #1
3 11925
jan
chomp(); is removing the \n;

try:
unless ($insert =~ /^--|^\s?$/)

Cheers,
Jan

"Dave Sisk" <ds***@nc.rr.com.0nospam0> wrote in message news:<0Q*********************@twister.southeast.rr .com>...
Hi Folks:

I need the right regex to match either a comment line (--) or a blank line.
What I've got below doesn't seem to be working like I'd expect. I've posted
a snippet of what I have below...would anyone be kind enough to point me in
the right direction? I also apparently need to strip the ';' off the end
of the INSERT statement...

TIA,
Dave

-----------------------------------------------------------
while(<SCRIPT>) {

chomp;

$insert = $_;

unless ($insert =~ /^--|^\s+$\n/) {

$rv = $dbh->do($insert);

}

}

The script I'm reading in looks like this:

-- Some comments on this line, the next line is a blank line, then the next
lines are inserts.

insert into sometable values('whatever1');

insert into sometable values('whatever2');

etc.

Jul 19 '05 #2
"jan" <ja*@ossifrage.net> wrote in message
news:fc**************************@posting.google.c om...
chomp(); is removing the \n;


Actually it is removing whatever the value of $/ is. Granted, by default
that is \n, but some people may change it and wonder why chomp() doesn't
work any more.

jue
Jul 19 '05 #3
In article <fc**************************@posting.google.com >, jan
<ja*@ossifrage.net> wrote:

[top-posting fixed]
"Dave Sisk" <ds***@nc.rr.com.0nospam0> wrote in message
news:<0Q*********************@twister.southeast.rr .com>...
Hi Folks:

I need the right regex to match either a comment line (--) or a blank line.
What I've got below doesn't seem to be working like I'd expect. I've posted
a snippet of what I have below...would anyone be kind enough to point me in
the right direction? I also apparently need to strip the ';' off the end
of the INSERT statement...

TIA,
Dave

-----------------------------------------------------------
while(<SCRIPT>) {
chomp;
$insert = $_;
unless ($insert =~ /^--|^\s+$\n/) {
Do you want to allow for blanks before the '--'?
Do you require a blank line have whitespace in it?

If "yes" and "no", change to:
unless ( $insert =~ /^\s*--|^\s*$/ ) {

To strip off semi-colon at end:

$insert =~ s/;\s*$//;
$rv = $dbh->do($insert);
}
}

The script I'm reading in looks like this:

-- Some comments on this line, the next line is a blank line, then the next
lines are inserts.

insert into sometable values('whatever1');

insert into sometable values('whatever2');

etc.

chomp(); is removing the \n;

try:
unless ($insert =~ /^--|^\s?$/)

Cheers,
Jan


Note: this newsgroup is defunct. Try comp.lang.perl.misc in the future.
Jul 19 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

6 posts views Thread by Vishant | last post: by
2 posts views Thread by Mr.Clean | last post: by
2 posts views Thread by Daniel Billingsley | last post: by
8 posts views Thread by rjb | last post: by
5 posts views Thread by JackRazz | last post: by
3 posts views Thread by Jeff | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.