Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw

Re: Problem wrapping prototyped function [SOLVED]

by Laurent_R (Canon)
on Dec 17, 2013 at 18:59 UTC ( #1067508=note: print w/replies, xml ) Need Help??

in reply to Problem wrapping prototyped function [SOLVED]

You could also possibly use the solution I outlined here: Re^5: Smartmatch alternatives.
  • Comment on Re: Problem wrapping prototyped function [SOLVED]

Replies are listed 'Best First'.
Re^2: Problem wrapping prototyped function [SOLVED]
by LanX (Bishop) on Dec 17, 2013 at 22:30 UTC
    I'm afraid you missed the point.

    The reason why people want to use any instead of grep is to break as soon as the condition is true.

    Example: Test array for odd numbers:

    DB<47> use List::MoreUtils qw/any/ DB<48> @x=1..10000;() DB<49> $i=0; $flag= any { $i++; $_ %2 } @x; ($i,$flag) => (1, 1) DB<50> $i=0; $flag= grep { $i++; $_ %2 } @x; ($i,$flag) => (10000, 5000)

    Looks like you reimplemented grep, just slower.

    Cheers Rolf

    ( addicted to the Perl Programming Language)

      Well, part of the discussion in the other post was about the fact that using grep in a Boolean context for simulating an any function is not very clear.

      The other point, which I should have mentioned and you could not guess it, is that I am not really using the List::Util version of reduce, but my own experimental lazy version of reduce, so that the process stops as soon as it has satisfied the relevant condition. (It should probably called something else than reduce, but OK, that's the idea.)

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1067508]
[Eily]: hu, don't tell the other French people I never tried it, I might get kicked out :P
choroba . o O ( The Czech at-sign is also edible )
[Eily]: the French @ is a mouthful I guess...
[Eily]: choroba Wikipedia gives me Zavináč which doesn't seem to translate to something edible?
[Eily]: (yes I'm very good at using question marks, thank you)
[Discipulus]: O_O frexit for you! even me i tried. it was in the arabic quarter in Granada; they offered as 'tapas' in bars. I eataly somewhere they eat ;=P Sardinia a Pulia iirc
[choroba]: Zavináč
[Eily]: choroba oh, that makes sense :)

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (6)
As of 2017-11-21 10:55 GMT
Find Nodes?
    Voting Booth?
    In order to be able to say "I know Perl", you must have:

    Results (297 votes). Check out past polls.