For starters, use strict would solve most of your problems, (but probably give you a host of new ones as you learn all the things you are doing wrong)
You are using a global variable $index to loop with , which you are never initializing. therefore only the first call to this function has any chance of working correctly.
How are you determining that $no_of_questions{$User_Name} is not being set properly? Are you saying that the loop never matches and the prints don't happen? or are you saying that they are and some unspecified test after that fact is not showing it?
If you showed us the data and how you are calling the function, we could be of more help.
sub search_for_username_and_no_of_questions { my $username; foreach (@records) { if (/userName\s+:\[(..*)\]/) { ($username = $1) =~ s/\s+//g; } elsif (/Set\s+of\s+questions\(bitmap\)\s+selected\s+:\s+(\d+)/) { $no_of_questions{$username} = $1; $timestamp{$username} = $Time_Stamp; } } }
(untested) should fix some of your more blatent coding problems, but I would want to eliminate the 2 global hashes and the global timestamp.
Update: I think he calls his function multiple times to get all the results, not just the first. Updated my code sample to work right when called only once for all of them, (assuming 1 no_questions row for each username row). Of course this new version doesn't get the timestamp right, but his code is so screwy and reliant on globals that you can't have everything.


-pete
"Worry is like a rocking chair. It gives you something to do, but it doesn't get you anywhere."

In reply to Re: special characters storage in perl by dreadpiratepeter
in thread special characters storage in perl by namishtiwari

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.