Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re^3: Transferring hash keys to array... Need help sorting

by Anonymous Monk
on Apr 21, 2017 at 17:52 UTC ( [id://1188568]=note: print w/replies, xml ) Need Help??


in reply to Re^2: Transferring hash keys to array... Need help sorting
in thread Transferring hash keys to array... Need help sorting

In that case, you might find the concept of structured data useful.

my $data = { key1 => { label => "label1", content => [...] }, key2 => ..., };
The above's a HoH, i.e. hash of hashes. Start reading with perldsc perhaps.

Replies are listed 'Best First'.
Re^4: Transferring hash keys to array... Need help sorting
by DARK SCIENTIST (Novice) on Apr 21, 2017 at 18:28 UTC
    I actually have a hash set up already that contains keys= the labels and values= sequence content. I read these keys and values into an array because it was easier to manipulate them (reverse and tr them and insert spaces between characters). Is there a way to just manipulate them straight from a hash reference instead of putting the keys and values into arrays? If so, I can just avoid arrays all together

      Of course you can manipulate the data. For example:

      foreach my $record (values %$HoH) { $record->{label} =~ tr/A-Za-z/N-ZA-Mn-za-m/; }
      Should perform the rot13 cryption on all the label fields. See perlop for =~, tr, etc.

        I'm a little new to Perl (clearly) and this makes things much easier... My use of arrays was pointless. I'm just going to copy and paste all the code manipulating the arrays and operate on the hash. Thanks

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1188568]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (7)
As of 2024-04-19 11:52 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found