Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Re: Picking out specific lengths from a set of hashes.

by huck (Prior)
on May 11, 2017 at 18:36 UTC ( [id://1190092]=note: print w/replies, xml ) Need Help??


in reply to Picking out specific lengths from a set of hashes.

In doing @seqarray = ($id."\n",$seq{$id}); you are resetting seqarray to a single member no matter what is in there already. I suspect you want to push something onto seqarray. I would push $id, then later use that to get at the contents of $seq{$id} as well.

foreach $id (keys %seq){ if ((length ($seq{$id}) <= $maxlength) || (length($seq{$id}) >= $m +inlength)){ push @seqarray,$id; } } for my $id (@seqarray){ print $id."\n".$seq{$id}."\n"; }

Replies are listed 'Best First'.
Re^2: Picking out specific lengths from a set of hashes.
by Peter Keystrokes (Beadle) on May 11, 2017 at 18:43 UTC
    Thank you. What's the reason for redeclaring the $id variable in the final 'for' loop? Edit: I'm also wondering whether the length function works on a hash such as $seq{$id} in the same way it works on say something like $id?

      What's the reason for redeclaring the $id variable in the final 'for' loop?

      Habit, keeping things local to where they are used rather than global in scope.

      I'm also wondering whether the length function works on a hash such as $seq{$id} in the same way it works on say something like $id?

      to length either is just yet another string

        Ahh, okay thanks.
      I'm also wondering whether the length function works on a hash such as $seq{$id} in the same way it works on say something like $id?

      $seq{$id} is not a hash, but a value, and it's length can be determined, as with any string or number or byte sequence. In Perl speak, the word hash denotes the whole structure of an associative array holding key/value pairs. A hash is minced meat, and that's what's done to the key of a tuple: it is transformed via a hashing function into something that can be used as index into an associative array. So, a perl "hash" is an "unordered collection of scalar values indexed by their associated string key (perldata) which for lookup purposes is minced through a hashing function". For entries (key/value pairs) in such a collection (hash entry) the string key is often referred to as hash key and the value as hash value.

      This may sound pedantic and as nitpicking (sorry about that), but people understand each other better if they agree on the meaning of terms.

      perl -le'print map{pack c,($-++?1:13)+ord}split//,ESEL'
Re^2: Picking out specific lengths from a set of hashes.
by Marshall (Canon) on May 13, 2017 at 06:11 UTC
    I think && instead of || is needed here? To be within the range from min to max, number must be <= max and >= min.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others exploiting the Monastery: (9)
As of 2024-04-18 11:05 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found