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

Main routines, unit tests, and sugar

by stephen (Priest)
on Jun 13, 2013 at 04:43 UTC ( #1038667=perlmeditation: print w/ replies, xml ) Need Help??

Help for this page

Select Code to Download


  1. or download this
    #!/usr/bin/env perl
    
    ...
        
        print "Hello $name\n";
    }
    
  2. or download this
    # Main routine
    sub main {
    ...
    }
    
    main();
    
  3. or download this
    # Main routine
    MAIN: {
    ...
    
        say_hello($greeted);
    }
    
  4. or download this
    # Main routine
    MAIN: {
    ...
    
        exit(0);
    }
    
  5. or download this
    package My::Routine;
    
    ...
    
    # Run the main routine only when called as a script
    __PACKAGE__->main() unless caller;
    
  6. or download this
    #!/usr/bin/perl
    
    ...
        say_hello($greeted);
    };
    
  7. or download this
    #!/usr/bin/env perl
    require 'script_with_main.pl';
    print "Loaded script!\n";
    run_main('Shakespeare!', 'perlmonks');
    
  8. or download this
    $ perl test_test_main.pl 
    Loaded script!
    Hello perlmonks
    
  9. or download this
    use strict;
    use warnings;
    ...
    };
    
    1;
    

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlmeditation [id://1038667]
Approved by davido
Front-paged by davido
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (6)
As of 2014-07-10 07:46 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    When choosing user names for websites, I prefer to use:








    Results (202 votes), past polls