in reply to Re: Re: Re: Re: Re: Re: Re: Modifying Perl script to write to MySQL??
in thread Modifying Perl script to write to MySQL??

I'm not sure I understand what you mean by "content?"
Isn't this is a variable - just a string which changes with each new ad??

If so, then I keep imagining an equation which might be expressed something like this (and I know this can't be right...)

$guestbookreal=$sth=$dbh->prepare($guestbookreal);
$sth->execute();

yikes!...   :-|

-Bob
  • Comment on Re: Re: Re: Re: Re: Re: Re: Re: Modifying Perl script to write to MySQL??

Replies are listed 'Best First'.
Re: Re: Re: Re: Re: Re: Re: Re: Re: Modifying Perl script to write to MySQL??
by CountZero (Bishop) on Feb 16, 2004 at 20:34 UTC
    Isn't this is a variable - just a string which changes with each new ad??

    Not in this case: $guestbookreal just holds the path and name of the file in which the data of the ad are stored. So you have to read what is in that file, which can be done as follows:

    my $content; open FILE, '<', $guestbookreal; # Open a filehandle FILE to $guestbook +real while (<FILE>) { chomp; # delete any EOL character(s) $content .= $_; # Add the next line to the previous parts }

    Now $content has the data you need. Then you do:

    $sth=$dbh->prepare($content); $sth->execute();

    Before anyone notices: I left out all error checking! A real script would be full of or die 'xxxx' statements.

    Now as to the basic script you were using. The author himself wrote:
    While the free code found at my web site has not evolved much in recent years, the general programming practices and standards of CGI programs have. nms is an attempt by very active programmers in the Perl community to bring the quality of code for these types of programs up to date and eliminate some of the bad programming practices and bugs found in the existing Matt's Script Archive code. I would highly recommend downloading the nms versions if you wish to learn CGI programming. The code you find at Matt's Script Archive is not representative of how even I would code these days.
    So do me a favour and go to http://nms-cgi.sourceforge.net/ and replace your script with a more modern and up-to-date version.

    CountZero

    "If you have four groups working on a compiler, you'll get a 4-pass compiler." - Conway's Law

      I've tried to modify the script as I thought you have suggested:

      http://www.usedflutes.com/countzero.txt

      Does that look like what you had in mind?
      If so, can you please tell me what then becomes of the  $guestbookreal = "/home/flute/usedflutes-www/new_listings.html"; part of the script?

      Thanks again CountZero for helping me out with this.

      -Bob

      p.s. Yes, I have downloaded the nms script and do intend at some point in the not-too-distant-future to update my script. I very much appreciate the encouragement from yourself, Dave and others to do so, thanks.
        You should put the while (<FILE>) { on a line by its own or else it will not be seen because of the comment prior in that line.

        As to what becomes of the $guestbookreal part of the script I have no idea whatsoever. For that I would have to analyze the whole script and sadly I'm lacking in time to do so.

        CountZero

        "If you have four groups working on a compiler, you'll get a 4-pass compiler." - Conway's Law