Re: Right regex to match -- comments or blank line?

From: jan (jan_at_ossifrage.net)
Date: 03/05/04


Date: 5 Mar 2004 07:35:49 -0800

chomp(); is removing the \n;

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

Cheers,
Jan

"Dave Sisk" <dsisk@nc.rr.com.0nospam0> wrote in message news:<0QT1c.45536$%d3.4130346@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.



Relevant Pages

  • Floating Point Number - Wierd
    ... I am running a simple script that is reading through a text file and adding up ... floating point numbers from each line. ...
    (perl.beginners)
  • [newbie] chomp acting weird (or me not understanding how it works??)
    ... I'm reading lines from an inputfile which contains on every line a word, ... I want to reconstruct the ... I'd like to use chomp, ...
    (comp.lang.perl.misc)
  • Re: Variable interpolation on STDIN ?
    ... Abhinav wrote in comp.lang.perl.misc: ... > I am reading the name of a file from STDIN. ... > chomp; ...
    (comp.lang.perl.misc)
  • RE: chomp operator
    ... One place where chompcomes in handy is when you're reading from a ... print $line, $foo; ... Without a 'chomp $line' the program will print: ... some text to append to line ...
    (perl.beginners)
  • Re: Unexplained output for PERL print statement
    ... > removed the Line Feed and left the Carriage Return in place. ... When reading a DOS file on Windows, chomp removes both characters. ...
    (comp.lang.perl.misc)