yskmonk has asked for the wisdom of the Perl Monks concerning the following question:

I am searching for few lines randomly from my outfile.html and placing them in an final.txt file.

here is my code:

open OUTFILE, "<$outfile"; open FINAL, ">$final"; while (<OUTFILE>) { print FINAL if /(line1)/; print FINAL if /(line2)/; print FINAL if /(line3)/; }

here is my output

line1<br> line2<br> line3<br>

my questions is my final.txt has  <br> at the end of each line as shown abouve.

how can I remove that?

Please Advise Thanks in advance!

Replies are listed 'Best First'.
Re: removing <br> from my output
by Utilitarian (Vicar) on May 19, 2009 at 16:06 UTC
Re: removing <br> from my output
by ack (Deacon) on May 19, 2009 at 16:40 UTC

    The <br> character is undoubtedly at the end of each line in your OUTFILE. You are printing into FINAL exactly whatever was read from OUTFILE. If you don't want the <br> at the end of each line then you have to explicitly remove it right after you read each line from OUTFILE. For example, if each line in OUTFILE has a line return at the end, then you would normally chomp($_) in your while... block before you do the print tests.

    ack Albuquerque, NM
Re: removing <br> from my output
by raisputin (Scribe) on May 19, 2009 at 17:43 UTC
    while (<OUTFILE>) { s/<br>//gi; print FINAL if /(line1)/; print FINAL if /(line2)/; print FINAL if /(line3)/;
    my input file reads:
    This is line1<br> This is line2<br> This is line3<BR>
    results in:
    $ cat final.txt This is line1 This is line2 This is line3
      Yes it worked.Thank you so much!

      I have 2 more questions:

      1. here is how my outfile.html looks
      line1=10 line3=20 line3=30 line4=Mon May 18 02:28:58 EDT 2009 line5=60
      and here is how my code looks for extracting lines like line1=10,line2=20
      print FINAL if /(line1=\d+)/; print FINAL if /(line2=\d+)/;

      but as my outfile.html has also some thing like below :

      line4=Mon May 18 02:28:58 EDT 2009
      how can I extract this line?

      2.my final output has few lines repeating since my outfile.html has lines repeating.how can I make it extract these lines only once?

Re: removing <br> from my output
by bichonfrise74 (Vicar) on May 20, 2009 at 05:03 UTC
    Try this...
    #!/usr/bin/perl use strict; while (<DATA>) { s/<br>$//; print if /(line[123])/; } __DATA__ line4<br> line1<br> test<br> line2<br> line3<br>
      Non of the above suggested methods are working... Please advise me further on this Thanks!
        yskmonk? Is that you? yskmonk said repeately that it is working for him.
Re: removing <br> from my output
by mboudreau (Acolyte) on May 19, 2009 at 20:55 UTC
    Try this:
    print FINAL "$1\n" if /(line1)/;
      This does not address where the line reads line1=Mon as asked above
Re: removing <br> from my output
by Anonymous Monk on May 19, 2009 at 19:04 UTC
    Yes it worked.Thank you so much!

    I have 2 more questions:

    1. here is how my outfile.html looks
    line1=10 line3=20 line3=30 line4=Mon May 18 02:28:58 EDT 2009 line5=60
    and here is how my code looks for extracting lines like line1=10,line2=20
    print FINAL if /(line1=\d+)/; print FINAL if /(line2=\d+)/;

    but as my outfile.html has also some thing like below :

    line4=Mon May 18 02:28:58 EDT 2009
    how can I extract this line?

    2.my final output has few lines repeating since my outfile.html has lines repeating.how can I make it extract these lines only once?

Re: removing <br> from my output
by yskmonk (Initiate) on May 19, 2009 at 19:11 UTC
    Yes it worked.Thank you so much!

    I have 2 more questions:

    1. here is how my outfile.html looks
    line1=10 line3=20 line3=30 line4=Mon May 18 02:28:58 EDT 2009 line5=60
    and here is how my code looks for extracting lines like line1=10,line2=20
    print FINAL if /(line1=\d+)/; print FINAL if /(line2=\d+)/;

    but as my outfile.html has also some thing like below :

    line4=Mon May 18 02:28:58 EDT 2009
    how can I extract this line?

    2.my final output has few lines repeating since my outfile.html has lines repeating.how can I make it extract these lines only once?

      while (<OUTFILE>) { s/<br>//gi; print FINAL if /(line\d=(\d||[A-Za-z]{3}).)/; }
      May be fugly (guys?) but that extracts the lines as you show them anyway. As for not having duplicates. I am not sure, but I will see if I can come up with something. I'm kinda a newb at perl, so...