Database Perl

#!/bin/perl
use AnyDBM_File;
dbmopen(%states, "statedb", 0666);
@sortedkeys=sort keys %states;
foreach $key ( @sortedkeys ){
    $value=$states{$key};
    $total++;
    write;
}
dbmclose(%states);    
format STDOUT_TOP=
Abbreviation     State
------------------------------
.
format STDOUT=
@<<<<<<<<<<<<<<@<<<<<<<<<<<<<<<
$key,          $value
.
format SUMMARY=
------------------------------
Number of states:@###
$total
.
$~=SUMMARY;
write;