CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner:
finding right system( )

 



andersqf
Novice

Apr 2, 2009, 7:30 AM

Post #1 of 2 (682 views)
finding right system( ) Can't Post

I have a package aa with a subroutine system( ); which calls the subroutine system. It does work but after learning a little more about perl I do not understand why.

As I understand it, after declaring package aa, every call to system( ); should invoke aa::system( );. instead I get the perl subroutine system (as I want to). If I change to main::system( );, perl does not find the subroutine.

I am not complaining, I am just curious.

The code:

package aa;

sub system( ) {
my $directive = $_[0];
my $status = 0;
if( ! $aa::inhibit ) { $status = system( $directive ); }
my $line1 = "system $status $directive\n";
if( $aa::print ) { print $line1; }
if( $status != 0 ) {
if( !$aa::print ) { print $line1; }
my $line2 = ' *** ERROR *** ' . $! . "\n";
print $line2;
}
return $status;
}


FishMonger
Veteran / Moderator

Apr 2, 2009, 7:59 AM

Post #2 of 2 (678 views)
Re: [andersqf] finding right system( ) [In reply to] Can't Post

Start by reading the "Overriding Built-in Functions " section in perldoc perlsub
http://perldoc.perl.org/perlsub.html#Overriding-Built-in-Functions

as well as the "Prototypes" section.
http://perldoc.perl.org/perlsub.html#Prototypes


(This post was edited by FishMonger on Apr 2, 2009, 8:01 AM)

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives