Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

Anonymous Monk already pointed out that you are comparing strings using == incorrectly. That being said, I just found the way you are doing this near incomprehensible. The code is verbose and that confounds readability. I refactored:

use strict; use Data::Dumper; my @line1 = ('_W9C2JJDCB','<P>This is the problem1.</P>','<P>This is r +es1</P>'); my @line2 = ('_W9C2JJDCB','<P>This is the problem2.</P>','<P>This is r +es2</P>'); my @line3 = ('_W9C2JJDCB','<P>This is the problem3.</P>','<P>This is r +es3</P>'); my @line4 = ('_W8CXXXXAB','<p>hi there</p>','<p>why are you capitalizi +ng paragraph tags?</p>'); my @totlines; #push (@totlines,\@line1); #push (@totlines,\@line2); #push (@totlines,\@line3); push @totlines, \@line1, \@line2,\@line3,\@line4; my @dir1 =('_W9C2JJDCB', '201200240', 'TEST: IGNORE', 'John Doe', 'Closed', 'HIP', 'email@email.com', 'email2@email.com', ); my @dir2 = ( '_W8CXXXXAB', '2012192222', 'WHAT: HELL', 'Captain Jack', 'Wide Open', 'UNCOOL', 'you@notme.com', 'stillyou@notme.com'); my %hash = ( '_W9C2JJDCB' => \@dir1); $hash{'_W8CXXXXAB'} = \@dir2; for my $key (keys %hash){ foreach my $u (@totlines) { if($key eq $u->[0]) { #print qq|$key is equal to $u->[0]\n|; push @{$hash{$key}},@$u; } } } print Dumper \%hash;
Makes:
$VAR1 = { '_W9C2JJDCB' => [ '_W9C2JJDCB', '201200240', 'TEST: IGNORE', 'John Doe', 'Closed', 'HIP', 'email@email.com', 'email2@email.com', '_W9C2JJDCB', '<P>This is the problem1.</P>', '<P>This is res1</P>', '_W9C2JJDCB', '<P>This is the problem2.</P>', '<P>This is res2</P>', '_W9C2JJDCB', '<P>This is the problem3.</P>', '<P>This is res3</P>' ], '_W8CXXXXAB' => [ '_W8CXXXXAB', '2012192222', 'WHAT: HELL', 'Captain Jack', 'Wide Open', 'UNCOOL', 'you@notme.com', 'stillyou@notme.com', '_W8CXXXXAB', '<p>hi there</p>', '<p>why are you capitalizing paragraph tag +s?</p>' ] };
I think this is what you were trying to do. I copied your @$u from the original code but as you can see from the output that copies the id over and over again. You could use a slice like this instead:
perl -e '@a = 1..5; print @a[1..@a];'

Celebrate Intellectual Diversity


In reply to Re: Comparing Hash key with array by InfiniteSilence
in thread Comparing Hash key with array by packetstormer

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 surveying the Monastery: (5)
As of 2024-03-28 16:55 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found