Something like this untested code should work.

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.


TGI says moo


In reply to Re: Hash accessing issue while returning hash from sub routinue by TGI
in thread Hash accessing issue while returning hash from sub routinue by tilak_sai

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.