Hello, I've discovered that my random hashes based on my above code are not actually random, but are biased based on the original network. What I should do is outlined in my pseudocode, some elements of which I am having trouble with:
#read IDs into %edges using match operator /(\S*)(\t)(\S*)/ and specia +l variables $1, $3 for each ID per line #assign IDs as format $edge{ID1,ID2} #skip edge assignment if ID2,ID1 already exists .. the network needs t +o be undirected such that ID2-ID1 is equivalent to ID1-ID2 and should + therefore not be counted twice #populate hash of unique IDs from %edges #create array of unique IDs from hash of unique IDs .... @uniqIDs, $un +iqIDs[0]=ID1, uniqIDs[1]=ID2 etc .. how do i do this? #initialize degree counter hash (IDs are keys, values are degrees) usi +ng @uniqIDs with foreach #go through %edges and increment %counter for each ID #generate random network with rand(int(scalar(@uniqIDs))), discard ran +dom picks if they already exist or represent undirected equivalent #initialize random network degree counter hash, and then count random +network degrees as before
I'm already stuck at how to skip an edge assignment if $2,$1 exists. Then, how can I populate a new hash of unique IDs? Again, the problem of excluding something if it already exists.
my $filename = "edges.txt"; #Set a variable for our file name open(my $fh, "<", $filename) or die "Can't open file $filename."; #Op +en the file edges.txt while (<$fh>) { if ($_ =~ m/(\S+)\t(\S+)/) { #Match the IDs in the fil +e to $1 and $2 $edge{$1,$2}= $holder; #assign IDs as format $edge +{ID1,ID2} close $fh; #Close the file edges.txt my @list = keys %uniqedge; print "@list\n"; #Prints the list of keys, but they are un +i-directional (i.e. repeated for ID1-ID2 and ID2-ID1)
Once I have these steps, I can proceed to counting and using the unique IDs list to create my random networks.

In reply to Re^4: Tallying appearance of a unique string from hash keys by jack_j
in thread Tallying appearance of a unique string from hash keys by jack_j

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.