Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re: If any element-in-array comparision

by fisher (Priest)
on Jan 27, 2012 at 16:06 UTC ( #950402=note: print w/ replies, xml ) Need Help??


in reply to If any element-in-array comparision

you need to go through given list at least once, but not with counter. You loop through whole list, preparing your output data, and if there is element bigger than 0.1 you trigger some variable to, say, 1. No need in counter, but in trigger.

Also, you can output the whole array with 'print' and 'join', in one line of code.


Comment on Re: If any element-in-array comparision
Re^2: If any element-in-array comparision
by chessgui (Scribe) on Jan 27, 2012 at 16:22 UTC
    I learned at this site that there are utilities for lists. For example to get the maximum value of a list:
    use List::UtilsBy qw(max_by); my @list=(0.03,0.04,0.01); my $max=max_by {$_} @list; print "Maximum of ",join(',',@list)," is $max\n";
      Yes, you're of course right. By stating that 'you need to go through list' I meant that general algorythm goes through list at least once and this is a must. What you will use for that task - List::Utils or grep or your own cycle - isn't important in this context.

      And of course I can provide some code snippets, but I feel that this would be a bad idea for OP who doesn't show us a line of his own.
        well my own code was like this.
        #!/usr/bin/perl -w use strict; use warnings; my @data=<>; foreach (@data) { my @row=split(/\t/, $_); my $otuhead=shift(@row); my $logic=1; foreach (@row) { if ($_>=0.01){$logic++;} } if ($logic!=1){print "$otuhead @row";} $otuhead=(); }

        And yes I am acutely aware that the basic algorithm for finding out max, min etc. from a list has actually go through the list. I was just looking for utilities, commands, or whatnot that can make it well ... look nice would probably be the best explanation. Something that does not need extra curly brackets and extra declared variables. Extra space and hmm more general eyestrain. The question was more motivated by general curiosity than an actual need for this current problem. Which I have already solved (probably quite horribly as people soon will point out I guess :D)

        edit: in code I shift off the first element -because it is a header and therefore not numerical.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (12)
As of 2014-08-27 17:43 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (248 votes), past polls