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

Re: Rook question

by blue_cowdawg (Monsignor)
on Oct 18, 2012 at 13:35 UTC ( #999737=note: print w/replies, xml ) Need Help??


in reply to Rook question

another solution:

sub total { my $sum =0; map { $sum += $_ } @_; return $sum; }
Couldn't resist... :-)


Peter L. Berghold -- Unix Professional
Peter -at- Berghold -dot- Net; AOL IM redcowdawg Yahoo IM: blue_cowdawg

Replies are listed 'Best First'.
Re^2: Rook question
by Anonymous Monk on Oct 18, 2012 at 17:18 UTC

    Let's fold a list.

    use List::Util 'reduce'; sub total { return reduce { $a + $b } 0, @_; }
      The above code hardly even resembles Perl as I know it. Got a lot to learn... I've heard at work they use 'map' regularly (I wouldn't say 'frequently'--something about it not processing efficiently with mysql in some contexts). I'll need to read up on that.
            something about it not processing efficiently with mysql in some contexts

        eh? What does map have to do with mysql? O-o


        Peter L. Berghold -- Unix Professional
        Peter -at- Berghold -dot- Net; AOL IM redcowdawg Yahoo IM: blue_cowdawg

        I can't say I'd choose cowdawg's approach for this question, because map is a bit ill suited for this specific problem. Athanasius's is probably the most idiomatic while still being easy to understand.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://999737]
help
Chatterbox?
[Cosmic37]: test
[Cosmic37]: sort of anyway... hurls some peaches... :-D
[Cosmic37]: when slurping one can undef the record separator thingy; but presumably one should redefine it afterwards? how?
[Cosmic37]: I'm wondering whether there is a specific/(or at least "usual") command or does one take a copy before undefining and then copy it back after slurping file into a string?
[BarApp]: I need help accessing perl files. I need permission!!!

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (4)
As of 2017-06-29 16:31 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    How many monitors do you use while coding?















    Results (672 votes). Check out past polls.