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:
sub definitions

 



andersqf
Novice

Jan 9, 2009, 6:28 AM

Post #1 of 12 (2837 views)
sub definitions Can't Post

Is there some place where I can get well defined documentation on Perl subroutines? I am using ActivePerl on XP Pro SP3 and they have a lot of documentation but they do not have, as far as I can find, any search function.

My immediate problem is that I want the return status from the system( ) subroutine to check if it worked OK. I also want some place to search for other subfunctions when I need it.

I think there should be some post in the FAQ forum on finding help, this forum however does not have any post since 2002.

Thanks for any answer
andersqf


FishMonger
Veteran / Moderator

Jan 9, 2009, 6:39 AM

Post #2 of 12 (2835 views)
Re: [andersqf] sub definitions [In reply to] Can't Post

Is this what you're looking for?

perldoc perldoc
perldoc perl
perldoc perlsub
perldoc -f system


Code
if ( system(....) == 0 ) { 
print "system command was successful";
}
else {
print "system command failed";
}



(This post was edited by FishMonger on Jan 9, 2009, 6:42 AM)


andersqf
Novice

Jan 9, 2009, 7:15 AM

Post #3 of 12 (2829 views)
Re: [FishMonger] sub definitions [In reply to] Can't Post

Well, yes and no.

Where do I write for example "perldoc -f system"? As I said, I could not find any search function in the ActivePerl documentation. Does perlguru have some place where I can search perldoc? I only found SEARCH POSTS.


FishMonger
Veteran / Moderator

Jan 9, 2009, 7:48 AM

Post #4 of 12 (2828 views)
Re: [andersqf] sub definitions [In reply to] Can't Post

"perldoc -f system" is executed from the command line, like this:


Code
C:\>perldoc -f system 
system LIST
system PROGRAM LIST
Does exactly the same thing as "exec LIST", except that a fork
is done first, and the parent process waits for the child
process to complete. Note that argument processing varies
depending on the number of arguments. If there is more than one
argument in LIST, or if LIST is an array with more than one
value, starts the program given by the first element of the list
with arguments given by the rest of the list. If there is only
one scalar argument, the argument is checked for shell
metacharacters, and if there are any, the entire argument is
passed to the system's command shell for parsing (this is
"/bin/sh -c" on Unix platforms, but varies on other platforms).
If there are no shell metacharacters in the argument, it is
split into words and passed directly to "execvp", which is more
efficient.

Beginning with v5.6.0, Perl will attempt to flush all files
opened for output before any operation that may do a fork, but
this may not be supported on some platforms (see perlport). To
be safe, you may need to set $| ($AUTOFLUSH in English) or call
the "autoflush()" method of "IO::Handle" on any open handles.

The return value is the exit status of the program as returned
by the "wait" call. To get the actual exit value, shift right by
eight (see below). See also "exec". This is *not* what you want
to use to capture the output from a command, for that you should
use merely backticks or "qx//", as described in "`STRING`" in
perlop. Return value of -1 indicates a failure to start the
program or an error of the wait(2) system call (inspect $! for
the reason).

Like "exec", "system" allows you to lie to a program about its
name if you use the "system PROGRAM LIST" syntax. Again, see
"exec".

Since "SIGINT" and "SIGQUIT" are ignored during the execution of
"system", if you expect your program to terminate on receipt of
these signals you will need to arrange to do so yourself based
on the return value.

@args = ("command", "arg1", "arg2");
system(@args) == 0
or die "system @args failed: $?"

You can check all the failure possibilities by inspecting $?
like this:

if ($? == -1) {
print "failed to execute: $!\n";
}
elsif ($? & 127) {
printf "child died with signal %d, %s coredump\n",
($? & 127), ($? & 128) ? 'with' : 'without';
}
else {
printf "child exited with value %d\n", $? >> 8;
}

Alternatively you might inspect the value of
"${^CHILD_ERROR_NATIVE}" with the W*() calls of the POSIX
extension.

When the arguments get executed via the system shell, results
and return codes will be subject to its quirks and capabilities.
See "`STRING`" in perlop and "exec" for details.


Or on the web at:
http://perldoc.perl.org/



shawnhcorey
Enthusiast


Jan 9, 2009, 8:05 AM

Post #5 of 12 (2826 views)
Re: [andersqf] sub definitions [In reply to] Can't Post


In Reply To
Well, yes and no.

Where do I write for example "perldoc -f system"? As I said, I could not find any search function in the ActivePerl documentation. Does perlguru have some place where I can search perldoc? I only found SEARCH POSTS.


Start a DOS PROMPT from the Start menu and type in the command.

The status returned by system under Windows is always zero. You have to find other ways to test its status.

__END__

I love Perl; it's the only language where you can bless your thingy.

Perl documentation is available at perldoc.perl.org. The list of standard modules and pragmatics is available in perlmodlib.

Get Markup Help. Please note the markup tag of "code".


andersqf
Novice

Jan 9, 2009, 8:11 AM

Post #6 of 12 (2824 views)
Re: [shawnhcorey] sub definitions [In reply to] Can't Post

OK, got it.

Thanks
andersqf


KevinR
Veteran


Jan 9, 2009, 9:44 AM

Post #7 of 12 (2819 views)
Re: [andersqf] sub definitions [In reply to] Can't Post


In Reply To
OK, got it.

Thanks
andersqf


Activeperl comes with a ton of documentation:

start>>programs>>activeperl>>documentation

(it may be different on your computer)

It will open your default browser because its in html format. Its really much easier than using the DOS window although you can do it that way too.
-------------------------------------------------


FishMonger
Veteran / Moderator

Jan 9, 2009, 9:58 AM

Post #8 of 12 (2817 views)
Re: [shawnhcorey] sub definitions [In reply to] Can't Post

I'm not trying to be "nit picky" but for the sake of accuracy it's not a DOS window in XP. It's a cmd window which emulates dos for backwards compatibility.


(This post was edited by FishMonger on Jan 9, 2009, 9:59 AM)


shawnhcorey
Enthusiast


Jan 9, 2009, 10:56 AM

Post #9 of 12 (2812 views)
Re: [FishMonger] sub definitions [In reply to] Can't Post

Don't do Windows.

I thought it was still called a Dos Prompt in the Start menu.

__END__

I love Perl; it's the only language where you can bless your thingy.

Perl documentation is available at perldoc.perl.org. The list of standard modules and pragmatics is available in perlmodlib.

Get Markup Help. Please note the markup tag of "code".


FishMonger
Veteran / Moderator

Jan 9, 2009, 11:02 AM

Post #10 of 12 (2811 views)
Re: [shawnhcorey] sub definitions [In reply to] Can't Post

Nope, it's called "Command Prompt"


andersqf
Novice

Jan 9, 2009, 12:24 PM

Post #11 of 12 (2806 views)
Re: [KevinR] sub definitions [In reply to] Can't Post

Yes, I know that there is a lot of documentation. My problem was that I could not find a search function, I could for example not find the documentation for the 'system' subroutine.


KevinR
Veteran


Jan 9, 2009, 1:04 PM

Post #12 of 12 (2802 views)
Re: [andersqf] sub definitions [In reply to] Can't Post


In Reply To
Yes, I know that there is a lot of documentation. My problem was that I could not find a search function, I could for example not find the documentation for the 'system' subroutine.


In the navigation menu on the left, Perl Core Documentation, then the perlfunc link. Lists all of perls builtin functions and describes them.
-------------------------------------------------

 
 


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

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