sub Msg {
my $line = shift;
my ($pf,$fixFields) = split(/received:|Sent:/, $line);
my %fixMsg = split(/[,=]/, $fixFields);
@fixMsg{('_time_', '_mi_', '_fixsession_')} = (split(/\|/, $pf))[2
+,3,5];
return \%fixMsg;
}
open( my $file, '<', "abc.txt" )
or die "Unable to open data file - $!\n";
while(<$file>){
my $msg = pfUtils::Msg($_);
my %skip_keys = map {$_ => undef} qw( _mi_ _fixsession_ _time_ );
foreach my $key ( sort keys %$msg ) {
next if exists $skip_keys{$key};
my $value = $msg->{$key};
next unless defined $value and length $value;
my $code = 'where did this come from?';
printf "\n\t%20s (%3d) = %s ", $code,$key,$value;
}
}
close $file;
I have some coding style suggestions for you.
Use less white space. Most people don't use enough. You've gone too far in the opposite direction.
Use more descriptive names. What's a pf? potato fragment? pig fertilizer?
You have some variables declared with my, others are not. Are you using "strict" and "warnings"? You should be.
Check the results of your calls. Especially to things like open that fail frequently.
Spend some time reading some basic perl tutorials and perldoc. You have several very odd and incorrect usage in your post. For example, you are using bitwise or in your tests for hash keys to skip. Various resources can be found by searching PM. http://learn.perl.org has a good list, too.
Read about how to post here. You will get a better response if you take the advice to heart. The article on effectively asking questions has good pointers that can be used to good effect in any online forum.
To progress do these three things: keep reading, keep writing code, and keep asking questions.
|