Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re^5: array in hashes

by fisher (Priest)
on Jul 29, 2011 at 10:07 UTC ( #917425=note: print w/replies, xml ) Need Help??


in reply to Re^4: array in hashes
in thread array in hashes

i want (7-7)/(3-2) as output.

Is this what you want?

for (keys(%genome1)) { if ($genome2{$_}) { print "for ".$_." it is (".${$genome1{$_}}[1]."-". ${$genome2{$_}}[1].")/(".${$genome1{$_}}[0]."-".${$genome2{$_}}[ +0].")\n"; } }

Replies are listed 'Best First'.
Re^6: array in hashes
by JavaFan (Canon) on Jul 29, 2011 at 10:19 UTC
    There's no need for the additional blocks. Writing $genome1{$_}[1] instead of ${$genome1{$_}}[1] is just fine.

      Further to JavaFan's point about clarity, there's also no need to go overboard using concatenation for complex hash or array values in a string. They will interpolate just fine:

      >perl -wMstrict -le "my %hash = ( a => [11,22], b => [33,44], ); my $hashref = { c => [55,66], d => [77,88], }; ;; print qq{$hash{a}[0] $hash{b}[1] $hashref->{d}[1]}; " 11 44 88
      Yes, I know. I wrote this for clarity.
        Clarity? 3 extra, not-needed, punctuation characters that hardly anyone ever use?

        I fail to see why that brings clarity, or who benefits from it.

Re^6: array in hashes
by persianswallow (Novice) on Jul 29, 2011 at 10:44 UTC

    thank you soooooooooooooo much.:-) i need amount of those calculation.i mean (15-4)/(10-3)is equal to 1.5714286 but it doesnt print that.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (1)
As of 2020-12-06 01:34 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    How often do you use taint mode?





    Results (65 votes). Check out past polls.

    Notices?