DeveloperGuy <> wrote:
> I am very very new to Perl
We will still expect that you use Perl rather than something
merely Perlish-looking.
> and am trying automate a process in my AIX
> Unix box. I issed the command ps -aef and sent it to a file.
You can do that from within Perl itself, no need for a file.
my @ps_lines = `ps -aef`; # backwards single quotes
or
my @ps_lines = qx/ps -aef/; # backwards single quotes in disguise
or
open PS, 'ps -aef|' or die "could not run ps $!";
while ( <PS> ) ...
> How do
> I get how many different users running programs, the total time for
> each user in hours:minutes format, and who is running the longest
> process and the program name?
By parsing the output of the ps command.
You might want to use Perl's unpack() or substr() functions
to help you with that.
> I am not familiar with using the loops.
Then become familiar with using the loops, they are documented in:
perldoc perlsyn
> I know that I can probably use the date command to specify the date.
You can do that from within Perl too, no need for an external date program.
perldoc -f localtime
perldoc -f gmtime
> This is where I am stuck thus far. Please help anyone...
>
> #! /usr/bin/perl
>
> use strict;
When you put that in your programs you are making a promise:
I promise to declare my variables before using their short names.
If you break your promise, then perl will refuse to run your program.
> use warnings;
>
> @users;
You have not declared that variable, so perl refuses to run your program.
my @users;
> @tmpfile = OPEN(DataFileHandle, /home/smallp/data.txt);
Perl does not have an OPEN() function, only an open() function.
Case matters.
Put 'quotes' around your strings.
open() returns a single thing, no need for an array to hold its return value.
It is a convention to use all UPPER CASE for filehandles.
You should always, yes *always*, check the return value from open()
to ensure that you actually got what you asked for:
open DATA_FILEHANDLE, '/home/smallp/data.txt' or
die "could not open '/home/smallp/data.txt' $!";
Your code never makes use of the filehandle. You will need to *read*
from it to get the data to process...
> $tmpfile[0];
> $users[0];
Those are do-nothing statements, they have no useful effect.
What were you hoping those 2 lines of code would do for you?
> for ($count= 0; $count <= $#users; $count++
{
A more Perlish way to get the same thing is:
foreach my $count ( 0 .. $#users ) {
> If $tmpline[0] eq $users[i]
Perl does not have an "If" keyword, only an "if" keyword.
Case (still) matters.
You need (parenthesis) around the condition in an if statement.
> if TRUE then exit
Perl does not even have a "then" keyword, nor a "TRUE" keyword.
This is not Perl code. What language is it?
--
Tad McClellan SGML consulting
Perl programming
Fort Worth, Texas