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:
Help from an Expert on simple code

 



jay
New User

Sep 23, 2005, 9:28 PM

Post #1 of 5 (1004 views)
Help from an Expert on simple code Can't Post

Fellows,

I'm looking for some guidance/assistance with a code I'm trying to come
up with. Machine: Redhat 9

I'm looking for a simple code that will execute something like this:
cat /proc/cpuinfo |grep processor

cat /proc/cpuinfo |grep MHz

execute lspci |grep 00:07.0
but if it encounters more then 1 line for 00:07.0 ignore it, and only print once.

Then somehow print it to display like this:
processor : 0 cpu MHz : 497.443
00:07.0 ISA bridge: Intel Corp. 82371AB/EB/MB PIIX4 ISA (rev 02)


Can someone give me a hand on this?

Any help would be greatly appreciated.

Sincerely,
Jay


jay
New User

Sep 24, 2005, 7:36 PM

Post #2 of 5 (1000 views)
Re: [jay] Help from an Expert on simple code [In reply to] Can't Post

Guys,
I'm just looking for a little help from the experts. Just
a couple of lines or the sintex to exec the commands within perl i.e.:

#!/usr/bin/perl -w

@output1 = exec cat /proc/cpuinfo |grep processor;
print @output1 /n;

any guidance? I'm not sure how to exec commands here, that's why I'm posting this - for help. thx


mulander
New User

Sep 25, 2005, 10:24 PM

Post #3 of 5 (997 views)
Re: [jay] Help from an Expert on simple code [In reply to] Can't Post

If you use the exec command, your perl script executes the supplied command and exits itself so you will not cache the output to @output1, try backticks instead:

Code
#!/usr/bin/perl 
use warnings;
use strict;
my @output1 = `cat /proc/cpuinfo | grep processor`;
print "@output1\n";

Of course instead of using the system grep you can use perl buildin grep, map or regexps.


davorg
Thaumaturge / Moderator

Sep 26, 2005, 2:19 AM

Post #4 of 5 (994 views)
Re: [jay] Help from an Expert on simple code [In reply to] Can't Post

You use the qx() operator to execute an external command an capture the output.


Code
my @cpuinfo = qw(grep processor /proc/cpuinfo);


You'll often see that written using backticks instead - that's just another version of the same thing.


Code
my @cpuinfo = `grep processor /proc/cpuinfo`;


p.s. This really isn't "advanced", so I've moved the thread into the beginners' forum and removed the copy that you had already put there. Please don't ask the same question in multiple forums.

--
Dave Cross, Perl Hacker, Trainer and Writer
http://www.dave.org.uk/
Get more help at Perl Monks


(This post was edited by davorg on Sep 26, 2005, 3:24 AM)


jay
New User

Sep 26, 2005, 3:38 PM

Post #5 of 5 (987 views)
Re: [davorg] Help from an Expert on simple code [In reply to] Can't Post

Thanks. This is what I was looking for. Thx fellows.

 
 


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

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