in reply to Re: Updating entry in DBM file adds extra character %09
in thread Updating entry in DBM file adds extra character %09

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

Replies are listed 'Best First'.
Re: Re: Re: Updating entry in DBM file adds extra character %09
by Juerd (Abbot) on Mar 18, 2002 at 10:02 UTC

    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
    

      THANKS for the tips. Very helpful. Considered tie before but will give it more thought now. Also will try the join. Didn't realize hadn't replaced == with eq (teaching myself perl these past months when I have free time). Will try this stuff this week.
        Using join when creating each database record essentially fixed my problem. Thought I'd provide a summary of the answer for anyone looking up this prob in the future. Thanks, Perlmonks!!