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

Yes of course there is: just take the content of "/home/flute/usedflutes-www/new_listings_publish.html", put it in a scalar variable and give it to $sth=$dbh->prepare($yourscalarvariable); $sth->execute();

CountZero

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

  • Comment on Re: Re: Re: Re: Re: Re: Re: Modifying Perl script to write to MySQL??
  • Download Code

Replies are listed 'Best First'.
Re: Re: Re: Re: Re: Re: Re: Re: Modifying Perl script to write to MySQL??
by bobafifi (Beadle) on Feb 16, 2004 at 17:07 UTC
    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
      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.
Re: Re: Re: Re: Re: Re: Re: Re: Modifying Perl script to write to MySQL??
by bobafifi (Beadle) on Feb 16, 2004 at 18:42 UTC
    OK - looking around on the Web, I've found three "content->scalar" equations:
    { local $/; $content = <HANDLE> } ===== open FILE, "inputfile" or die "Couldn't open file"; $content.=<FILE> close FILE; ===== open FILE, 'inputfile' or die "Could not open file inputfile: $!"; sysread(FILE, my $content, -s FILE); close FILE or die "Could not close file: $!";
    Is this what you're referring to and if so, can you please recommend which one of the above I should try using?

    Thanks again,

    -Bob