Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris

comment on

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

Hey there! Currently, I'm having troubles with Perl printing the memory location of a hash when I feel that I haven't given it sufficient cause to do so. This is a word processing tool that I'm making for myself to help in the study of foreign languages. I'm reading in English words and their foreign (in my case, German) equivalent, and storing them in a hash. When one iterates over the hash, however, Perl decides that I'm telling it to print out the hashes memory location as well as all the elements of the hash I have purposefully put in there. It's interesting to note that the hashes memory location does not receive a 'tag' from the hash_processor subroutine. Any help would be greatly appreciated.

sub add_words::main () { my %words = {}; my $english; my $foreign; until ('1' == '0') { print "Enter English: "; chomp($english = <STDIN>); print "Enter German: "; chomp($foreign = <STDIN>); if (($english && $foreign) eq '-1') { last; } ($english, $foreign) = &hash_processor::function($english, $foreign +, '0'); $words{$english} = $foreign; } foreach my $word (sort keys %words) { # First output is description of hash's mem location, and I DON'T K +NOW WHY. print "$word ==> $words{$word}\n"; } } sub hash_processor::function () { my ($english, $foreign, $process) = @_; if ($process == '0') { $english = "$english" . "$hash_processor::tag_count"; $foreign = "$foreign" . "$hash_processor::tag_count"; } $hash_processor::tag_count++; return ($english, $foreign); }

Output is something like:

HASH(0x950c5e6) ==> word ==> Wort two words ==> zwei Woerter etc. ==> usw.

In reply to Hash Printing reveals Hash Memory Location by perlStuck

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.