Anonymous user
Modulinos: Difference between revisions
Perl, Python, Ruby: stop exporting a function named 'main'.
m (→{{header|J}}) |
|||
Line 492:
=={{header|Perl}}==
Perl has scripted main. The code inside <tt>unless(caller) { ... }</tt> only runs when <tt>Life.pm</tt> is the main program.
<lang perl>#!/usr/bin/env perl
# Life.pm
package Life;
use strict;
use warnings;
sub meaning_of_life {
Line 504 ⟶ 506:
}
print "Main: The meaning of life is " . meaning_of_life() . "\n";
▲unless(caller) { main; }</lang>
<lang perl>#!/usr/bin/env perl
# death.pl
use strict;
use
use Life;
print "Test: The meaning of life is " . meaning_of_life() . "\n";</lang>▼
print "Life means " . Life::meaning_of_life . ".\n";
print "Death means invisible scary skeletons.\n";</lang>
=={{header|PHP}}==
Line 547 ⟶ 549:
=={{header|Python}}==
Python has scripted main.
<lang python>#!/usr/bin/env python
# life.py
def meaning_of_life():
if __name__ == "__main__":▼
<lang python>#!/usr/bin/env python▼
▲if __name__=="__main__":
▲ main()</lang>
▲<lang python>#!/usr/bin/env python
from life import
print "
print "Death means invisible scary skeletons."</lang>
=={{header|R}}==
Line 609:
Ruby has scripted main.
<lang ruby># life.rb
def meaning_of_life
end
if __FILE__ == $0
end</lang>
<lang ruby># death.rb
require
puts "
puts "Death means invisible scary skeletons."</lang>
=={{header|Tcl}}==
|