line breaks in perl

Discussion in 'Programming' started by James Hertz, Dec 22, 2009.

  1. #1
    Hi,

    When I download email from my log, so they are listed after each other like this.

    email@email.comemail1@email.comemail3@email.com

    Rather like this

    email@email.com
    email2@email.com
    email3@email.com

    Someone who can see which is missing a line break?

    #print "$line\n";
    $mfh = $1;
    if ($mfh=~ m/email\./){
    #$contents .= "$mfh\n" ;
    $seen{$mfh}=1;
    #print "$mfh\n";
    }
     
    James Hertz, Dec 22, 2009 IP
  2. rainborick

    rainborick Well-Known Member

    Messages:
    424
    Likes Received:
    33
    Best Answers:
    0
    Trophy Points:
    120
    #2
    If you are trying to see plain text that was contained in a file that you download, it could simply be that the editor that you're using to read the text requires a \r and possibly \r\n. If you are trying to see the text in a web browser, you'll probably have to use HTML code <br> instead of \n.
     
    rainborick, Dec 22, 2009 IP
  3. HowDoYou

    HowDoYou Well-Known Member

    Messages:
    443
    Likes Received:
    11
    Best Answers:
    0
    Trophy Points:
    130
    #3
    #print "$line<br>";
    $mfh = $1;
    if ($mfh=~ m/email\./){
    #$contents .= "$mfh<br>" ;
    $seen{$mfh}=1;
    #print "$mfh<br>";
    }

    if its printing stright to your browser this will work.
     
    HowDoYou, Dec 22, 2009 IP
  4. James Hertz

    James Hertz Peon

    Messages:
    11
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    I run through a cron on the server and sent to my email so <br> does not, unfortunately.
     
    James Hertz, Dec 22, 2009 IP
  5. jedi.knight

    jedi.knight Peon

    Messages:
    20
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Where is the actual print statement? The one in the post is commented with a hash, or am I missing something?
     
    jedi.knight, Dec 23, 2009 IP
  6. James Hertz

    James Hertz Peon

    Messages:
    11
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #6
    There is nothing else and it comes out with a list, but there is no line break between each email.

    Do you have suggestions for changes to the script?
     
    James Hertz, Dec 23, 2009 IP
  7. James Hertz

    James Hertz Peon

    Messages:
    11
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #7
    Hi,

    There is little more here

    my $fh = new FileHandle ("< /var/log/mail.log") or die "an error occured ";
    my $line;

    while (<$fh>) {
    chomp;
    $line = $_;
    if ($line =~ m/^$dato .* to=<(.*\@email\.\w*).*status=sent.*>/){
    #print "$line\n";
    $mfh = $1;
    if ($mfh=~ m/email\./){
    #$contents .= "$mfh\n" ;
    $seen{$mfh}=1;
    #print "$mfh\n";
    }
     
    James Hertz, Dec 23, 2009 IP
  8. jedi.knight

    jedi.knight Peon

    Messages:
    20
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #8
    How about this one:

    
    #!/usr/bin/perl -w
    
    use strict;
    
    my $date = 'Dec 24';
    my $domain = 'email.com';
    
    open(FH, '/var/log/mail.log') or die 'An error occurred.';
    my %seen;
    
    while (<FH>) {
        m/^$date .* to=<([^>]+\@$domain)>.* status=sent .*/ and $seen{$1} = 1;
    }   
    
    print join "\n", sort keys %seen;
    print "\n";
    
    Code (markup):
     
    jedi.knight, Dec 23, 2009 IP
  9. impressive.designs

    impressive.designs Peon

    Messages:
    30
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #9
    How about this one:
     
    impressive.designs, Dec 24, 2009 IP