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

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.

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

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!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • 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
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            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?

    What's my password?
    Create A New User
    and all is quiet...

    How do I use this? | Other CB clients
    Other Users?
    Others taking refuge in the Monastery: (5)
    As of 2018-02-24 09:14 GMT
    Find Nodes?
      Voting Booth?
      When it is dark outside I am happiest to see ...

      Results (310 votes). Check out past polls.