#!/bin/perl
# File: packex (Pack Examples)

# The hash %persons uses last names as keys, and the 
# values are first name followed by salary.
# Pack: salary, last name, first name
# in a long integer, and two 15 character fields.

%persons = ('smith', 'slim 50000',
	    'jones', 'joe 52000',
	    'curtis', 'curt 49000',
	    'morgan', 'mike 51000' );

open(SALARYS, '>salarys') || die "Can't open salarys:$!\n";

while ( ($last, $value) = each %persons ) {
   $record = pack("L A15 A15", reverse(split(' ',$value)), $last);
   print SALARYS $record;
}
close(SALARYS);
