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

When I update a record in my DBM file, %09 is appended at the frontside of each value. This causes a problem when I use the values as input for the defaults on an HTML form created via perlscript.

I am aware that I can simply remove the %09 (some sort of tab sequence) from each value using string operations, but how do I stop the append from happening in the first place? Thanks.

colouroflove@yahoo.com
  • Comment on Updating entry in DBM file adds extra character %09

Replies are listed 'Best First'.
Re: Updating entry in DBM file adds extra character %09
by dws (Chancellor) on Mar 18, 2002 at 00:48 UTC
    When I update a record in my DBM file, %09 is appended at the frontside of each value.

    Show us a snippet of code that exhibits this behavior.

      Note, I've tried this with and without the delete function that here preceeds the update. Also, I am not certain that the character appended is always %09, but I know with the comment field it is definitely %09.

      dbmopen(%synusers,"synusers",0666) || die "Can't open synusers DBM fil +e\n"; #search database entries while (($key, $value) = each(%synusers)){ if (index($key,$fields{'updalumname'})!=-1){ ($alumemail, $emailpub, $alumsnail1, $snail1pub, $alumsna +il2, $snail2pub, $alumsnail3, $snail3pub, $phone, $phonepub, $alumyears, $yearspub, $comment, $comme +ntpub, $synpass, $synpass2)=split(/::/,$value); if ($fields{'synpassold'} ne $synpass2){ print "Content-type: text/html", "\n\n"; print "Incorrect password. If you cannot remember you +r old password, email the webmaster."; die; } if ($fields{'updsynpass'}==""){ $fields{'updsynpass'}=$synpass2; $fields{'updsynpass2'}=$synpass2; } delete $synusers{$fields{'updalumname'}}; $synusers{$fields{'updalumname'}}=" $fields{'updalumemail'}::$fields{'updemailpub'}:: $fields{'updalumsnail1'}::$fields{'updsnail1pub'}::$fields +{'updalumsnail2'}::$fields{'updsnail2pub'}:: $fields{'updalumsnail3'}::$fields{'updsnail3pub'}::$fields +{'updphone'}::$fields{'updphonepub'}::$fields{'updalumyears'}::$field +s{'updyearspub'}:: $fields{'updcomment'}::$fields{'updcommentpub'}::$fields{' +updsynpass'}::$fields{'updsynpass2'}"; print "Content-type: text/html", "\n\n"; print "Thank you for updating your information."; die; } }
      Edit by dws to add <code> tag

        dbmopen

        Consider using a tied hash instead.

        print "Content-type: text/html", "\n\n";

        You can add the \n\n in the first literal string.

        die;

        You shouldn't die unless a real error occurs. Bad user input is not considered a program error, so it should not output to STDERR (everything that is output to STDERR is appended to the error log of the webserver). Consider using exit instead.

        if ($fields{'updsynpass'}==""){

        Don't use == for string comparison. Use the string equality test operator eq instead.

        $fields{'updalumemail'}::$fields{'updemailpub'}:: $fields{'updalumsnail1'}::$fields{'updsnail1pub'}::$fields{'updalums +nail2'}::$fields{'updsnail2pub'}:: $fields{'updalumsnail3'}::$fields{'updsnail3pub'}::$fields{'updphone +'}::$fields{'updphonepub'}::$fields{'updalumyears'}::$fields{'updyearspub'}:: $fields{'updcomment'}::$fields{'updcommentpub'}::$fields{'updsynpass +'}::$fields{'updsynpass2'}"

        Ouch. Consider using join instead. That would also fix your original %09-character problem. join is the exact opposite of split.

        $synusers{ $fields{updalumname} } = join '::', @fields{qw(updalumemail updemailpub updalumsnail1 updsnail1pub updalumsnail2 updsnail2pub updalumsnail3 updsnail3pub updphone updphonepub updalumyears updyearspub updcomment updcommentpub updsynpass updsynpass2)} +;

        U28geW91IGNhbiBhbGwgcm90MTMgY
        W5kIHBhY2soKS4gQnV0IGRvIHlvdS
        ByZWNvZ25pc2UgQmFzZTY0IHdoZW4
        geW91IHNlZSBpdD8gIC0tIEp1ZXJk
        

Re: Updating entry in DBM file adds extra character %09
by Juerd (Abbot) on Mar 18, 2002 at 09:54 UTC

    When I update a record in my DBM file, %09 is appended at the frontside of each value.

    Assuming you mean the character that is %09 when uri-encoded, you are talking about \t, the tab character. (It is also known as ^I, \009, \x09, \cI, etcetera).

    I've looked at your code, and it appears you have avery large interpolated string. Layed out different, it is:

    { $foo = " $bar $baz $xyzzy "; }
    (Well, I couldn't enter tab characters in Mozilla, so I used four spaces instead.)
    That code equals:
    { $foo = "\n\t\t$bar\n\t\t$baz\n\t\t$xyzzy\n\t"; }
    The solution is to remove the whitespace from your variable. You'll have a very long line by then. It might be useful to know that Perl lets you concatenate strings using the . operator :)

    U28geW91IGNhbiBhbGwgcm90MTMgY
    W5kIHBhY2soKS4gQnV0IGRvIHlvdS
    ByZWNvZ25pc2UgQmFzZTY0IHdoZW4
    geW91IHNlZSBpdD8gIC0tIEp1ZXJk
    

Re: Updating entry in DBM file adds extra character %09
by Slipstream (Monk) on Mar 18, 2002 at 02:30 UTC
    The %09 sounds like a special character substitution for a URL. Unfortunately I can't think of which character it is for off the top of my head. Is your input form is passing info with Get instead of the Post method?
      I'm passing with POST, but that's not the issue. When I first populate the record in the DBM file, no special characters are appended. The problem only occurs when I update a record in the DBM file.

      This all has something to do, I think, with the fact that when I delete a record from the database it is still present when I open the .pag file in a text editor, yet will not show up in a search of the DBM using the 'each' function (the desired effect). Obviously, some sort of incomplete deletion seems to be affecting the updated record.

      %09 is explained as the following on some sources I have read on the net: HT::=character_nbr(9)::= Move to next Tab-stop(ASCII'HT)\t. Decimal = 9, Hex = 09, ASCII = HT
        Don't be mislead by what a .pag file looks like in a text editor. When you delete a record, the space use for it in the file isn't reclaimed right away. A .pag file isn't like a flat text file, where deleting a line means rewriting the entire file to make the line really go away. As long as you can't get the deleted line back out of the DBM file via public interfaces, dont' worry about whether remnants of the record are still in the file.

        Show us the code that's setting up %header.

      It may be, actually, that the password fields are not experiencing this problem. If that's the case, the problem may indeed be more related to the HTML methods. Testing.
        FYI, I suspect the problem is related to the arrangement of the code where I enter the values into the DBM. The line
        $synusers{$fields{'updalumname'}}="
        
        and those few that follow, I had to change a bit when I first wrote them. You'll note that the value assignments are spread strangely over 5 lines of code. I was having problems (redisplaying values in HTML) that were seemingly related to the carriage returns in the code.