On Friday 09 November 2007 10:30, [EMAIL PROTECTED] wrote:
> Ok, so I'm not *really* a beginner; however, wondering if this is
> possible....

You have read the perlform man page?

perldoc perlform


> I have a subroutine that basically goes through an array and searches
> for processes... It has two different types of processes it looks
> for, so I just grabbed ps using ps -ef |grep someuser | grep someapp
> and threw it into an array.

Why run the external grep program when you can filter the ps output 
directly in perl?


> I am going through the array using foreach and doing something like
> this (note: format lines up properly in the script, looks kind of odd
> in this web-based editor):

You *do* have warnings and strict enabled?

use warnings;
use strict;


> sub some_routine() {

Why are you using prototypes?  There were introduced to allow one to 
override builtin functions, not for user subroutines.


> format PROC1_OUT =
> @<<<<<< @<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< @<<<<<
> "Tag 1:" $entry                                              $cps
> .
>
> format PROC2_OUT =
> @<<<<<< @<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< @<<<<<
> "Tag 2:"   $entry                                              $cps
> .
>
>   foreach $entry (@running_procs) {
>     print "entered foreach\n" if ($DEBUG);
>     $entry =~ s/Element\s\:\s//g;
>     # check ps...for $entry.  If running, print up, else print down.
>     $cps = false;

Is that supposed to be:

     $cps = false();

Or:

     $cps = 'false';

And why are you assigning a value here and then assigning another value 
on the next lie?


>     $cps = check_ps($entry);
>     write PROC1_OUT;
>   }
>
>   foreach $entry (@running_procs2) {
>     $entry =~ s/Element\s\:\s//g;
>     $entry =~ s/\s*Manager*//g;

The pattern 'Manager*' matches 'Manage' or 'Manager' or 
'Managerrrrrrrrr'.  Is that really what you wanted?


>     $cps = false;
>     $cps = check_ps($entry);

There's that double assignment and bareword again.


>     # check ps...for $entry.  If running, print up, else print down.
>     write PROC2_OUT;
>   }
> }
>
> Here's the deal...I need this to write to STDOUT for both, but need a
> separate tag for each format.  This works w/ STDOUT just fine (if I
> format STDOUT once), but I don't want the same tag (see format above)
> for both outputs.

I can think two ways to do what you want.

Number 1:  Change the Format Name variable.

$ perl -le'
format FORM1 =
@<<<<<<<<<<<<<<
"Form 1"
.
format FORM2 =
@<<<<<<<<<<<<<<
"Form 2"
.

select( ( select( STDOUT ), $~ = "FORM1" )[ 0 ] );
write;
select( ( select( STDOUT ), $~ = "FORM2" )[ 0 ] );
write;
'
Form 1
Form 2



Number 2:  Use a variable instead of a literal string.

$ perl -le'
my $tag = "Form 1";

format STDOUT =
@<<<<<<<<<<<<<<
$tag
.

write;
$tag = "Form 2";
write;
'
Form 1
Form 2




John
-- 
use Perl;
program
fulfillment

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/


Reply via email to