Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re: special characters storage in perl

by dreadpiratepeter (Priest)
on Aug 05, 2009 at 13:24 UTC ( [id://786105]=note: print w/replies, xml ) Need Help??


in reply to special characters storage in perl

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."

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://786105]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others meditating upon the Monastery: (3)
As of 2024-04-18 19:24 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found