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

I guess what I'm not getting a clear picture of maybe described like this:

If the current output to the HTML page from $guestbookreal = "/home/flute/usedflutes-www/new_listings_publish.html"; (http://www.usedflutes.com/new_listings_publish.html is producing a string that I can literally copy & paste, drop into a GUI, and hit "GO" adds a new record to MySQL without any problem, then isn't there a syntax equivalent for that move - or is that not possible??

Thanks once again for your help (and patience with me!) with this CountZero,

-Bob
  • Comment on 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: Modifying Perl script to write to MySQL??
by CountZero (Bishop) on Feb 16, 2004 at 16:36 UTC
    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

      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

      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