Beefy Boxes and Bandwidth Generously Provided by pair Networks Bob
XP is just a number
 
PerlMonks  

Comment on

( #3333=superdoc: print w/ replies, xml ) Need Help??
Your structure and logic is much more complicated than necessary, but I have preserved it, and made a few corrections. Try this one:
use strict; use warnings; use Data::Dumper; my %ex = ( 37 => "p" , 41 => "t", 23 => "s" , 52 => "m", 44 => "a" , 65 => "q", 26 => "d" , 88 => "o" , 99 => "g" , 100 => "l" , 101 => "f" , 201 => "i" ); my @buckets = ( [],[],[],[],[],[],[],[],[],[] ); sub perlhash { my $k = shift @_; my $hash = 0; $hash = ($k % 10); return $hash; } while(my ($k , $v) = each(%ex)) { my $hash = perlhash($k); my $ch = $buckets[$hash]; my $entry; # print Dumper $buckets[$hash]; if(scalar @{$ch} == 0){ $entry = {$k => $v}; }else{ $entry = $ch->[0]; $entry->{$k} = $v ; next; } push @$ch , $entry; } print Dumper \@buckets; print "enter a key u want to search"; chomp(my $k = <STDIN>); my $h = perlhash($k); print "The Key in Slot $h is " . join (",",keys (%{$buckets[$h][0]}) +) . "\n" ;

             I hope life isn't a big joke, because I don't get it.
                   -SNL


In reply to Re: trying to implement hash table. and getting lots of difficulties. plz help me out.......... by NetWallah
in thread trying to implement hash table. and getting lots of difficulties. plz help me out.......... by Priti24

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!
  • 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, 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, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • Outside of code tags, you may need to use entities for some characters:
            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.
  • Log In?
    Username:
    Password:

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

    How do I use this? | Other CB clients
    Other Users?
    Others rifling through the Monastery: (11)
    As of 2014-04-16 12:05 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      April first is:







      Results (425 votes), past polls