Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3

Thread: Hard Return

  1. #1
    New Coder
    Join Date
    Aug 2002
    Posts
    13
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question Hard Return

    I have a flat text file with a list of email addresses each with a hard return after the address. Is there a way to replace the hard return with a ; ?? Thanks in advance!

  • #2
    Regular Coder
    Join Date
    Jul 2002
    Location
    London, UK
    Posts
    126
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Something like this perhaps:
    Code:
    #!/usr/bin/perl -w
    use strict;
    
    my $filename, $data;
    $filename = "dbfile.txt";
    
    open (DATA, "<$filename") || die "Couldn't open $filename for reading: $!";
    undef $/; #this means the next line will slurp all the data in..
    $data = <DATA>;
    $/ = "\n";
    close DATA;
    
    $data =~ s/\n/;\n/sg;
    
    open (DATA, ">$filename") || die "Couldn't open $filename for writing: $!";
    print DATA $data;
    close DATA;
    That's how I'd do it... hope it helps a bit.
    Last edited by Mouldy_Goat; 08-10-2002 at 01:23 AM.

  • #3
    New Coder
    Join Date
    Aug 2002
    Posts
    24
    Thanks
    0
    Thanked 0 Times in 0 Posts

    hey.

    If he wanted to actually REPLACE the hard CR with a semicolon...

    $data =~ s/\n/;/sg;

    Which should give the string instead:

    joe@noemail.com;george@yyahoo.com;clumsy@dummy.com

    then open write print etc..

    However, I've run across this problem with some servers...
    If the file has "@" directly in it, then that needs to be escaped as well.

    Maybe add to the substitution list:
    $data=~ s/\@/\\@/sg;

    It all depends on the server/perl config, and the program that's working with it though. I've had problems with the stupid @ character in parsed files before, and I use 3 different sun/unix/linux setups... well heck what do I know. They got idiot brains of their own.

    Good grief, these escaped slashes make me mad anyways. I mean, is there a REAL exact list of characters and combinations that MUST be escaped so's Perl never produces an error? 100 percent of the time? I wish that linux/unix admins followed all of the same standard protocols for their server setups.

    It ain't the 95% that's the problem, it's the 5%.

    hmmm, maybe the single semi-colon sub needs to be escaped also? dunno. haven't tried it.
    Last edited by pager; 08-14-2002 at 06:02 AM.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •