Logo

This is www.cargal.org, home to all who seek knowledge and discussion.
Community, Arts, Research, Gnu, Answers and Liberty

CARGAL?
CARGAL is a project to promote free webculture and to provide a plattform for everyone to express him/herself.
Please read the about
//
CARGAL ist ein Projekt um die freie Netzkultur zu fördern und jedem/r Interessierten eine Plattform zu bieten, sich frei zu entfalten.
Bitte lies vorher die Info

CONTACT
If you want to get in direct contact with us use a jabberclient and go to the conference "cargal" on "jabber.cargal.org"
more infos

Wenn du mit uns in direkten Kontakt treten willst benutze einen Jabberclient und gehe zur Konferenz namens "cargal" auf "jabber.cargal.org"
mehr Infos

Projekte
Wo werden Leute, ob CARGALvereinsmitglied oder nicht, gebraucht,
welches Thema würde sich über Aufmerksamkeit freuen?

TOPICS
·Anleitung (126)
·Arts (162)
 ·Buch (14)
 ·Film (74)
  ·Kino (32)
  ·TV (6)
  ·DVD (13)
 ·Musik (41)
  ·Ogg (5)
 ·Küche (12)
  ·Bars
  ·Restaurants (5)
·Cargal (84)
 ·Verein_CARGAL (28)
·Computer (475)
 ·Apple (4)
 ·Betriebssysteme (119)
  ·FreeBSD
  ·GNU (94)
   ·GPL (1)
   ·Hurd
   ·Linux (92)
    ·Debian (33)
     ·Debianhelp (2)
     ·Debianpaket
    ·Gentoo (8)
    ·Redhat (3)
    ·SuSE (2)
 ·Hardware (23)
  ·Prozessor
   ·AMD
   ·Intel
 ·Internet (156)
  ·Apache (1)
  ·mITtendrin (85)
 ·Laptop (2)
 ·Programmiersprachen (51)
  ·Java (1)
  ·Perl (9)
  ·PHP (7)
 ·Software (78)
  ·Encryption (11)
   ·GnuPG (3)
  ·Gnome (3)
  ·Gnome2 (4)
  ·Instantmessaging (4)
  ·KDE
  ·Mozilla (1)
  ·Openoffice (3)
  ·X (4)
 ·Usenet
 ·Security (9)
·Disobey (69)
·Events (47)
·News (40)
·Personal (263)
·Science (15)
·Smartphones (2)
 ·Android (1)
·Spiele (13)
·Visions (124)
 ·Politik (56)
 ·Soziales (48)

FreeSoftware
Reports: New Xbox could DOOM second-hand games market
Industry execs: Network admins are an endangered species
Grim outlook for Big Storage as revenues dip across board
China’s state-run rags brand Mars One mission a scam
US Senator introduces 'Patent Abuse Reduction Act'


PolitikSoziales
Judge Thinks Apple Will Lose E-Book Price-Fixing Case
Sozialistische Trümmerlandschaften
Geschichten aus Kuba
Hoffnungssignal für Imker und Bienenfreunde
Politiker, die in Bratwürste beißen


Who's new
steph02
sel
tobik1000
mm2knet
Schneemann

Browse archives
< May 2013 >
SMTWTFS
  1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31  


Workpages of CARGAL
Skriptsprachen, ein Vergleich
- Aufgabe 2 - Fakultät

Perl
Last updated by m3 on Monday, 25/10/2004 - 13:28

Natürlich ist die Berechnung der Fakultät auch in Perl möglich. Und getreu dem Motto "There Is More Than One Way To Do It" gibts auch in Perl mehrere Möglichkeiten, das Problem zu lösen.

Zunächst ganz klassisch, sogar ohne Rekursion:
 1 #!/usr/bin/perl
2
use strict;
3
4 sub fak {
5 my ($max, $fak, $i);
6 $fak = 1;
7 $max = $_[0];
8 for($i=1; $i<=$max; $i++) {
9 $fak *= $i;
10 }
11 return $fak;
12 }
13
14 print "Die Fakultaet von 7 ist " . &fak(7) . "\n";
In der zweiten Version fahren wir dann alle Geschütze auf. Sowohl die Rekursion, also auch meinen speziellen Liebling, den dreifach-Operator "?:".
1 #!/usr/bin/perl
2
3
sub fak {
4 $_[0] > 1 ? $_[0] * fak($_[0]-1) : 1;
5 }
6
7 print "Die Fakultaet von 7 ist " . fak(7) . "\n";
Falls was unklar ist, kommentiere ich gerne noch ausführlicher.

Coloring by Code2Html


    previousindexnext
    Objective CamlupPHP


    Control panel

    Comment viewing options:

    Select your prefered way to display the comments and click 'Update settings' to active your changes.


  • Ternärer Vergleichsoperatur r by citizen428@cargal.org
  • Navigation

    Log in
    Username:

    Password:

    Remember me

    » New password

    GnuPG
    Key-Suchstring:



    » add to Sidebar

    Latest poll: Wenn eins der
    folgenden Smartphones, dann....
    PALM PRE FTW!
    Motorola Milestone
    Nokia N900
    Sony Xperia X10 Rachael
    BOB hat ein Dynatac 8000 , das reicht mir auch!