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: Advanced:
Getting text with system("");

 



Rivotti
User

Jul 3, 2001, 10:50 AM

Post #1 of 6 (1792 views)
Getting text with system(""); Can't Post

Hi,

I'm trying to get the text of perldoc and assign it to a variable like this:

my $func_text = system("perldoc -f $1"); #where $1 is the function

this returns nothing...
Is this the right way to do this? Is there any other?

thanks in advance
Rivotti



mhx
Enthusiast

Jul 3, 2001, 11:28 AM

Post #2 of 6 (1790 views)
Re: Getting text with system(""); [In reply to] Can't Post

It does not work because system() won't return the output of the command it executes, but its exit status. The easiest way to perform your task would be to use backticks:

Code
#!/bin/perl -w 
use strict;

my $fun = 'map';
my $doc = `perldoc -f $fun`;

print "$doc\n";

Another way would be to use the open() function with a pipe.
Hope this helps.

-- Marcus



Rivotti
User

Jul 3, 2001, 4:27 PM

Post #3 of 6 (1785 views)
Re: Getting text with system(""); [In reply to] Can't Post

Marcus...

That was great. Can you explain why? I never read about using `` before. Anyway thanks

Rivotti



Pro_4
User

Jul 3, 2001, 6:44 PM

Post #4 of 6 (1783 views)
Re: Getting text with system(""); [In reply to] Can't Post

Hmm, that is very interesting, when i run it on my computer it returns a General Failure Reading Device, but when i try just typing perldoc -f map it works.... weird. What exactly does the `` function do? Is there any perldoc things on it?

@letters = ('A'..'Z', 'a'..'z', '1'..'5', '_');
@i = ( '15', '43', '40');
print @letters [ @i, -1, 55];


Jasmine
Administrator / Moderator

Jul 3, 2001, 9:45 PM

Post #5 of 6 (1780 views)
Re: Getting text with system(""); [In reply to] Can't Post

Backticks are used to perform system commands -- check out http://www.perldoc.com/perl5.6/pod/func/system.html



Rivotti
User

Jul 4, 2001, 6:03 AM

Post #6 of 6 (1777 views)
Re: Getting text with system(""); [In reply to] Can't Post

Thanks Jasmine,

always a great help...

Rivotti


 
 


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

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