Loading ...
Sorry, an error occurred while loading the content.
 

Re: [PBML] Almost There - A Little More Help, Please?

Expand Messages
  • Ofir
    Wow, man! Will it really take me a lifetime to learn what you know about Perl? ... Thank you very much! I ll dive into your code ASAP! Ofir ... From: Charles
    Message 1 of 5 , Apr 1, 2002
      Wow, man! Will it really take me a lifetime to learn what you know about
      Perl? ...
      Thank you very much! I'll dive into your code ASAP!
      Ofir

      ----- Original Message -----
      From: "Charles K. Clarkson" <cclarkson@...>
      To: <perl-beginner@yahoogroups.com>
      Sent: Monday, April 01, 2002 12:00 PM
      Subject: Re: [PBML] Almost There - A Little More Help, Please?


      > "Ofir" <ofirb1@...> wrote:
      >
      > : Dear Charles,
      > : I know my code is VERY clumsy. I guess that's because I'm learning all
      by
      > : myself (and great guys like you).
      > :
      > : You can take a look at the result (output), at this address:
      > : http://fsuarchive.jdc.org.il/cgi-bin/ticker/ofir_news.cgi
      > : I'm sorry it's in Hebrew, but I guess you can get the idea.
      > :
      > : The whole idea is fetching a news file, from our local news
      > : backend text file (at:
      > : http://www.ynet.co.il/Ext/Chn/News/NewsTickerCgi/0,8102,0,00.txt )
      > : which has a very ugly structure ...)
      > :
      > : So, I'm fetching this file, saving it on my server, open it, reading and
      > : splitting the four-lines records (there are always only 5 news items
      there,
      > : i.e. five - four lines records, and if you see the source of it - you'll
      > : notice 2 excessive blank lines there).
      >
      > You can test for a malformed line in the until block. See below.
      >
      > : Then, I'm cleaning the unwanted characters (there's a "@f=arial.gif" and
      > : other characters I don't need), and printing out the news in a table
      (at:
      > : http://fsuarchive.jdc.org.il/cgi-bin/ticker/ofir_news.cgi)
      >
      > There's an easier way to clean this up. Instead of all those
      > substitutions just try to match the url. Pull it out if it matches
      > or continue (or end) if it doesn't.
      >
      > last unless $x[0] =~ /openWin\('([^']*)/;
      >
      > This skips printing that sixth table row. The url is in $1 on a match.
      >
      > : So, there are 5 news items, but I always get a 6 blank line at the end
      of
      > : the table.
      > : I added the VERY not descriptive $c (counter for printing: 1,2, 3, etc
      in
      > : the counter column...) and $i - for altering the lines HTML class
      (thus -
      > : their colors).
      > :
      > : No matter what I do - always I get the 6 lines.
      > :
      > : I'm attaching my whole very ill code, and I hope you won't be too mad at
      me
      > : ;-)
      >
      > No offense Ofir, but I don't even know you. How could I possibly
      > be mad at you?
      >
      > <soapbox>
      > I added:
      > use strict;
      > use warnings;
      >
      > and added 'my ' in front of the variables and, sure enough, there's
      > a typo near the bottom of the script. Doesn't affect the operation
      > unless there's an error. I let you find it on your own.
      > </soapbox>
      >
      > : ### Begin of ill Code
      > :
      > : #!D:/Perl/bin/Perl.exe
      > : ######### Configurations
      > : use LWP::Simple;
      > : use CGI::Carp qw(fatalsToBrowser); # just for debugging
      > : $mypath = "D:/apachegr/apache/htdocs/news";
      > : $news_file="ynet.txt";
      > : $my_file_name="$mypath/$news_file";
      > : $ynet_base="http://www.ynet.co.il";
      > : $logfile = "d:/apachegr/apache/htdocs/news/ynet_log1.txt";
      > : ######### Configurations
      >
      > :
      > : ######### Functions
      > : &Fetch_It;
      > : &Header;
      > : &get_records2($logfile);
      > : &Footer;
      > : ######### Functions
      >
      > Get out of the habit of placing the '&' prefix on subroutine
      > calls:
      >
      > Fetch_It();
      > Header();
      > get_records2($logfile);
      > Footer();
      >
      > : ######### Header
      > : sub Header {
      > : print "Content-type: text/html\n\n";
      > : print "<HTML>\n";
      > : print "<HEAD>\n";
      > : print "<meta http-equiv='content-type' content='text/html;
      > : charset=windows-1255'>\n";
      > : print "<title>JDC-News</title>\n";
      > :
      > : print <<"HTML_code";
      > : <style type="text/css">
      > : <!--
      > : .presser {background-color:#6699cc; font-family: Arial, Helvetica,
      > : sans-serif; font-size: 12; font-weight: bold; color: #FFFFFF}
      > : .roll2 { font-family: Arial, Helvetica, sans-serif; font-size: 12px;
      COLOR:
      > : #0000FF; FONT-WEIGHT: normal; TEXT-DECORATION: underline}
      > : .presser1 {background-color:#6699cc; font-family: Arial, Helvetica,
      > : sans-serif; font-size: 12; font-weight: bold; color: #FFFFFF; border:
      1pt
      > : solid Black;}
      > : .back {color: #000000; background-color: #FFFFFF}
      > : .MainTable { font-family: Arial, Helvetica, sans-serif; font-size:
      12px;
      > : font-weight: normal; color: #000066}
      > : .TableHead { font-family: Arial, Helvetica, sans-serif; font-size:
      12px;
      > : font-weight: normal; color: #FFFFFF}
      > : .TableHead1 { font-family: Arial, Helvetica, sans-serif; font-size:
      12px;
      > : font-weight: normal; color: #FF0000}
      > : .DATA1 { font-family: Arial, Helvetica, sans-serif; font-size: 12px;
      > : font-weight: normal; color: #FFFFFF; background-color:#C0C0C0}
      > : .DATA0 { font-family: Arial, Helvetica, sans-serif; font-size: 12px;
      > : font-weight: normal; color: #FFFFFF; background-color:#999999}
      > : -->
      > : </style>
      > : HTML_code
      >
      > Good for you! Stylesheets are great. You should look into using
      > CGI::Application for CGI. I use CGI::APpplication + HTML::Template.
      > Quite a learning curve, but well worth it.
      >
      > : print "</HEAD>\n";
      > : print "<BODY>\n";
      > : print <<"END";
      > : <table border=0 cellpadding=0 cellspacing=0 width=100% bgcolor=FFCC00>
      > : <tr width="50%" bgcolor="#3399CC" align="left">
      > : <td bgcolor="#C0C0C0" class="TableHead">
      > : JDC-News</font></td>
      > : <td bgcolor="#C0C0C0" class="TableHead">2002
      > : </td>
      > : <td width="50%" bgcolor="#C0C0C0" align="right"
      > : class="TableHead">Version 1.0</td>
      > : </tr>
      > : </table>
      > : END
      > : }
      > : ######### Header
      > :
      > : ######### Get Records2
      > : sub get_records2 {
      > : @hdrs = ('#','çãùåú','ùòä');
      > : print "<BR><BR><TABLE BORDER=1 CELLSPACING=1 CELLPADDING=2 CLASS=DATA1
      > : ALIGN=CENTER DIR=RTL><TR><TH>";
      > : print join('</TH><TH>',@hdrs);
      > : print "</TH></TR>\n";
      > :
      > : my $file_name = shift;
      > : local *FH;
      > :
      > : open(FH,"$file_name") || die "Cannot open $file_name: $!";
      > :
      > : $i = 0;
      > : $c = 1;
      >
      > This is very amusing. Just can't break old habits, huh. Took me
      > the longest time to stop putting three letter prefixes on variable
      > names (ala VB).
      >
      > : until (eof FH) {
      > : my @x = map scalar <FH>, 1 .. 4;
      > :
      > : $x[7] = $c; # counter
      > : $x[0] =~ s/\@f=arial.gif c=#888888 r=javascript:openWin//;
      > : $x[0] =~ s/\('//;
      > : $x[0] =~ s/\'\)\;//;
      > : $x[0] =~
      > :
      s/','NewsFlash','menubar=no,resizable=no,scrollbars=yes,width=449,height=300
      > : //; $x[0] = "$ynet_base/$x[0]";
      > : $x[3] =~ s/$x[3]/<A HREF=\"$x[0]\">$x[3]<\/A>/;
      > : @x = @x[7,3,1];
      > : print "<TR CLASS=DATA$i VALIGN=TOP><TD>\n";
      > : print join("</TD><TD>",@x);
      > : print "</TD></TR>\n\n";
      > : $i = $i ? 0 : 1;
      > : $c++ ;
      > : }
      >
      > Okay, let's re-write the until block:
      >
      > my $toggle = 0;
      > my $counter = 1;
      > until (eof FH) {
      > my @record = map scalar <FH>, 1 .. 4;
      >
      > last unless $record[0] =~ /openWin\('([^']*)/;
      > chomp $record[3];
      > my $link = qq|<A HREF="$ynet_base$1">$record[3]</A>|;
      >
      > print qq|<TR CLASS="DATA$toggle" VALIGN="TOP"><TD>\n|;
      > print join("</TD><TD>", $counter++, $link, $record[1]);
      > print "</TD></TR>\n\n";
      > $toggle = $toggle ? 0 : 1;
      > }
      >
      > That seems to fix it as for as I can tell. Let us know if you
      > need more help.
      >
      > HTH,
      > Charles K. Clarkson
      > --
      > Clarkson Energy Homes, Inc.
      > CJ Web Work - Domains for Real Estate Investors.
      >
      > E Pluribus Unum -- One from many.
      >
      >
      >
      >
      >
      >
      > Unsubscribing info is here:
      http://help.yahoo.com/help/us/groups/groups-32.html
      >
      > Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/
      >
      >
      >
    Your message has been successfully submitted and would be delivered to recipients shortly.