Monks,

I'm working on a database using a dbm file indexed with the IP of the user's computer ($ENV{REMOTE_ADDR}). The problem is that if I set it to $dbm_hash{$ENV{REMOTE_ADDR}} I get errors, both in CLI and CGI modes. If I do $userIP = $ENV{REMOTE_ADDR} and then call $dbm_hash($userIP) the same problems occure. However, if I do $userIP = "192.1.1.191" the script will run in CLI, but still errors out in CGI. What am I doing wrong?

~~Guildencrantz
#my $userIP = $ENV{REMOTE_ADDR}; my $userIP = "129.168.1.100"; my @formData = split/&/, $ENV{QUERY_STRING}; my %rawData; my $dbEntry; foreach (@formData) { my ($name, $value) = split /=/, $_; $name =~ tr/+/ /; $name =~ s/%([a-f0-9][a-f0-9])/chr(hex($1))/egi; $value =~ tr/+/ /; $value =~ s/%([a-f0-9][a-f0-9])/chr(hex($1))/egi; $rawData{$name} = $value; } $dbEntry = "<TR><TD>$userIP</TD><TD>$rawData{user}</TD><TD>$rawData{se +rver}</TD><TD>$rawData{serverpw}</TD><TD>$rawData{gameDiff}</TD><TD>$ +rawData{worldDiff}</TD><TD>$rawData{map}</TD><TD>$rawData{dod}</TD><T +D>$rawData{teamEnabled}</TD><TD>$rawData{pauseEnabled}</TD><TD>$rawDa +ta{pvpEnabled}</TD><TD>$rawData{joinEnabled}</TD><TD>$rawData{chooseS +tartEnabled}</TD><TD>$rawData{newRestrictionEnabled}</TD></TR>"; my %allIPs; dbmopen(%allIPs, "database/allIPs", 0664) or die "Cannot open allIPs database: $!"; $allIPs{$userIP} = $dbEntry or die "$!"; dbmclose %allIPs;

In reply to dbm troubles by Guildencrantz

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.