Somebody must've surreptiously removed the caffeine from my caffeinated beverage because I just can't see why this doesn't work.

I simply wish to pass the hard-coded source hashref and a target hashref to a sub to measure lengths of strings from the first and populate the second. That part works great.

But I don't seem to have any visibility of the target hashref outside of measureHashrefLength even though it's declared in my main sub.

O Monks of Perl, enlighten me!

#! /home/gnu/bin/perl package main; use strict; use autouse 'Data::Dumper' => qw(Dumper); # prototypes sub readAdvisorTablesIntoHashref($); sub measureFieldLengths(); sub writeOutHashrefs(); sub writeOutHashref($$); #globals my $allActivity_hashref = { '1234-5678' => { 'Address' => "656 Poplar" ,'City' => "Monroe" ,'State' => "WI" ,'Zip' => "87654" ,'Phone' => "444-555-666 +6" } , '5757-4968' => { 'Address' => "656 Poplar" ,'City' => "Nightmare" ,'State' => "ND" ,'Zip' => "56532" ,'Phone' => "777-8888" } }; my $allActivity_fieldLength_hashref = undef; my $subHadErrors = 0; $subHadErrors = measureFieldLengths() unless( $subHadErrors); $subHadErrors = writeOutHashrefs() unless( $subHadErrors); exit(0); #------------------------------- sub measureFieldLengths() { print "entering measureFieldLengths\n"; my $errorHit = 0; measureFieldLength( "ACTIVITY", $allActivity_hashref, $allActivity_f +ieldLength_hashref); print "exiting measureFieldLengths\n"; return $errorHit; } #------------------------------- sub measureFieldLength($$$) { my ( $tableName, $tableName_hashref, $tableName_fieldLength_hashref) + = @_; print "entering measureFieldLength\n"; my $errorHit = 0; print "--inside measureFieldLength--input --". Dumper( $tableName_h +ashref); unless( $errorHit) { for my $Id ( sort{ $tableName_hashref->{$a} <=> $tableName_hashref->{$ +b} } keys( %$tableName_hashref)) { my $row_hashref = $tableName_hashref->{$Id}; for my $field_name ( sort{ $row_hashref->{$a} <=> $row_hashref->{$b} } keys( %$row_hashref)) { my $field_valu = $row_hashref->{$field_name}; $tableName_fieldLength_hashref->{$Id}->{$field_name} = 0; $tableName_fieldLength_hashref->{$Id}->{$field_name} = length( + $field_valu) if( defined( $row_hashref->{$field_name})); } } } print "--inside measureFieldLength--output --". Dumper( $tableName_f +ieldLength_hashref); print "exiting measureFieldLength\n"; return $errorHit; } #------------------------------- sub writeOutHashrefs() { print "entering writeOutHashrefs\n"; my $errorHit = 0; print "--inside writeOutHashrefs --input --". Dumper( $allActivity +_fieldLength_hashref); print "WT* why isnt global allActivity_fieldLength_populated ???? +\n"; writeOutHashref( "ACTIVITY", $allActivity_fieldLength_hashref); print "entering writeOutHashrefs\n"; return $errorHit; } #------------------------------- sub writeOutHashref($$) { my ( $tableName, $tableName_hashref) = @_; print "entering writeOutHashref\n"; my $errorHit = 0; unless( $errorHit) { for my $Id ( sort{ $tableName_hashref->{$a} <=> $tableName_hashref->{$ +b} } keys( %$tableName_hashref)) { my $row_hashref = $tableName_hashref->{$Id}; print $Id."\n"; my $outline = $Id; for my $field_name ( sort{ $row_hashref->{$a} <=> $row_hashref->{$b} } keys( %$row_hashref)) { my $field_valu = $row_hashref->{$field_name}; $outline = $outline.join('=', $field_name, $field_valu); } print $outline."\n"; } } print "entering writeOutHashref\n"; return $errorHit; }

In reply to no visibility to global hashref ?!? by kerchunk

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!
  • 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, details, 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, summary, 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.