Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

More info: array of hashes

by chumley (Sexton)
on Apr 25, 2001 at 23:06 UTC ( [id://75570]=note: print w/replies, xml ) Need Help??


in reply to Getting information from an array of hashes

Update:

I wanted to add some details of what I've already tried. First of all, the function that returns this array of hashes is not mine. It's part of the ARSPerl package. The actual function is called ars_GetEntry() which returns a hash of all the fields in a form. I looked through ARS.pm and it looks like this function is coded in C, not Perl, so it doesn't look like I'll be able to hack it. (Unless my boss is willing to pay for me to take a C class... :-) )

When calling the function, one of the arguments is the index of the particular record I want to retrieve. The keys to the hash are the field ID numbers from that form. This works fine for all the other fields I need to get - I have no problem retrieving and printing all the other information I need.

If one of the fields is a 'diary' field (Which I think is specific to Remedy), then that element of the hash is an array of hashes. Does that make sense? It took me a few times reading to understand it. IOW, quoting the documentation for this function:

ars_GetEntry(ctrl,schema,entry_id,...)

This function returns a hash (associative array) of field ids and values for a given schema and entry id. If you specify any field ids after the entry_id parameter, only the values for those fields will be returned, otherwise all field id value pairs are returned. All field values are converted into numeric or string values, except for the diary type. The diary field type is encoded as an array of hashes. Each hash has a timestamp, user and value field.

Here is one thing I have done that works, sort of:

@diary_entry = keys %{$diary_data[0]}; for $temp (@diary_entry) { print "$temp\n"; }

This returns:

$ ./send_referral.pl 0000079100 Diary ID: 536870914 timestamp value user

According to the docs, this is what I should see for the keys. Next, change the print statement, like so:

print "$temp: $diary_data[0]{$temp}\n";

This was interesting:

$ ./send_referral.pl 0000079100 Diary ID: 536870914 Use of uninitialized value at ./send_referral.pl line 201. timestamp: Argument "NWORLASTE800 LOGIN FAILED\nNWORLASTE801 LOGIN FAIL\n\nWA..." + isn't numeric in helem at ./send_referral.pl line 201. Bad index while coercing array into hash at ./send_referral.pl line 20 +1. $

The gibberish that looks like "NWORLASTE800 LOGIN FAILED\nNWORLASTE801 LOGIN FAIL\n\nWA..." looks like part of what I should see. This part of what should be in the data, under %hash{value}, and could run to thousands of characters. (The actual limit for this field is 500KB)

Finally, here are two things I have tried and the result:

@diary_entry = values %{$diary_data[0]}; print "@diary_entry\n";

and

# Another try: my %hash = %{$diary_data[0]}; @diary_entry = keys %hash; #@diary_entry = keys %{$diary_data[0]}; print "@diary_entry\n"; for $temp (@diary_entry) { print "$temp\n"; }

give me an error that says "Out of memory during ridiculously large request at ./send_referral.pl line 194." (Line 194 says "my %hash = %{$diary_data[0]")

So, to summarize, I have an array of hashes. I can get the keys to those hashes but I can't get any data out of them. Thank you Ovid, AgentM, and hdp for the suggestions. I'll be reading them carefully to make sure I understand them.

Chumley

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others imbibing at the Monastery: (4)
As of 2024-03-29 11:30 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found