Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
Thank you everyone for your replys - they were very helpfull, its partially solved the mystery, but not completely!!!
Here's a little more detailed explanation:

I need to read a file (line by line of course).
Line looks like that "subject^email^timestamp"

After file is read I need to do Insertion into database. Now, subjects could be the same and I decided to create this datastructure:
%subjects{$subject}{%hash => email, timestamp} (hope it's clear so far)
%subjects is hash, which has "subject" as a key
$subject is array, which holds hashes or emails and times

So, I created this code:
my %subjects; foreach my $subm(@subm){ ($subject, $email, $time) = split(/^/, $subm); my %info; $info{email} = $email; $info{time} = $time; if(! exists $subjects{$subject}){ print "Key DOES NOT exist\n"; $subjects{$subject} = []; }else{ print "KEY DO EXIST\n"; } push @{$subjects{$subject}}, %info; }
I have this code to check that everything is correct:
foreach my $key (sort (keys %subjects)){ print "\n\nKEY = $key"; my @ar = @{subjects{$key}}; my $size = @ar; print "\nSize of Array = $size"; }
Unfortunately, Size gives me size =1 , which is not true. Please tell me if I am doing something wrong....

Thank you very much!!!

Edited by Chady -- added code tags.


In reply to Updated Hashes & Arrays by Bugorr

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



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others avoiding work at the Monastery: (5)
As of 2024-04-19 22:50 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found