J
JerryP
Hi!
This is simple? But it has been a while that I have programmed in
Perl. What I am wanting to do is build a hash from a text file:
text:
79706-0000 2229.17
79706-0000 2523.25
79701-0000 53904.48
79701-0000 78957.81
79701-0000 378043.04
79701-0000 1255172.34
79702-0000 7367.23
79702-0000 20742.95
79702-0000 67331.82
79702-0000 137629.57
79703-0000 1444.18
79701-0000 57565.48
79703-0000 2415.00
79703-0000 2787.97
79703-0000 4780.55
79703-0000 5061.21
79703-5011 1125.80
79704-0000 2382.31
79705-0000 4612.65
79706-0000 1416.50
79703-0000 64014.50
With script:
use strict;
local( *FI, *FO );
my @text = ();
my @zip = ();
my %ref;
open ( FI, "msj_sare.lst" ) or die "Couldn't open c:\\vf\
\sj_sare.lst";
my @text_ = <FI>;
close FI;
s/\n// for( @text = @text_ );
foreach ( @text ) {
/(\d+)\-(\d+)(\s+)(-?(?:\d+(?:\.\d*)?|\.\d+))/;
push( @zip, $1 );
push( @{ $ref{ $1 }{ $2 }},$_ );
}
# then sort with
open ( FO, "+>msj_sare.jwp" ) or die "Couldn't open c:\\vf\
\sj_sare.jwp";
foreach my $family ( sort keys %ref ) {
# for my $role ( sort { $ref{$b} <=> $ref{$a} } keys %
{ $ref{$family} } ) {
print " $family*$ref{ $family }*\n";
for my $role ( sort keys %{ $ref{$family} } ) {
print(join(', ',sort keys ${ $ref{$family} }),"\n");
# print "$ref{$family}{$role}[0]\n";
print FO "$ref{$family}{$role}[0]\n";
}
print FO "\n";
}
I am wanting to print out the data in the following format:
79701-0000 1255172.34
79701-0000 378043.04
79701-0000 78957.81
79701-0000 57565.48
79701-0000 53904.48
79702-0000 137629.57
79702-0000 67331.82
79702-0000 20742.95
79702-0000 7367.23
79703-0000 64014.50
79703-0000 5061.21
79703-0000 2787.97
79703-0000 2415.00
79703-0000 4780.55
79703-0000 1444.18
79703-5011 1125.80
79704-0000 2382.31
79705-0000 4612.65
79706-0000 2523.25
79706-0000 2229.17
79706-0000 1416.50
Thanks,
Jerry
This is simple? But it has been a while that I have programmed in
Perl. What I am wanting to do is build a hash from a text file:
text:
79706-0000 2229.17
79706-0000 2523.25
79701-0000 53904.48
79701-0000 78957.81
79701-0000 378043.04
79701-0000 1255172.34
79702-0000 7367.23
79702-0000 20742.95
79702-0000 67331.82
79702-0000 137629.57
79703-0000 1444.18
79701-0000 57565.48
79703-0000 2415.00
79703-0000 2787.97
79703-0000 4780.55
79703-0000 5061.21
79703-5011 1125.80
79704-0000 2382.31
79705-0000 4612.65
79706-0000 1416.50
79703-0000 64014.50
With script:
use strict;
local( *FI, *FO );
my @text = ();
my @zip = ();
my %ref;
open ( FI, "msj_sare.lst" ) or die "Couldn't open c:\\vf\
\sj_sare.lst";
my @text_ = <FI>;
close FI;
s/\n// for( @text = @text_ );
foreach ( @text ) {
/(\d+)\-(\d+)(\s+)(-?(?:\d+(?:\.\d*)?|\.\d+))/;
push( @zip, $1 );
push( @{ $ref{ $1 }{ $2 }},$_ );
}
# then sort with
open ( FO, "+>msj_sare.jwp" ) or die "Couldn't open c:\\vf\
\sj_sare.jwp";
foreach my $family ( sort keys %ref ) {
# for my $role ( sort { $ref{$b} <=> $ref{$a} } keys %
{ $ref{$family} } ) {
print " $family*$ref{ $family }*\n";
for my $role ( sort keys %{ $ref{$family} } ) {
print(join(', ',sort keys ${ $ref{$family} }),"\n");
# print "$ref{$family}{$role}[0]\n";
print FO "$ref{$family}{$role}[0]\n";
}
print FO "\n";
}
I am wanting to print out the data in the following format:
79701-0000 1255172.34
79701-0000 378043.04
79701-0000 78957.81
79701-0000 57565.48
79701-0000 53904.48
79702-0000 137629.57
79702-0000 67331.82
79702-0000 20742.95
79702-0000 7367.23
79703-0000 64014.50
79703-0000 5061.21
79703-0000 2787.97
79703-0000 2415.00
79703-0000 4780.55
79703-0000 1444.18
79703-5011 1125.80
79704-0000 2382.31
79705-0000 4612.65
79706-0000 2523.25
79706-0000 2229.17
79706-0000 1416.50
Thanks,
Jerry