RE: Regex question

2003-01-29 Thread Olivier . Gerault
You can do something like :

$out =~ m/(^.*Name\:.*$)/xo  $name = $1;

or

if ($out =~ m/Name\:/xo)
{
  $name = $out;
}

---

Legendo metulas imitabere cancrum

Olivier GĂ©rault


___
ActivePerl mailing list
[EMAIL PROTECTED]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs



Re: Regex question

2003-01-29 Thread Andy_Bach
You don't need the 'x' option (white space used in RE for comments) or the 
'o' option (compile it - this is used when there is a variable in the RE, 
e.g.
$name = Name:
while () {
   if ( /$name/o ) {

the colon (:) is not a special char and does not need an escape slash.

The '1' you get now is the number of matches, you need to have caputuring 
parens to get a return here:
($name) = $out =~ m/Name\:/xo ;
($name) = $out =~ /Name:\s+(.*)/;

A standard way to do this:
open(CMD,c:/tmp/test.cmd /i $c |)
   or die can't run cmd: $!
while (CMD) {
   if ( /Computer Name:/ ) {
  print;
   } elsif ( /User Name:/ ) {
  print;
   }
}   # while CMD
close CMD;

Note, now that you have this processing it line by line, you can do:
   if ( /Computer Name:\s+(.*)/ {
   my $computer = $1;
   print The computer is called $computer\n;
   }

That is, you can capture and work w/ the data in your script before 
outputting it.



Andy Bach, Sys. Mangler
Internet: [EMAIL PROTECTED] 
VOICE: (608) 261-5738  FAX 264-5030

 ... even if you're mediocre/decent at perl [the cmecf] code is pretty 
confusing in certain areas ... CB
___
ActivePerl mailing list
[EMAIL PROTECTED]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs



RE: Daemon example

2003-01-29 Thread FARRINGTON, RYAN
Title: RE: Daemon example





win32::daemon::simple required you to be able to use win32::daemon as well... daemon has to be installed as a package =(

-Original Message-
From: Jenda Krynicky [mailto:[EMAIL PROTECTED]]
Sent: Wednesday, January 29, 2003 10:25 AM
To: FARRINGTON, RYAN
Cc: [EMAIL PROTECTED]
Subject: RE: Daemon example



From: FARRINGTON, RYAN [EMAIL PROTECTED]
 here is what I get when I try to install the win32::daemon on 5.8
 
 Error installing package
 'http://www.roth.net/perl/packages/win32-daemon.ppd': R
 ead a PPD for 'http://www.roth.net/perl/packages/win32-daemon.ppd',
 but it is no t intended for this build of Perl
 (MSWin32-x86-multi-thread-5.8)


I said:

 I'm using it (though via Win32::Daemon::Simple) with 5.8 (build 804)
 with no problems. You can install it with PPM from
 http://Jenda.Krynicky.cz/perl


Try


ppm install http://Jenda.Krynicky.cz/perl/Win32-Daemon.ppd


Jenda
= [EMAIL PROTECTED] === http://Jenda.Krynicky.cz =
When it comes to wine, women and song, wizards are allowed 
to get drunk and croon as much as they like.
 -- Terry Pratchett in Sourcery





RE: Daemon example

2003-01-29 Thread Jenda Krynicky
From:   FARRINGTON, RYAN [EMAIL PROTECTED]
 win32::daemon::simple required you to be able to use win32::daemon as
 well... daemon has to be installed as a package =(

Oh well ... I did NOT ask you to install Win32::Daemon::Simple !

What do you get if you run

ppm install http://Jenda.Krynicky.cz/perl/Win32-Daemon.ppd

?

Jenda

= [EMAIL PROTECTED] === http://Jenda.Krynicky.cz =
When it comes to wine, women and song, wizards are allowed 
to get drunk and croon as much as they like.
-- Terry Pratchett in Sourcery

___
ActivePerl mailing list
[EMAIL PROTECTED]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs



RE: capturing output of command

2003-01-29 Thread Ekbert Mertens
But does someone have a proposal how to capture the STDERR output of the
batch script, too?
Up to now, I only could capture the STDOUT output via 
   @Result=`command line`
and I would like to capture both, ideally in the same array to get the
correct order...

Kind regards 
Ekbert Mertens


  Hi List,
 
  I have a script which is running another batch script on a 
 NT machine.
  During the perl script execution, I am not seeing the 
 output of the dos
  batch script on the screen. Some how its getting lost. Any 
 Idea as how can
 I
  change my script to display the dos script output as well??
 
  The requirement is to get the details such as hostname and 
 NT user login
 by
  the ip and update a database. Is there any perl modules 
 available to that.
 I
  always have the IP and would like to know what's the 
 hostname and the NT
  user logged in to that host.
 
  The script is as below
 
  #!/usr/local/ActivePerl-5.6/bin/perl
  use Sybase::CTlib;
 
 
  $dbh = Sybase::CTlib-ct_connect('user','pwd','server');
  if($dbh eq undef)
  {
  print Connection Failed to Server\n;
  }
  else
  {
  print Connection OK to Server\n;
  $sql = select ipaddr from db..Logins where loggedindatetime =
  dateadd(hour,-1,getdate());
  $data = $dbh-ct_sql($sql);
  foreach $r (@$data)
  {
  foreach $c (@$r)
  {
  print $c \t;
  `c:/tmp/test.cmd /i $c`;
  }
  print \n;
  }
  }
 
 Try capturing the results of the command. Add this line after the use
 statement:
 
 my @Results = ();
 
 The change your:
 
 `c:/tmp/test.cmd /i $c`;
 
 To:
 
 @Results = `c:/tmp/test.cmd /i $c`;
 
 Then you can access and parse the results contained in the array.
 
 Dirk Bremer - Systems Programmer II - ESS/AMS  - NISC St. Peters
 USA Central Time Zone
 636-922-9158 ext. 8652 fax 636-447-4471
 
 [EMAIL PROTECTED]
 www.nisc.cc
 
 ___
 ActivePerl mailing list
 [EMAIL PROTECTED]
 To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
 
___
ActivePerl mailing list
[EMAIL PROTECTED]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs



RE: Regex question

2003-01-29 Thread Arms, Mike
It's a bit hard to understand your real question. But here's
a go at it anyway.

If you want to grab the whole lines that have Name: in it:

  # Note the use of an array here.
  @out = `c:/tmp/test.cmd /i $c`;
  @names = grep( /Name:/, @out );
  print for @names;

If you want to get the names and values into a hash:

  # Note the use of an array here.
  @out = `c:/tmp/test.cmd /i $c`;
  for ( @out ) {
$names{$1} = $2 if /(.*)\s+Name:\s*(.*)\s*/;
  }
  print $_ = $names{$_}\n for keys %names;

Or you could do something with each line that had Name: in it:

  # Note the use of an array here.
  @out = `c:/tmp/test.cmd /i $c`;
  for ( @out ) {
if ( ($key, $name) = /(.*)\s+Name:\s*(.*)\s*/ ) {
  print $key : $name\n;
}
  }

--
Mike Arms


 -Original Message-
 From: Sabherwal, Balvinder (MBS)
 [mailto:[EMAIL PROTECTED]]
 Sent: Wednesday, January 29, 2003 9:22 AM
 To: [EMAIL PROTECTED]
 Subject: Regex question
 
 
 List,
 
 I need your help with the regex in my script.
 
 $out = `c:/tmp/test.cmd /i $c`;
 
 The above line gets the result in the variable and I'm trying 
 to match a
 pattern as below and I want to store the lines in another 
 variable if the
 matching pattern is found.
 
 ($name) = $out =~ m/Name\:/xo ;
 
 
 The value I get in $name is 1. Question is how do I get the 
 lines from the
 $out into $name?? $out is a multiline output. The sample out 
 put is as below
 
 Successful purge and preload of the NBT Remote Cache Name Table.
 
 User Information:
 -
 User Name: PINTOA
 
 Computer Information:
 -
 Computer Name: W-DEV-2103C
 IP Address: 10.90.78.7
 MAC Address: 00-C0-4F-47-64-85
 
 
 From the above output I need to strip out the below lines 
 into the $name.
 
 User Name: PINTOA
 Computer Name: W-DEV-2103C
 
 Thanks for your help in advance.
 ___
 ActivePerl mailing list
 [EMAIL PROTECTED]
 To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
 

___
ActivePerl mailing list
[EMAIL PROTECTED]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs



RE: capturing output of command

2003-01-29 Thread chengkai


 But does someone have a proposal how to capture the STDERR 
 output of the batch script, too? Up to now, I only could 
 capture the STDOUT output via 
@Result=`command line`
 and I would like to capture both, ideally in the same array 
 to get the correct order...
 
 Kind regards 
 Ekbert Mertens
 

   To capture the STDERR, do

 @result = `command line 21`;

   This will make the STDERR redirect to the STDOUT ...

~Mike L.

___
ActivePerl mailing list
[EMAIL PROTECTED]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs



RE: Daemon example

2003-01-29 Thread FARRINGTON, RYAN
Title: RE: Daemon example





ARG!!! WTF... why does that work and installing it from www.roth.net doesn't =(


-Original Message-
From: Jenda Krynicky [mailto:[EMAIL PROTECTED]]
Sent: Wednesday, January 29, 2003 11:00 AM
To: [EMAIL PROTECTED]
Subject: RE: Daemon example



From:  FARRINGTON, RYAN [EMAIL PROTECTED]
 win32::daemon::simple required you to be able to use win32::daemon as
 well... daemon has to be installed as a package =(


Oh well ... I did NOT ask you to install Win32::Daemon::Simple !


What do you get if you run


 ppm install http://Jenda.Krynicky.cz/perl/Win32-Daemon.ppd


?


Jenda


= [EMAIL PROTECTED] === http://Jenda.Krynicky.cz =
When it comes to wine, women and song, wizards are allowed 
to get drunk and croon as much as they like.
 -- Terry Pratchett in Sourcery


___
ActivePerl mailing list
[EMAIL PROTECTED]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs





RE: Daemon example

2003-01-29 Thread FARRINGTON, RYAN
Title: RE: Daemon example





now I get:


Can't locate loadable object for module Win32::Daemon in @INC (@INC contains: d:
/perl/lib d:/perl/site/lib .) at xml_service.pl line 13





ARG... oh well... I'll work it off 5.6 and forget the threading stuff I'm trying to learn =)
-Original Message-
From: Jenda Krynicky [mailto:[EMAIL PROTECTED]]
Sent: Wednesday, January 29, 2003 11:00 AM
To: [EMAIL PROTECTED]
Subject: RE: Daemon example



From:  FARRINGTON, RYAN [EMAIL PROTECTED]
 win32::daemon::simple required you to be able to use win32::daemon as
 well... daemon has to be installed as a package =(


Oh well ... I did NOT ask you to install Win32::Daemon::Simple !


What do you get if you run


 ppm install http://Jenda.Krynicky.cz/perl/Win32-Daemon.ppd


?


Jenda


= [EMAIL PROTECTED] === http://Jenda.Krynicky.cz =
When it comes to wine, women and song, wizards are allowed 
to get drunk and croon as much as they like.
 -- Terry Pratchett in Sourcery


___
ActivePerl mailing list
[EMAIL PROTECTED]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs





RE: Daemon example

2003-01-29 Thread Jenda Krynicky
From: FARRINGTON, RYAN [EMAIL PROTECTED]
 ARG!!! WTF... why does that work and installing it from www.roth.net
 doesn't =(

Because Dave did not compile the module for Perl 5.8 yet. I compiled 
the module myself. I did send him the DLL and the files I changed so 
I think he will add the 5.8 version to his repository soon as well.

Jenda

= [EMAIL PROTECTED] === http://Jenda.Krynicky.cz =
When it comes to wine, women and song, wizards are allowed 
to get drunk and croon as much as they like.
-- Terry Pratchett in Sourcery

___
ActivePerl mailing list
[EMAIL PROTECTED]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs



Date Conversion in Perl

2003-01-29 Thread Kenneth Jideofor \[ MTN - Ikoyi \]
Hi,

Given a number of days, it is expected to determine the real date from Jan
1, 1970.
The real date should be in the following format: Year-Month-Day.

How do I implement this task using Perl.

For example, write a Perl script to convert 12016 days to its real date from
Jan 1, 1970.

Regards,
Ken

___
ActivePerl mailing list
[EMAIL PROTECTED]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs



Re: Date Conversion in Perl

2003-01-29 Thread Mark Morgan

 perl -e '$days=12016; $seconds=$days*86400; print localtime($seconds) . \n'
Sun Nov 24 16:00:00 2002

HTH,
 - Mark

On Wed, 29 Jan 2003, Kenneth Jideofor [ MTN - Ikoyi ] wrote:

 Date: Wed, 29 Jan 2003 19:57:10 +0100
 From: Kenneth Jideofor [ MTN - Ikoyi ] [EMAIL PROTECTED]
 To: [EMAIL PROTECTED]
 Subject: Date Conversion in Perl

 Hi,

 Given a number of days, it is expected to determine the real date from Jan
 1, 1970.
 The real date should be in the following format: Year-Month-Day.

 How do I implement this task using Perl.

 For example, write a Perl script to convert 12016 days to its real date from
 Jan 1, 1970.

 Regards,
 Ken

 ___
 ActivePerl mailing list
 [EMAIL PROTECTED]
 To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

___
ActivePerl mailing list
[EMAIL PROTECTED]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs



RE: Date Conversion in Perl

2003-01-29 Thread brianr
Kenneth Jideofor \[ MTN - Ikoyi \] writes:
  Hi,
  
  Given a number of days, it is expected to determine the real date from Jan
  1, 1970.
  The real date should be in the following format: Year-Month-Day.
  
  How do I implement this task using Perl.
  
  For example, write a Perl script to convert 12016 days to its real date from
  Jan 1, 1970.

My first suggestion would be to install the Date::Calc module and read
the documentation.

Alternatively, a quick and dirty solution is:

perl -MPOSIX=strftime -e print strftime('%Y-%m-%d', localtime(12016*60*60*24))

This question sounds a bit like homework. Is it?

HTH

-- 
Brian Raven
Magically turning people's old scalar contexts into list contexts is a
recipe for several kinds of disaster.
 -- Larry Wall in [EMAIL PROTECTED]


---
The information contained in this e-mail is confidential and solely 
for the intended addressee(s). Unauthorised reproduction, disclosure, 
modification, and/or distribution of this email may be unlawful. If you 
have received this email in error, please notify the sender immediately 
and delete it from your system. The views expressed in this message 
do not necessarily reflect those of 
LIFFE Holdings Plc or any of its subsidiary companies.
---

___
ActivePerl mailing list
[EMAIL PROTECTED]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs



File Formatting in Perl

2003-01-29 Thread Kenneth Jideofor \[ MTN - Ikoyi \]
Hi all,

I have file whose content is arranged in rows of two lines, each row-pair
separated from the next by a line-space.
I want to rearrange the file in a two-column format such that all the
entries in the first rows in a pair are put in the first column while their
corresponding second rows are put in the second column.

For instance,

Given the content of a file as:










I want it rearranged in the following format using Perl:





I look forward to your assistance.

Regards,
Ken

 
___
ActivePerl mailing list
[EMAIL PROTECTED]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs



Re: File Formatting in Perl

2003-01-29 Thread Terry L Fritts
Hello Kenneth,

Wednesday, January 29, 2003 you wrote:
KJM Given the content of a file as:
KJM 
KJM 

KJM 
KJM 

KJM 
KJM 

KJM I want it rearranged in the following format using Perl:
KJM 
KJM 
KJM 

one way:
open(FIN, $fpin) or die no file;
my @FIN = FIN;
close(FIN);
my $str = join(x, @FIN);
$str =~ s/\nx\nx/\n/g;
$str =~ s/\nx/\t/g;
open(FOUT, $fpout);
print FOUT $str;
close(FOUT);
exit;

___
ActivePerl mailing list
[EMAIL PROTECTED]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs



Re: File Formatting in Perl

2003-01-29 Thread Andy_Bach
my $cnt = 1;
while (DATA) {
  next unless  /\w/;
  s/\n/\t\t/ if ($cnt++ % 2);
  print;
}
__DATA__









More homework?

a

Andy Bach, Sys. Mangler
Internet: [EMAIL PROTECTED] 
VOICE: (608) 261-5738  FAX 264-5030

 ... even if you're mediocre/decent at perl [the cmecf] code is pretty 
confusing in certain areas ... CB
___
ActivePerl mailing list
[EMAIL PROTECTED]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs