Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

comment on

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

I am interested in creating a hash of hashes that will contain variables that are set by the user.

I have put this together to create a hash of a variable (population size, @total) that is sent into this subroutine. $tester is also sent into the array and is the number of populations that the user creates.

sub splitter { my %hasher = (); my $increase = 0; my $input = ""; while ($tester--) { $increase ++; push @key, $increase; } @hasher{@key} = @total; foreach $key (sort { $a <=> $b } keys %hasher) { print "Population #$key = $hasher{$key}\n"; } while () { print "Enter the population you will act on: "; chomp ($input = <STDIN>); $output = $hasher{$input}; #references a specific value in the + hash. print "$output BEFORE \n"; $output = $output + 8; print "$output AFTER\n"; $hasher{$input} = $output; #returns the modified value to the +hash foreach $key (sort { $a <=> $b } keys %hasher) { print "Population #$key = $hasher{$key}\n"; } return $output; } }

Later in the code, I take the $output value and turn it into an array that is modified, and i want to then return it to the hash in the following format:
A: Population number
1. Listing of individuals from 1…n (user defined) ie. @array = (1 … $population);
2. Listing of genetic marker associated with each individual (not yet coded)

The other thing I wanted to do, is be able to modify the arrays at the lower level of the hash, as I have done for my simple hash above. Something I have no idea how to do.

I have only been at this two weeks, and this is my first attempt at programming. Any help on any aspect of this post would be greatly appreciated. Thanks monks!


In reply to Hash of Hashes by BioNrd

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 scrutinizing the Monastery: (2)
As of 2024-04-20 05:58 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found