FAQ
Hi All,

I'm new to perl, so this may seem really basic, so any hints or
directions to help files would be greatly appreciated. :-)

I written a script that fetches a file from my web server (LWP::Simple
and Net::FTP::Common both work) and loads it into mysql. (DBI) That
part works great! The problem I'm having is the file in loading into
mysql is double spaced. How can I go about deleting the blank lines
before I load it into mysql?

Thanks!

Brian
bvolk@bvolk.com

Search Discussions

  • Timothy Johnson at Mar 26, 2002 at 10:01 pm
    Try this:

    open(INFILE,"myfile.txt");
    open(OUTFILE,"SSlines.txt");
    while(<INFILE>){
    unless($_ eq "\n"){ #blank lines probably have only a \n
    print OUTFILE $_;
    }
    }

    -----Original Message-----
    From: Brian Volk
    Sent: Tuesday, March 26, 2002 1:48 PM
    To: beginners@perl.org
    Subject: delete blank lines from a file?


    Hi All,

    I'm new to perl, so this may seem really basic, so any hints or
    directions to help files would be greatly appreciated. :-)

    I written a script that fetches a file from my web server (LWP::Simple
    and Net::FTP::Common both work) and loads it into mysql. (DBI) That
    part works great! The problem I'm having is the file in loading into
    mysql is double spaced. How can I go about deleting the blank lines
    before I load it into mysql?

    Thanks!

    Brian
    bvolk@bvolk.com


    --
    To unsubscribe, e-mail: beginners-unsubscribe@perl.org
    For additional commands, e-mail: beginners-help@perl.org


    --------------------------------------------------------------------------------
    This email may contain confidential and privileged
    material for the sole use of the intended recipient.
    If you are not the intended recipient, please contact
    the sender and delete all copies.
  • Brian Volk at Mar 26, 2002 at 11:13 pm
    Timothy,

    Thank you very much for the quick reply! It works great!!!! :-)


    Brian


    Timothy Johnson wrote:
    Try this:

    open(INFILE,"myfile.txt");
    open(OUTFILE,"SSlines.txt");
    while(<INFILE>){
    unless($_ eq "\n"){ #blank lines probably have only a \n
    print OUTFILE $_;
    }
    }

    -----Original Message-----
    From: Brian Volk
    Sent: Tuesday, March 26, 2002 1:48 PM
    To: beginners@perl.org
    Subject: delete blank lines from a file?


    Hi All,

    I'm new to perl, so this may seem really basic, so any hints or
    directions to help files would be greatly appreciated. :-)

    I written a script that fetches a file from my web server (LWP::Simple
    and Net::FTP::Common both work) and loads it into mysql. (DBI) That
    part works great! The problem I'm having is the file in loading into
    mysql is double spaced. How can I go about deleting the blank lines
    before I load it into mysql?

    Thanks!

    Brian
    bvolk@bvolk.com
  • Randal L. Schwartz at Mar 27, 2002 at 6:42 pm
    "Timothy" == Timothy Johnson writes:
    Timothy> Try this:

    Timothy> open(INFILE,"myfile.txt");
    Timothy> open(OUTFILE,"SSlines.txt");
    Timothy> while(<INFILE>){
    Timothy> unless($_ eq "\n"){ #blank lines probably have only a \n
    Timothy> print OUTFILE $_;
    Timothy> }
    Timothy> }

    The "probably" is spooky there. "is blank" or "looks blank" are
    two different things. Yours is fine for "is blank". For "looks blank",
    just accept the ones that have /\S/ somewhere:

    while (<INFILE>) {
    print OUTFILE if /\S/;
    }

    --
    Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
    <merlyn@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
    Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
    See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupbeginners @
categoriesperl
postedMar 26, '02 at 9:45p
activeMar 27, '02 at 6:42p
posts4
users3
websiteperl.org

People

Translate

site design / logo © 2022 Grokbase