Can someone take a look at the following sample code and let me know if you see any areas I can improve upon I tend to use the same structure when parsing txt files and before I commit this convention into memory maybe one of you guru's could let me know what I can improve upon.
Thanks #!/usr/bin/perl -w use strict; use Data::Dumper; my $file = 'sample.txt'; my ($ds,$time_v,$host); open(my $fh, "<", $file ) or die("Fatal error unable to read $file: $!"); while(<$fh>) { /(^[a-zA-Z].*)/ and $host = $1 and next; /(^\d+)/ and $time_v = $1; if ( defined $host and defined $time_v ) { push @{$ds->{$host}},$time_v; } } close ($fh); #print Dumper($ds); my $total = 0; while ( my ($k, $v) = each(%{$ds}) ) { if ( ref $v eq 'ARRAY') { foreach(@{$v}) { $total +=$_; } print "$k: $total\n"; $total = 0; } } -- [ Rodrick R. Brown ] http://www.rodrickbrown.com http://www.linkedin.com/in/rodrickbrown