in reply to Scripts with only sub-routines?

Some details would help here. Without having a look at what you have, I can only guess.

Modules that you use can execute code.

A sub BEGIN is actually a block that runs without being called, if you have any of those. See perlmod for more info and other blocks that might act this way.

You speak of some variable settings. Something like "my $host = `hostname` is actually executing the hostname shell command (note the backticks, not single quotes).

Replies are listed 'Best First'.
Re^2: Scripts with only sub-routines?
by Fletch (Bishop) on Mar 24, 2008 at 20:51 UTC
    Modules that you use can execute code

    Exactly; and the code they execute may not be immediately obvious.

    #!/usr/bin/perl use strict; use warnings; use EndRunner qw( foo ); sub foo_one { print "Foo one called!\n"; } sub foo_two { print "Foo two called\n"; } sub foo_dies { die "Aieee!\n"; } our $foo_bad_example = "no problem here"; __END__ ## This would go in EndRunner.pm package EndRunner; use strict; use warnings; our @ISA = qw( Exporter ); require Exporter; my @packages_to_run; sub import { my( $package, @args ) = @_; my $caller_package = ( caller( 1 ) )[0]; for my $prefix ( @args ) { push @packages_to_run, [ $caller_package, $prefix ]; } return; } END { no strict 'refs'; for my $items ( @packages_to_run ) { my( $package, $prefix ) = @{ $items }; for my $sub ( grep /^${prefix}_/, keys %{ $package . "::" } ) { my $sub_ref = *{"${package}::$sub"}{CODE}; next unless defined $sub_ref; eval { $sub_ref->(); }; if( $@ ) { warn "EndRunner: problem calling '$sub' in $package: $@\n"; } } } } 1; __END__

    Just imagine what chaos one could foment if you changed that to (say) rot13 the prefix before picking what to run, or generated the prefix based on the phase of the moon . . . :)

    The cake is a lie.
    The cake is a lie.
    The cake is a lie.