Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Golf: Factorials

by srawls (Friar)
on May 23, 2001 at 04:59 UTC ( #82440=perlmeditation: print w/replies, xml ) Need Help??

Help for this page

Select Code to Download


  1. or download this
    @a = factorial(5); $a[0] = 120<br>
    @a = factorial(5,3,10); $a[0..2] = (120,6,3628800)
    
  2. or download this
    sub f {
    push@a,eval join'*',1..$_ for@_;@a
    }
    

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlmeditation [id://82440]
Approved by root
help
Chatterbox?
choroba's discovered two instances of a weird animal in the code at work: \@$var
[Eily]: hum, tied scalar, generates a new array when derefed ? :D
[Corion]: choroba: Ah, when doing a shallow copy, I prefer [ @$var ] - I think \@$var might return the same reference instead of a reference to a fresh copy
[Corion]: perl -wle "my $ar = [1,2,3]; my $br=\@$ar; print qq($ar / $br)" confirms this to me
[karlgoethebier]: "discovered" this to sum an array: perl -E 'say scalar map {1 .. $_} (1..3);'

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (10)
As of 2017-09-26 08:45 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    During the recent solar eclipse, I:









    Results (293 votes). Check out past polls.

    Notices?