Re: RE : Regular expressions

2003-12-17 Thread Jeff 'japhy' Pinyan
On Dec 17, Hemond, Steve said:

Actually, I have to test two conditions to get into a block,

If the strings found are either one two or two three, go ahead.

if ($text =~ /one two/ or /two three/)

That code is the same as

  if (($text =~ /one two/) or ($_ =~ /two three/)) { ... }

You want either

  if ($text =~ /one two/ or $text =~ /two three/) { ... }

or

  if ($text =~ /one two|two three/) { ... }

-- 
Jeff japhy Pinyan  [EMAIL PROTECTED]  http://www.pobox.com/~japhy/
RPI Acacia brother #734   http://www.perlmonks.org/   http://www.cpan.org/
stu what does y/// stand for?  tenderpuss why, yansliterate of course.
[  I'm looking for programming work.  If you like my work, let me know.  ]


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




Re: RE : Regular expressions

2003-12-17 Thread James Edward Gray II
On Dec 17, 2003, at 10:09 AM, Hemond, Steve wrote:

Actually, I have to test two conditions to get into a block,

If the strings found are either one two or two three, go ahead.

if ($text =~ /one two/ or /two three/)
Now that is a mistake.  ;)

if ($text =~ /\bone two\b/ || $text =~ /\btwo three\b/) {

James

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



Re: RE : Regular expressions

2003-12-17 Thread James Edward Gray II
On Dec 17, 2003, at 10:29 AM, Hemond, Steve wrote:

Okay, here`s the real problem,

# ps -efA |grep dispatch
cspenard 33958 45716   0 09:08:05  pts/8  0:00 
/prog/gena/8.1.1/bin/dispatch genie -u /prog/gena/impress/gui/im
msirois 37212  9842   0 08:41:17  pts/1  0:04 
/prog/gena/8.1.1/bin/dispatch genie -u /prog/gena/impress/gui/im

My script passes each process and when it finds dispatch genie it 
holds its data in a hash table.

As you can see, dispatch genie is found in these two columns.

if ($cmd =~ /dispatch genie/)  {

That returns absolutely nothing.

Why?
returns nothing is a little confusing.  The test above should 
evaluate to true, if $cmd contains 'dispatch genie' and whatever is 
inside the if block should be executed.  If you're saying the if block 
isn't being executed, well $cmd probably doesn't contain what you think 
it does then.

James

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



RE: RE : Regular expressions

2003-12-17 Thread Ed Christian
Hemond, Steve wrote:
 Okay, here`s the real problem,
 
 # ps -efA |grep dispatch
 cspenard 33958 45716   0 09:08:05  pts/8  0:00
 /prog/gena/8.1.1/bin/dispatch genie -u /prog/gena/impress/gui/im
 msirois 37212  9842   0 08:41:17  pts/1  0:04
 /prog/gena/8.1.1/bin/dispatch genie -u /prog/gena/impress/gui/im  
 
 My script passes each process and when it finds dispatch genie it
 holds its data in a hash table. 
 
 As you can see, dispatch genie is found in these two columns.
 
 if ($cmd =~ /dispatch genie/)  {
 
 That returns absolutely nothing.
 
 Why?
 


Again, that regexp works just fine. (If you're setting $cmd properly...)
Something else must be wrong that you're not sending in your email
requests. Send the actual code.

#!/usr/bin/perl -w
use warnings;
use strict;

while (DATA) {
chomp;
(/dispatch genie/) ? print Hit\n : print Miss\n;
}

__DATA__
cspenard 33958 45716   0 09:08:05  pts/8  0:00
/prog/gena/8.1.1/bin/dispatch genie -u /prog/gena/impress/gui/im
msirois 37212  9842   0 08:41:17  pts/1  0:04
/prog/gena/8.1.1/bin/dispatch genie -u /prog/gena/impress/gui/im

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




RE : RE : Regular expressions

2003-12-17 Thread Hemond, Steve
I think I begin to understand...

I begin by fetching the results of the ps -efA command and split it into many 
variables ($uid, $pid, etc.)

open(PS, ps -efA|); 
while (PS) { 
($uid,$pid,$ppid,$c,$stime,$tty,$time,$cmd) = split;

if ($cmd =~ /dispatch genie/)  {
$infos{$pid}{'uid'}   = $uid;
$infos{$pid}{'ppid'}  = $ppid;
$infos{$pid}{'c'} = $c;
$infos{$pid}{'stime'} = $stime;
$infos{$pid}{'tty'}   = $tty;
$infos{$pid}{'time'}  = $time;
$infos{$pid}{'cmd'}   = $cmd;


I thought $cmd, as the last variable for the split command, would contain the next 
word and also the rest of the line, which it does not. It seems to take only the next 
word and do nothing with the rest of the line.

So $cmd contains /prog/gena/8.1.1/bin/dispatch 

NOT /prog/gena/8.1.1/bin/dispatch genie -u /prog/gena/impress/gui/im

Steve Hemond
Programmeur Analyste / Analyst Programmer
Smurfit-Stone, Ressources Forestières
La Tuque, P.Q.
Tel.: (819) 676-8100 X2833
[EMAIL PROTECTED] 



  -Original Message-
  From: Ed Christian [mailto:[EMAIL PROTECTED] 
  Sent: Wednesday, December 17, 2003 11:40 AM
  To: Hemond, Steve
  Cc: [EMAIL PROTECTED]
  Subject: RE: RE : Regular expressions
  
  
  Hemond, Steve wrote:
   Okay, here`s the real problem,
   
   # ps -efA |grep dispatch
   cspenard 33958 45716   0 09:08:05  pts/8  0:00
   /prog/gena/8.1.1/bin/dispatch genie -u /prog/gena/impress/gui/im
   msirois 37212  9842   0 08:41:17  pts/1  0:04
   /prog/gena/8.1.1/bin/dispatch genie -u /prog/gena/impress/gui/im
   
   My script passes each process and when it finds dispatch 
  genie it 
   holds its data in a hash table.
   
   As you can see, dispatch genie is found in these two columns.
   
   if ($cmd =~ /dispatch genie/)  {
   
   That returns absolutely nothing.
   
   Why?
   
  
  
  Again, that regexp works just fine. (If you're setting $cmd 
  properly...) Something else must be wrong that you're not 
  sending in your email requests. Send the actual code.
  
  #!/usr/bin/perl -w
  use warnings;
  use strict;
  
  while (DATA) {
  chomp;
  (/dispatch genie/) ? print Hit\n : print Miss\n;
  }
  
  __DATA__
  cspenard 33958 45716   0 09:08:05  pts/8  0:00
  /prog/gena/8.1.1/bin/dispatch genie -u /prog/gena/impress/gui/im
  msirois 37212  9842   0 08:41:17  pts/1  0:04
  /prog/gena/8.1.1/bin/dispatch genie -u /prog/gena/impress/gui/im
  

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




Re: RE : RE : Regular expressions

2003-12-17 Thread drieux
On Dec 17, 2003, at 8:47 AM, Hemond, Steve wrote:
[..]
open(PS, ps -efA|);
while (PS) {
($uid,$pid,$ppid,$c,$stime,$tty,$time,$cmd) = split;
[..]

forgive me if I presume that you are running on some
version of Linux? ( because by BSD boxes do not like the A
and my Solaris box would get what you are looking for )
hence
meatbop: 53:] ps -efA | grep httpd.conf
drieux   11069 10988  0 10:08 pts/000:00:00 grep httpd.conf
meatbop: 54:]  ps -efAww | grep httpd.conf
root  1644 1  0 Nov10 ?00:00:00 
/usr/sbin/httpd2-prefork -f /etc/apache2/httpd.conf
hqadmin   1645  1644  0 Nov10 ?00:00:00 
/usr/sbin/httpd2-prefork -f /etc/apache2/httpd.conf
hqadmin   1646  1644  0 Nov10 ?00:00:00 
/usr/sbin/httpd2-prefork -f /etc/apache2/httpd.conf
hqadmin   1647  1644  0 Nov10 ?00:00:00 
/usr/sbin/httpd2-prefork -f /etc/apache2/httpd.conf
hqadmin   1648  1644  0 Nov10 ?00:00:00 
/usr/sbin/httpd2-prefork -f /etc/apache2/httpd.conf
hqadmin   1649  1644  0 Nov10 ?00:00:00 
/usr/sbin/httpd2-prefork -f /etc/apache2/httpd.conf
drieux   11071 11031  0 10:08 pts/100:00:00 grep httpd.conf
meatbop: 55:]

it is possible that you are getting bitten by the classic
problem of the 'ps output' being truncated to the 'terminal size'
since you did not expressly assert that you wanted to 'go big'.
Hence the problem is NOT with the RegEx, but with limitations
of what is actually being put into $cmd based upon the input
from the popen() command as invoked.
HTH.

ciao
drieux
---

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



RE : RE : RE : Regular expressions

2003-12-17 Thread Hemond, Steve
I am issuing this command on an Aix box and running allright :-)

Forgive my curiosity.. are you running Solaris on a x86 box? 

Steve Hemond
Programmeur Analyste / Analyst Programmer
Smurfit-Stone, Ressources Forestières
La Tuque, P.Q.
Tel.: (819) 676-8100 X2833
[EMAIL PROTECTED] 



  -Original Message-
  From: drieux [mailto:[EMAIL PROTECTED] 
  Sent: Wednesday, December 17, 2003 1:14 PM
  To: Perl Perl
  Subject: Re: RE : RE : Regular expressions
  
  
  
  On Dec 17, 2003, at 8:47 AM, Hemond, Steve wrote:
  [..]
   open(PS, ps -efA|);
   while (PS) {
  ($uid,$pid,$ppid,$c,$stime,$tty,$time,$cmd) = split;
  [..]
  
  forgive me if I presume that you are running on some
  version of Linux? ( because by BSD boxes do not like the A 
  and my Solaris box would get what you are looking for ) hence
  
  meatbop: 53:] ps -efA | grep httpd.conf
  drieux   11069 10988  0 10:08 pts/000:00:00 grep httpd.conf
  meatbop: 54:]  ps -efAww | grep httpd.conf
  root  1644 1  0 Nov10 ?00:00:00 
  /usr/sbin/httpd2-prefork -f /etc/apache2/httpd.conf
  hqadmin   1645  1644  0 Nov10 ?00:00:00 
  /usr/sbin/httpd2-prefork -f /etc/apache2/httpd.conf
  hqadmin   1646  1644  0 Nov10 ?00:00:00 
  /usr/sbin/httpd2-prefork -f /etc/apache2/httpd.conf
  hqadmin   1647  1644  0 Nov10 ?00:00:00 
  /usr/sbin/httpd2-prefork -f /etc/apache2/httpd.conf
  hqadmin   1648  1644  0 Nov10 ?00:00:00 
  /usr/sbin/httpd2-prefork -f /etc/apache2/httpd.conf
  hqadmin   1649  1644  0 Nov10 ?00:00:00 
  /usr/sbin/httpd2-prefork -f /etc/apache2/httpd.conf
  drieux   11071 11031  0 10:08 pts/100:00:00 grep httpd.conf
  meatbop: 55:]
  
  it is possible that you are getting bitten by the classic 
  problem of the 'ps output' being truncated to the 'terminal 
  size' since you did not expressly assert that you wanted to 'go big'.
  
  Hence the problem is NOT with the RegEx, but with 
  limitations of what is actually being put into $cmd based 
  upon the input from the popen() command as invoked.
  
  HTH.
  
  
  ciao
  drieux
  
  ---
  
  
  -- 
  To unsubscribe, e-mail: [EMAIL PROTECTED]
  For additional commands, e-mail: [EMAIL PROTECTED] 
http://learn.perl.org/ http://learn.perl.org/first-response


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




Re: RE : RE : RE : Regular expressions

2003-12-17 Thread drieux
On Dec 17, 2003, at 10:16 AM, Hemond, Steve wrote:

I am issuing this command on an Aix box and running allright :-)
interesting,

let's do a quick piece of test code

open(PS, ps -efA|) or die unable to open ps command\n:$!;
while (PS) {
($uid,$pid,$ppid,$c,$stime,$tty,$time,$cmd) = split;
print $pid - $cmd\n;
}
close(PS);
that will at least get us to what is going on with
the actual $cmd data itself.
Forgive my curiosity..
Curiosity Killed The Cat you know...
But the cat came back, the very next day,
thought he was a gonner but cat came back...
- old american folk song.
are you running Solaris on a x86 box?
Solaris on Sparc and x86
FreeBsd, some variations on linux,
my desk top tho is OSX.
Haven't been on an AIX box in a while.
Loved Unicos. But real Men are not afraid
to toggle it into a PDP-8 or an AN/Ukky-20
in battleship grey, or ...
ciao
drieux
---

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



RE : RE : RE : RE : Regular expressions

2003-12-17 Thread Hemond, Steve
Here is a sample of what your piece of code returns on my Aix box.

44520 - /prog/gena/8.1.1/bin/dispatch
44650 - reproject
45176 - aioserver
45432 - aioserver
45724 - -ksh
46002 - /bin/bsh
46232 - /usr/dt/bin/dtterm
46584 - /usr/bin/ksh
46820 - /usr/dt/bin/ttsession
47060 - /bin/bsh
47304 - /usr/dt/bin/dtlogin
47396 - /usr/dt/bin/dtterm
47722 - dtfile
47942 - /usr/dt/bin/dtsession
48272 - dtfile
48568 - ora_cjq0_gist
48758 - gxtrackd
49032 - dtwm
49330 - /usr/lib/lpd/pio/etc/piohpnpf
49592 - bsh
49672 - /usr/dt/bin/dtterm
50170 - /usr/dt/bin/dtlogin
50400 - dtterm
50604 - dispscript
50844 - genie
51096 - /prog/gena/8.1.1/bin/dispatch
51348 - gmap
51676 - reproject
51874 - gxtrackd
52086 - ps
52378 - perl
52646 - sh
53164 - /usr/bin/ksh
53432 - /bin/bsh

Like $cmd will stop at the end of the word, not the end of the rest of the line.

Steve Hemond
Programmeur Analyste / Analyst Programmer
Smurfit-Stone, Ressources Forestières
La Tuque, P.Q.
Tel.: (819) 676-8100 X2833
[EMAIL PROTECTED] 



  -Original Message-
  From: drieux [mailto:[EMAIL PROTECTED] 
  Sent: Wednesday, December 17, 2003 1:24 PM
  To: Perl Perl
  Subject: Re: RE : RE : RE : Regular expressions
  
  
  
  On Dec 17, 2003, at 10:16 AM, Hemond, Steve wrote:
  
   I am issuing this command on an Aix box and running allright :-)
  
  interesting,
  
  let's do a quick piece of test code
  
   open(PS, ps -efA|) or die unable to open ps command\n:$!;
   while (PS) {
   ($uid,$pid,$ppid,$c,$stime,$tty,$time,$cmd) = split;
   print $pid - $cmd\n;
   }
   close(PS);
  
  that will at least get us to what is going on with
  the actual $cmd data itself.
  
   Forgive my curiosity..
  
  Curiosity Killed The Cat you know...
  But the cat came back, the very next day,
  thought he was a gonner but cat came back...
   - old american folk song.
  
   are you running Solaris on a x86 box?
  
  Solaris on Sparc and x86
  FreeBsd, some variations on linux,
  my desk top tho is OSX.
  Haven't been on an AIX box in a while.
  Loved Unicos. But real Men are not afraid
  to toggle it into a PDP-8 or an AN/Ukky-20
  in battleship grey, or ...
  
  
  ciao
  drieux
  
  ---
  
  
  -- 
  To unsubscribe, e-mail: [EMAIL PROTECTED]
  For additional commands, e-mail: [EMAIL PROTECTED] 
http://learn.perl.org/ http://learn.perl.org/first-response


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




Re: RE : RE : RE : Regular expressions

2003-12-17 Thread drieux
On Dec 17, 2003, at 10:24 AM, drieux wrote:

open(PS, ps -efA|) or die unable to open ps command\n:$!;
while (PS) {
($uid,$pid,$ppid,$c,$stime,$tty,$time,$cmd) = split;
print $pid - $cmd\n;
}
close(PS);
Tell me not to make my coffee with last night's bong water!
if split is splitting on the default blank space,
root $1
1644 $2
1   $3
0   $4
Nov10   $5
?   $6
00:00:00  $7
/usr/sbin/httpd2-prefork  $8
	-f /etc/apache2/httpd.conf

what we want is the saner process of

	($uid,$pid,$ppid,$c,$stime,$tty,$time,$cmd) = split(/\s+/,$_,8);

eg:

sed 's/^/### /' junk.plx
### #!/usr/bin/perl -w
### use strict;
###
### open(PS, ps -efAww | grep http|);
### while(PS)
### {
### #   my ($uid,$pid,$ppid,$c,$stime,$tty,$time,$cmd) = split;
### #   print $pid - $cmd\n;
### my  ($uid,$pid,$ppid,$c,$stime,$tty,$time,$cmd) = split(/\s+/,$_,8);
### print Better $pid - $cmd\n;
### print \t$uid,$pid,$ppid,$c,$stime,$tty,$time,$cmd\n;
###
### }
My Apology!

ciao
drieux
---

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



Re: RE : RE : Regular expressions

2003-12-17 Thread Wiggins d Anconia


 I think I begin to understand...
 
 I begin by fetching the results of the ps -efA command and split it
into many variables ($uid, $pid, etc.)
 
 open(PS, ps -efA|); 
 while (PS) { 
   ($uid,$pid,$ppid,$c,$stime,$tty,$time,$cmd) = split;
 
   if ($cmd =~ /dispatch genie/)  {
   $infos{$pid}{'uid'}   = $uid;
   $infos{$pid}{'ppid'}  = $ppid;
   $infos{$pid}{'c'} = $c;
   $infos{$pid}{'stime'} = $stime;
   $infos{$pid}{'tty'}   = $tty;
   $infos{$pid}{'time'}  = $time;
   $infos{$pid}{'cmd'}   = $cmd;
 
 
 I thought $cmd, as the last variable for the split command, would
contain the next word and also the rest of the line, which it does not.
It seems to take only the next word and do nothing with the rest of the
line.
 
 So $cmd contains /prog/gena/8.1.1/bin/dispatch 
 
 NOT /prog/gena/8.1.1/bin/dispatch genie -u /prog/gena/impress/gui/im
 

Ah!  And now we have come full circle back to Why you should use a
module to handle this type of code rather than re-inventing the wheel!

You don't risk breaking the spokes of the wheel while fixing the pedals
if you don't start out by reinventing the wheel to begin with...

http://danconia.org

--
Boycott the Sugar Bowl! You couldn't pay me to watch that game.

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




RE : RE : RE : RE : Regular expressions

2003-12-17 Thread Hemond, Steve
No worries :-)

It works now, thanks a lot :-)

Best regards,

Steve Hemond
Programmeur Analyste / Analyst Programmer
Smurfit-Stone, Ressources Forestières
La Tuque, P.Q.
Tel.: (819) 676-8100 X2833
[EMAIL PROTECTED] 



  -Original Message-
  From: drieux [mailto:[EMAIL PROTECTED] 
  Sent: Wednesday, December 17, 2003 1:38 PM
  To: Perl Perl
  Subject: Re: RE : RE : RE : Regular expressions
  
  
  
  On Dec 17, 2003, at 10:24 AM, drieux wrote:
  
  
  open(PS, ps -efA|) or die unable to open ps command\n:$!;
   while (PS) {
  ($uid,$pid,$ppid,$c,$stime,$tty,$time,$cmd) = split;
  print $pid - $cmd\n;
  }
  close(PS);
  
  Tell me not to make my coffee with last night's bong water!
  if split is splitting on the default blank space,
  
   root $1
   1644 $2
   1   $3
   0   $4
   Nov10   $5
   ?   $6
   00:00:00  $7
   /usr/sbin/httpd2-prefork  $8
  
   -f /etc/apache2/httpd.conf
  
  what we want is the saner process of
  
   ($uid,$pid,$ppid,$c,$stime,$tty,$time,$cmd) = split(/\s+/,$_,8);
  
  eg:
  
  sed 's/^/### /' junk.plx
  ### #!/usr/bin/perl -w
  ### use strict;
  ###
  ### open(PS, ps -efAww | grep http|);
  ### while(PS)
  ### {
  ### #   my ($uid,$pid,$ppid,$c,$stime,$tty,$time,$cmd) = split;
  ### #   print $pid - $cmd\n;
  ### my  ($uid,$pid,$ppid,$c,$stime,$tty,$time,$cmd) = 
  split(/\s+/,$_,8);
  ### print Better $pid - $cmd\n;
  ### print \t$uid,$pid,$ppid,$c,$stime,$tty,$time,$cmd\n;
  ###
  ### }
  
  My Apology!
  
  ciao
  drieux
  
  ---
  
  
  -- 
  To unsubscribe, e-mail: [EMAIL PROTECTED]
  For additional commands, e-mail: [EMAIL PROTECTED] 
http://learn.perl.org/ http://learn.perl.org/first-response


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




Re: RE : RE : Regular expressions

2003-12-17 Thread drieux
On Dec 17, 2003, at 10:40 AM, Wiggins d Anconia wrote:
[..]
Ah!  And now we have come full circle back to Why you should use a
module to handle this type of code rather than re-inventing the 
wheel!
[..]

technically I agree with you. In terms of code re-use
and code maintainability. So it sorta depends upon
what the 'real goal' is all about...
There is also the minor point,
that some times doing silly things that
are better covered in an already established
module will help folks 'get it' about what
they are doing and how they can do things.
In this case steve Thought that his problem
was with his lack of knowledge about 'regular expression'
and how to do that. When his issue was with how to
effectively use split() - one of the variants that
he could have used of course would have been
	my ($uid,$pid,$ppid,$c,$stime,$tty,$time,$cmd,@args) = split;

But that would have meant dealing with @args problem
where he needed to find TWO things in an array in a
given order, rather than merely regExing a longer scalar.


ciao
drieux
---

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



RE : RE : RE : Regular expressions

2003-12-17 Thread Hemond, Steve

drieux is right about me being exploring Perl. In fact, that is a good exercice to 
play with regular expressions and data types as I had to build a hash of hashes to do 
the thing.

However, I wouldn't let a script in that stat if I knew of a better/quicker/shorter 
method.

I will then have to improve my script soon.

What would be the best way to put values returned by the ps command you just 
mentionned in variables?

Thanks again for your great help. 

P.S : I look like the typical lazy guy who don`t even read and try by himself. This is 
because I am at work, and overloaded with other things, and as you know bosses, I made 
the mistake to tell him that I would do that little thing in Perl, he know thinks that 
I am a Perl guru! I've started reading a Perl5 book by the evenings, so, I do my 
homework in some way :-)

I appreciate your help. Thanks again,

Best regards,

Steve Hemond
Programmeur Analyste / Analyst Programmer
Smurfit-Stone, Ressources Forestières
La Tuque, P.Q.
Tel.: (819) 676-8100 X2833
[EMAIL PROTECTED] 



  -Original Message-
  From: drieux [mailto:[EMAIL PROTECTED] 
  Sent: Wednesday, December 17, 2003 2:04 PM
  To: Perl Perl
  Subject: Re: RE : RE : Regular expressions
  
  
  
  On Dec 17, 2003, at 10:40 AM, Wiggins d Anconia wrote:
  [..]
   Ah!  And now we have come full circle back to Why you 
  should use a 
   module to handle this type of code rather than re-inventing the 
   wheel!
  [..]
  
  technically I agree with you. In terms of code re-use
  and code maintainability. So it sorta depends upon
  what the 'real goal' is all about...
  
  There is also the minor point,
  that some times doing silly things that
  are better covered in an already established
  module will help folks 'get it' about what
  they are doing and how they can do things.
  
  In this case steve Thought that his problem
  was with his lack of knowledge about 'regular expression'
  and how to do that. When his issue was with how to
  effectively use split() - one of the variants that
  he could have used of course would have been
  
   my ($uid,$pid,$ppid,$c,$stime,$tty,$time,$cmd,@args) = split;
  
  But that would have meant dealing with @args problem
  where he needed to find TWO things in an array in a
  given order, rather than merely regExing a longer scalar.
  
  
  
  ciao
  drieux
  
  ---
  
  
  -- 
  To unsubscribe, e-mail: [EMAIL PROTECTED]
  For additional commands, e-mail: [EMAIL PROTECTED] 
http://learn.perl.org/ http://learn.perl.org/first-response


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




Re: RE : RE : Regular expressions

2003-12-17 Thread John W. Krahn
Steve Hemond wrote:
 
 I think I begin to understand...
 
 I begin by fetching the results of the ps -efA command and split it
 into many variables ($uid, $pid, etc.)
 
 open(PS, ps -efA|);

You should _ALWAYS_ verify that the file opened correctly!


 while (PS) {
 ($uid,$pid,$ppid,$c,$stime,$tty,$time,$cmd) = split;

Ah yes, more fun with split.  :-)   Your line above is interpreted by perl as:

($uid,$pid,$ppid,$c,$stime,$tty,$time,$cmd) = split ' ', $_, 9;

Where the ninth field is discarded.  You want to tell split that you want exactly 
eight fields.

($uid,$pid,$ppid,$c,$stime,$tty,$time,$cmd) = split ' ', $_, 8;

You are also going to have to use chomp because $cmd will have a trailing newline.

chomp;
($uid,$pid,$ppid,$c,$stime,$tty,$time,$cmd) = split ' ', $_, 8;


 if ($cmd =~ /dispatch genie/)  {
 $infos{$pid}{'uid'}   = $uid;
 $infos{$pid}{'ppid'}  = $ppid;
 $infos{$pid}{'c'} = $c;
 $infos{$pid}{'stime'} = $stime;
 $infos{$pid}{'tty'}   = $tty;
 $infos{$pid}{'time'}  = $time;
 $infos{$pid}{'cmd'}   = $cmd;


open PS, 'ps -efA |' or die Cannot open pipe from ps: $!;
while ( PS ) {
next unless /dispatch genie/;
chomp;
my ( $uid, $pid, $ppid, $c, $stime, $tty, $time, $cmd ) =
split ' ', $_, 8;
@{ $infos{ $pid } }{ qw/ uid ppid c stime tty time cmd / } =
( $uid, $ppid, $c, $stime, $tty, $time, $cmd );
}
close PS or die Cannot close pipe from ps: $!;



John
-- 
use Perl;
program
fulfillment

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