Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Perl dont write my data base

by Anonymous Monk
on Jan 17, 2003 at 21:55 UTC ( [id://227812]=perlquestion: print w/replies, xml ) Need Help??

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

I create a perl script (over Windows XP platform) and my script not write a data base. Whay?
------------------------------

#!/usr/bin/perl # Get the form variables if ($ENV{'REQUEST_METHOD'} eq 'GET') { $buffer = $ENV{'QUERY_STRING'}; } else { read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'}); } # Break em up into a format the script can read @pairs = split(/&/, $buffer); foreach $pair (@pairs) { ($name, $value) = split(/=/, $pair); $value =~ tr/+/ /; $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/e +g; $FORM{$name} = $value; } $path = "C:\Program Files\sambar51\cgi-bin"; open(TEST, ">>path\textNX.txt"); print TEST "$FORM{'text'}\n"; close(TEST); print "Content-type: text/html\n\n"; print "Textul a fost adaugat in textNX.txt"; exit;
-----------------------------------------
I use sambar server. Please help me.
edited by boo_radley : code tags added, moved to SOPW.

Replies are listed 'Best First'.
Re: Perl dont write my data base
by sauoq (Abbot) on Jan 17, 2003 at 22:21 UTC

    Chances are it's a permissions issue. You should always check that your calls to open() succeed. It's common to do it something like this:

    open(TEST, ">>path\textNX.txt") or die "Couldn't open path\textNX.txt: + $!\n";
    Do that. Try again. Then check your error logs.

    Actually, another thing stands out to me. That filename won't be what you expect. That backwhack-t in "path\textNX.txt" is a tab. Either use two backwhacks, single quotes, or forward slashes.

    Update: And you've forgotten your dollar sign before 'path' in your call to open.

    -sauoq
    "My two cents aren't worth a dime.";
    
Re: Perl dont write my data base
by Mr. Muskrat (Canon) on Jan 17, 2003 at 22:29 UTC

    I'm not going to get into "use strict, -w and CGI" this time...

    $path = "C:\Program Files\sambar51\cgi-bin";
    should probably be written as
    $path = "C:/Program Files/sambar51/cgi-bin";

    open(TEST, ">>path\textNX.txt");
    should be
    open(TEST, ">>", "$path/textNX.txt");

    print "Content-type: text/html\n\n";
    can be written as
    print "Content-type: text/plain\n\n";
    since you only printing plain text.

Re: Perl dont write my data base
by Coruscate (Sexton) on Jan 18, 2003 at 01:16 UTC

    Mr. Muskrat mentioned the part about changing your $path = "C:\Program Files..." to use forward slahes instead of backslahes, and that's the best advice. If you really want to use your windows-formatted paths, use single quotes instead, so that your backslahes aren't taken to mean a special character. But, forward slahes look much better, and don't worry: perl is smart enough to always (I can't think of any exceptions, though there may be one or two), change the forward-slashes to backslashes in system calls.

    I create a perl script (over Windows XP platform) ... #!/usr/bin/perl
    Okay, I know that windows uses file associations over actually executing the shebang line (in most cases), but you should probably be using something like "#!c:/perl/bin/perl -w" as your first line (or wherever you have perl installed). Also note the use of the '-w' switch. It will make your life easier (though 'use strict' is even more life-saving, so you should probably add that one as well).

    if ($ENV{'REQUEST_METHOD'} eq 'GET') { $buffer = $ENV{'QUERY_STRING'}; } else { read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'}); } # Break em up into a format the script can read @pairs = split(/&/, $buffer); foreach $pair (@pairs) { ($name, $value) = split(/=/, $pair); $value =~ tr/+/ /; $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/e +g; $FORM{$name} = $value; }
    {sigh}. I don't know who ever wrote this snippet, as I've seen it many many times. Put simply, it's ugly. I can rewrite that chunk of code with 2 lines:
    use CGI ':standard'; my %FORM = CGI->Vars;
    'perldoc CGI' for more info on this. Then there's the thing with 'path\textNX.txt', another monk has already clued you in on this one.

    Summary/Revision:

    1. '/' not '\'
    2. -w or 'use warnings;'
    3. 'use strict;'
    4. 'perldoc CGI;'

Re: Perl dont write my data base
by Nitrox (Chaplain) on Jan 17, 2003 at 22:32 UTC
    _SNIP_

    Mr. Muskrat beat me to the submit button. :)

    -Nitrox

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://227812]
Approved by Mr. Muskrat
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others rifling through the Monastery: (6)
As of 2024-04-25 18:06 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found