Some Simple Scripts

Here are some simple scripts to illustrate the "look" of a Perl program.

Print a Message to the Terminal

Code:

  
  # file: message.pl
  print "When that Aprill with his shoures soote\n";
  print "The droghte of March ath perced to the roote,\n";
  print "And bathed every veyne in swich licour\n";
  print "Of which vertu engendered is the flour...\n";

Output:

(~) 50% perl message.pl
When that Aprill with his shoures soote
The droghte of March ath perced to the roote,
And bathed every veyne in swich licour
Of which vertu engendered is the flour...

Do Some Math

Code:


  # file: math.pl
  print "2 + 2 =", 2+2, "\n";
  print "log(1e23)= ", log(1e23), "\n";
  print "2 * sin(3.1414)= ", 2 * sin(3.1414), "\n";

Output:

(~) 51% perl math.pl
2 + 2 =4
log(1e23)= 52.9594571388631
2 * sin(3.1414)= 0.000385307177203065

Run a System Command

Code:

  
  # file: system.pl
  system "ls";

Output:

(~/docs/grad_course/perl) 52% perl system.pl
index.html	    math.pl~		problem_set.html~   what_is_perl.html
index.html~	    message.pl		simple.html	    what_is_perl.html~
math.pl		    problem_set.html	simple.html~

Return the Time of Day

Code:

  
  # file: time.pl
  $time = localtime;
  print "The time is now $time\n";

Output:

(~) 53% perl time.pl
The time is now Thu Sep 16 17:30:02 1999
<< Previous
Contents >> Next >>

Lincoln D. Stein, lstein@cshl.org
Cold Spring Harbor Laboratory
Last modified: Wed Oct 11 16:11:16 EDT 2000