Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re^5: Simplify code in Perl with "unless" conditionnal

by haukex (Archbishop)
on May 30, 2016 at 14:01 UTC ( [id://1164507]=note: print w/replies, xml ) Need Help??


in reply to Re^4: Simplify code in Perl with "unless" conditionnal
in thread Simplify code in Perl with "unless" condition

Hi Chaoui05,

From experience I can tell you that it's not always a good idea to randomize tests (it causes random failures and random successes, different on each run, not easily reproducible), instead making them deterministic. Why do you want to pick random browsers to compare?

This compares each browser to each other browser:

use Algorithm::Combinatorics 'combinations'; my @browsers = ('firefox', 'chrome', 'internet explorer'); my $iter = combinations(\@browsers,2); while (my $c = $iter->next) { print "Compare $$c[0] with $$c[1]\n"; } __END__ Compare firefox with chrome Compare firefox with internet explorer Compare chrome with internet explorer
I never know if i give enough information or not at each time.

As a basis you can always do the same thing: post short but runnable code that reproduces the problem along with short sample input, the output you would expect from that code (written by hand if necessary), and the output you're actually getting, including exact error messages. This is explained, for example, in How do I post a question effectively? and Short, Self Contained, Correct Example. If you're unsure, ask yourself, what information do we need to easily reproduce the problem you are seeing?

Hope this helps,
-- Hauke D

Replies are listed 'Best First'.
Re^6: Simplify code in Perl with "unless" conditionnal
by Chaoui05 (Scribe) on May 30, 2016 at 14:44 UTC

    Thanks for the reply, it's cool.

    First i want to do a randomize comparison test in the objective to not have same difference' screenshot at each time. And moreover to have different filename. Thanks for your approach , but it seems that we have always first browser with following and the following with following as we can see in your output ? And i would like to get them randomly for my part.

    Yes , in any case, here i have enough information. Thanks

    Concerning the way to post , i always try to explain the case with the maximum of information i.e. with the input and maximum of code as it's possible and with the output. And of course with explanations. iam using posts edited here, in perlmonks.

    Thanks again !

    Lost in translation

      Hi Chaoui05,

      Well, to randomize it, you can shuffle both the list of browsers and the list of combinations, that'll ensure that you always have all comparisons but in a random order:

      use List::Util 'shuffle'; use Algorithm::Combinatorics 'combinations'; my @browsers = shuffle('firefox', 'chrome', 'internet explorer'); for my $c (shuffle combinations(\@browsers,2)) { print "Compare $$c[0] with $$c[1]\n"; } __END__ Compare internet explorer with firefox Compare firefox with chrome Compare internet explorer with chrome

      Hope this helps,
      -- Hauke D

        Thanks , it seems even more better
        *****Lost in translation****TIMTOWTOI****

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others imbibing at the Monastery: (5)
As of 2024-04-24 06:13 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found