Re: Running a Perl program countinuously

2002-11-18 Thread Mat Harris
if you have root access you could run it in inittab

On Sun, Nov 17, 2002 at 06:05:43 +0200, Octavian Rasnita wrote:
 Hi all,
 
 I want to make a Perl program that runs permanently without stopping.
 How can I do this?
 
 I could run the program from shell using:
 
 nohup perl script.pl 
 
 . but if for some unknown reasons the process will be stopped, it won't
 restart automaticly.
 
 How can I make it to start automaticly after stopping?
 
 If I will use a cron job, how can I verify if the process is running, to
 decide if I need to start it or not on ... lets say each hour?
 
 Thank you.
 
 
 Teddy,
 Teddy's Center: http://teddy.fcc.ro/
 Email: [EMAIL PROTECTED]
 
 
 
 -- 
 To unsubscribe, e-mail: [EMAIL PROTECTED]
 For additional commands, e-mail: [EMAIL PROTECTED]

-- 
Mat Harris  OpenGPG Public Key ID: C37D57D9
[EMAIL PROTECTED]matthewh.genestate.com  



msg06906/pgp0.pgp
Description: PGP signature


Re: Running a Perl program countinuously

2002-11-18 Thread Christopher G Tantalo
Octavian Rasnita wrote:

 Hi all,

 I want to make a Perl program that runs permanently without stopping.
 How can I do this?

 I could run the program from shell using:

 nohup perl script.pl 

 . but if for some unknown reasons the process will be stopped, it won't
 restart automaticly.

 How can I make it to start automaticly after stopping?

 If I will use a cron job, how can I verify if the process is running, to
 decide if I need to start it or not on ... lets say each hour?

 Thank you.

 Teddy,

hmmm, you could have another script that checks to see if the process is
running, and if it is not, restart it.  You could stick this check program in a
cron to run every hour.  If someone has a different idea, I would also like to
know.  The above is what I do now.
chris
--
---
Just Your Friendly Neighborhood
_SPIDEY_



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


Re: Running a Perl program countinuously

2002-11-18 Thread J. Alejandro Ceballos Z.
Octavian Rasnita wrote:


Hi all,

I want to make a Perl program that runs permanently without stopping.
How can I do this?

 

via shell loop

while true
do
 the program
done



--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Re: Running a Perl program countinuously

2002-11-18 Thread Christopher G Tantalo
J. Alejandro Ceballos Z. wrote:

 Octavian Rasnita wrote:

 Hi all,
 
 I want to make a Perl program that runs permanently without stopping.
 How can I do this?
 
 
 
 via shell loop

 while true
 do
   the program
 done

that will spawn a new process off every iteration, which would be multiple
times per second.. I dont know if that is exactly what was asked for. And
quite possibly, would cause problems with the programs head budding each
other.
chris
--
---
Just Your Friendly Neighborhood
_SPIDEY_



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


Re: Running a Perl program countinuously

2002-11-18 Thread Octavian Rasnita
Yes I know this but if the root will restart the server, the program won't
restart.
Or, ... other problems might kill my program.

Teddy,
Teddy's Center: http://teddy.fcc.ro/
Email: [EMAIL PROTECTED]

- Original Message -
From: J. Alejandro Ceballos Z. [EMAIL PROTECTED]
To: beginners-cgi [EMAIL PROTECTED]
Sent: Monday, November 18, 2002 5:09 PM
Subject: Re: Running a Perl program countinuously


Octavian Rasnita wrote:

Hi all,

I want to make a Perl program that runs permanently without stopping.
How can I do this?



via shell loop

while true
do
  the program
done



--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Re: Running a Perl program countinuously

2002-11-18 Thread Octavian Rasnita
No, unfortunately I don't have root access.
Thank you for telling me about this option.

Teddy,
Teddy's Center: http://teddy.fcc.ro/
Email: [EMAIL PROTECTED]

- Original Message - 
From: Mat Harris [EMAIL PROTECTED]
To: Octavian Rasnita [EMAIL PROTECTED]
Cc: [EMAIL PROTECTED]
Sent: Monday, November 18, 2002 11:06 AM
Subject: Re: Running a Perl program countinuously





-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Re: Running a Perl program countinuously

2002-11-18 Thread Octavian Rasnita
Thank you.

Please tell me how can I verify if the process is running.


Teddy,
Teddy's Center: http://teddy.fcc.ro/
Email: [EMAIL PROTECTED]

- Original Message -
From: Christopher G Tantalo [EMAIL PROTECTED]
To: Octavian Rasnita [EMAIL PROTECTED]
Cc: [EMAIL PROTECTED]
Sent: Monday, November 18, 2002 2:44 PM
Subject: Re: Running a Perl program countinuously


Octavian Rasnita wrote:

 Hi all,

 I want to make a Perl program that runs permanently without stopping.
 How can I do this?

 I could run the program from shell using:

 nohup perl script.pl 

 . but if for some unknown reasons the process will be stopped, it
won't
 restart automaticly.

 How can I make it to start automaticly after stopping?

 If I will use a cron job, how can I verify if the process is running, to
 decide if I need to start it or not on ... lets say each hour?

 Thank you.

 Teddy,

hmmm, you could have another script that checks to see if the process is
running, and if it is not, restart it.  You could stick this check program
in a
cron to run every hour.  If someone has a different idea, I would also like
to
know.  The above is what I do now.
chris
--
---
Just Your Friendly Neighborhood
_SPIDEY_





-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Trouble with Term::Readkey

2002-11-18 Thread Tin-Shan Chau
I was trying to use the Term::ReadKey module as follows:


use Term::ReadKey;
ReadMode ('noecho');
$password = ReadLine(0);


but got the following:


Can't locate Configure.pm in @INC (@INC contains: n:\util\perl C:/perl/lib C:/pe
rl/site/lib .) at C:/perl/lib/Term/ReadKey.pm line 12.
BEGIN failed--compilation aborted at C:/perl/lib/Term/ReadKey.pm line 12.
Compilation failed in require at test.pl line 1.
BEGIN failed--compilation aborted at test.pl line 1.


The only configure.pm I could find was under c:\perl\site\lib\tk, but that was 
obviously not the one the module was looking for; as when I copied it to c:\perl\lib, 
I got even more error messages.

Also, I tried to upgrade Term::Readkey, but PPM said that it was already up-to-date.

Does anyone know what my problem might be?  Thanks.




RE: Trouble with Term::Readkey

2002-11-18 Thread Beau E. Cox
Hi -

I downloaded and compiled Term::ReadKey (perl makefile.pl,
nmake, nmake test, nmake install) on my win32
machine using ActivePerl 5.6.1 (633). No problems.

Configure.pm in INCLUDED with Term::ReadKey. Maybe the
PMD file (PPM) is incomplete. Do you have a compiler?
If so, try building it yourself instead of using PPM.

Aloha = Beau.

-Original Message-
From: Tin-Shan Chau [mailto:[EMAIL PROTECTED]]
Sent: Sunday, November 17, 2002 2:09 PM
To: Help on PERL
Subject: Trouble with Term::Readkey


I was trying to use the Term::ReadKey module as follows:


use Term::ReadKey;
ReadMode ('noecho');
$password = ReadLine(0);


but got the following:


Can't locate Configure.pm in @INC (@INC contains: n:\util\perl C:/perl/lib
C:/pe
rl/site/lib .) at C:/perl/lib/Term/ReadKey.pm line 12.
BEGIN failed--compilation aborted at C:/perl/lib/Term/ReadKey.pm line 12.
Compilation failed in require at test.pl line 1.
BEGIN failed--compilation aborted at test.pl line 1.


The only configure.pm I could find was under c:\perl\site\lib\tk, but that
was obviously not the one the module was looking for; as when I copied it to
c:\perl\lib, I got even more error messages.

Also, I tried to upgrade Term::Readkey, but PPM said that it was already
up-to-date.

Does anyone know what my problem might be?  Thanks.




-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




mail

2002-11-18 Thread Javeed SAR
Hi All,

i get mails  to a particular id in outlook.
In perl i want to know how to move this attachments to do a particular
activity is it possible.

Regards 
j





Re: Data Access

2002-11-18 Thread Tom Allison
Paul wrote:

--- Tom Allison [EMAIL PROTECTED] wrote:


My first guess is to use tie to access a file of type DB_File.
The number of records is small 1000 but the record structure is 
going to be either a hash of hashes, hash of arrays, or similar.


One possible solution depends on your data structure.
Frequently hashes of hashes are convenient, but can 
eat up a lot of memory and program speed when they
get large. On the other hand, if your keys allow it,
you can often compund the *keys* and end up with a 
single hash, which is easily storable via DBM. e.g.:


I thought I would fill you in on my adventures.

I was playing with DB_File to tie in DB_BTREE type data.

The DBTREE data storage, for what I am doing, was better than 5X 
faster then DB_HASH (default).  I'll stick with DBTREE for now.

I'm using tie-DB_BTREE to keep a list of email accounts for 
whitelisting  blacklisting of email.  I expect this to remain 
1,000 emails.  I'll probably add some kind of expiration method 
to kill entries that haven't been active for a while...

--
I'd just as soon kiss a Wookie.
		-- Princess Leia Organa


--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Problem with Mail::MboxParser

2002-11-18 Thread Nandita Shenvi

Hallo All,

I am new in perl and will be grarefull for any help.
my perl script is as follows:

#!/usr/bin/perl -w


use lib /home/shenvi/share/man/man3;


use IO;
use Mail::Internet;
use MIME::Tool;
use Mail::MboxParser::Mail;
use Mail::MboxParser;






#USE OF Mail::MboxParser

 my $mb =  Mail::MboxParser-new((\*STDIN), decode = 'HEADER');

for my $msg ($mb-get_message) {

  print $msg-header-{FROM}, \n;
  $msg-store_all_attachment('/home/shenvi/perl/tmp');

  }


when i try to run this scrpit  I keep on getting this error:
Error: The filename you passed to open() does not refer to an existing file
at Teststrip.PL line 31

in the above case line 31 is
my $mb =  Mail::MboxParser-new((\*STDIN), decode = 'HEADER');



thanks
nandita
Nandita Shenvi
Appartment Nr. 707
Westhoffstr. 15
44791 Bochum
Germany
0234/5844456



_
The new MSN 8: advanced junk mail protection and 2 months FREE* 
http://join.msn.com/?page=features/junkmail


--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Hi all, question about caracter detection

2002-11-18 Thread Miguel Angelo
Hi All,

Thankx for reading this.

I have a very newbie question...

i'm working on a CGI and i want only to permit some
caracters by the user...

imagine

my $STRING = kjsh234Sd\nki;

# now i want to check if there is any invalid caracter
# in this case a-z ; A-Z and 0-9

there for /[a-zA-Z0-9]/ but i am unable to find a
valid command for that, the \n always passes, i
definity do not want to use execption on what o do not
allow, i want only to allow some caracters
invalidating all others...

here what i have tried

if ( $STRING =~ /[a-zA-Z0-9]/ ) { etc }

my $count = ( $STRING =~ tr /a-zA-Z0-9// );

all failed...

please help me :)





=
*
* Miguel Angelo *
* E-mail: [EMAIL PROTECTED] *
* Domain: http://migas.mine.nu  *
*

__
Do You Yahoo!?
Everything you'll ever need on one web page
from News and Sport to Email and Music Charts
http://uk.my.yahoo.com

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




RE: Hi all, question about caracter detection

2002-11-18 Thread Beau E. Cox
Hi -

This will 'strip' all but a-zA-Z0-9:

#!/usr/bin/perl

use strict;
use warnings;

my $STRING = kjsh234Sd\nki;

$STRING =~ s/[^a-zA-Z0-9]//sg;

print $STRING\n;

the ~ makes the character class negative, the s makes
the regex examine new lines, and g means global.

Aloha - Beau.

-Original Message-
From: Miguel Angelo [mailto:[EMAIL PROTECTED]]
Sent: Monday, November 18, 2002 2:31 AM
To: [EMAIL PROTECTED]
Subject: Hi all, question about caracter detection


Hi All,

Thankx for reading this.

I have a very newbie question...

i'm working on a CGI and i want only to permit some
caracters by the user...

imagine

my $STRING = kjsh234Sd\nki;

# now i want to check if there is any invalid caracter
# in this case a-z ; A-Z and 0-9

there for /[a-zA-Z0-9]/ but i am unable to find a
valid command for that, the \n always passes, i
definity do not want to use execption on what o do not
allow, i want only to allow some caracters
invalidating all others...

here what i have tried

if ( $STRING =~ /[a-zA-Z0-9]/ ) { etc }

my $count = ( $STRING =~ tr /a-zA-Z0-9// );

all failed...

please help me :)





=
*
* Miguel Angelo *
* E-mail: [EMAIL PROTECTED] *
* Domain: http://migas.mine.nu  *
*

__
Do You Yahoo!?
Everything you'll ever need on one web page
from News and Sport to Email and Music Charts
http://uk.my.yahoo.com

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




RE: Hi all, question about caracter detection

2002-11-18 Thread Sudarshan Raghavan
On Mon, 18 Nov 2002, Beau E. Cox wrote:

 Hi -
 
 This will 'strip' all but a-zA-Z0-9:
 
 #!/usr/bin/perl
 
 use strict;
 use warnings;
 
   my $STRING = kjsh234Sd\nki;
 
   $STRING =~ s/[^a-zA-Z0-9]//sg;
 
   print $STRING\n;
 
 the ~ makes the character class negative, 

I guess you meant ^, not ~

 the s makes
 the regex examine new lines, and g means global.

You need an /s when you want . to match newlines (which it
normally doesn't). In this case since you are not using a
.., /s is not needed.

$STRING =~ s/[^a-zA-Z0-9]//g;
The above will work just fine

You can also use tr/// for this
$STRING =~ tr/a-zA-Z0-9//cd;

If the OP just wants to check not replace either of these should
do
unless ($STRING =~ m/[^a-zA-Z0-9]/) {
   # Valid STRING
}

or 

unless ($STRING =~ tr/a-zA-Z0-9//c) {
   # Valid STRING
}




-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




can't load XML::Parser::PerlSAX

2002-11-18 Thread Sorin Marti
Hi all

I downloaded the XML Parser 2.31 from CPAN and installed it.

Now I want to install  XML-DOM-1.41 but I get following error

Warning: prerequisite XML::Parser::PerlSAX failed to load: Can't locate 
XML/Parser/PerlSAX.pm

Do I have to install something else before XML-DOM? Is PerlSAX not in 
the XML Parser 2.31 package?

thanks for every advice...

Sorin






--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



RE: can't load XML::Parser::PerlSAX

2002-11-18 Thread Beau E. Cox
Hi -

If you go to Randy Kobes search site on cpan.org, you will
see the following in XLM::DOM-1.14:

Download / quickinstall XML-DOM-1.41.tar.gz : A perl module for building DOM
Level 1 compliant document structures
 Size: 116.288 kB Last modified: Oct 19, 2002
 README CPAN-testers results for XML-DOM
Author: T.J. Mather
 CPAN id: T/TJ/TJMATHER
 email: [EMAIL PROTECTED]
 Home page: http://maxmind.com/
Requires:
 ExtUtils::MakeMaker : create an extension Makefile...
 LWP::UserAgent : A WWW UserAgent class [in the libwww-perl-5.65
distribution]
 XML::Parser : A perl module for parsing XML documents [in the
XML-Parser-2.31 distribution]
 XML::Parser::PerlSAX : Perl SAX parser using XML::Parser [in the
libxml-perl-0.07 distribution]
 XML::RegExp : Regular expressions for XML tokens [in the XML-RegExp-0.03
distribution]

You must install any modules in the 'Requires:' section.

The easy way is to use cpan's CPAN module - it will automatically
download/make/test/install modules for you - INCLUDING modules
required by the one you want. Check it out!

Aloha = Beau.

-Original Message-
From: Sorin Marti [mailto:[EMAIL PROTECTED]]
Sent: Monday, November 18, 2002 3:33 AM
To: [EMAIL PROTECTED]
Subject: can't load XML::Parser::PerlSAX


Hi all

I downloaded the XML Parser 2.31 from CPAN and installed it.

Now I want to install  XML-DOM-1.41 but I get following error

Warning: prerequisite XML::Parser::PerlSAX failed to load: Can't locate
XML/Parser/PerlSAX.pm

Do I have to install something else before XML-DOM? Is PerlSAX not in
the XML Parser 2.31 package?

thanks for every advice...

Sorin






--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




sorting Numeric OR Character data

2002-11-18 Thread Balint, Jess
Hello all. I have a small subfunction with a for sort keys %hash construct
in it. In my sort, I want to have { $a = $b } (numberic) sorting, but I
get errors when character data is entered. Is there anyway to tell numberic
vs character without looping through keys looking for m/\D/? Thanks.

jess

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Re: Problem with Mail::MboxParser

2002-11-18 Thread Jan Gruber
Hi !

 in the above case line 31 is
 my $mb =  Mail::MboxParser-new((\*STDIN), decode = 'HEADER');

my $mb = Mail::MboxParser-new(\*STDIN, decode = 'HEADER');

should work fine (untested).

HTH,
Jan
-- 
cat /dev/world | perl -e while () {(/(^.*? \?) 42 \!/)  (print $1)}
errors-(c)
- 

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Re: hash

2002-11-18 Thread Jeff 'japhy' Pinyan
On Nov 10, SATAR VAFAPOOR said:

When I run the following code(with any hash), I get a contiuous stream of
output. The presence of the array in the loop causes the contiuous stream
of output. When the array is commented out an output is generated. Why
does the presence of the array cause a contiuous stream of output. Thanks

while (($k,$v)= each %ENV)
{
  @ks=keys %ENV;
  print $k $v\n;
}

First of all, there's no need to build a list of the keys in the hash IN
EACH ITERATION.  You're better off doing:

  my @keys = keys %ENV;
  while (($k,$v) = each %ENV) { ... }

I'm also not sure why you're using each() if you're going to store the
keys in an array.

But your PRIMARY problem is stated in the documentation of keys() and
each().  From perldoc -f keys:

  As a side effect, it resets HASH's iterator.

and from perldoc -f each:

  that will start iterating again.  There is a single iterator
  for each hash, shared by all each, keys, and values func-
  tion calls in the program; it can be reset by reading all the
  elements from the hash, or by evaluating keys HASH or values
  HASH.

-- 
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]




System/Exec/Fork ... Help!

2002-11-18 Thread Jason Frisvold
I'm writing a monitoring system (Yes, still...  Finally got the go-ahead
to do this) and my design calls for a central Smart Daemon that spawns
and monitors the lesser Daemons that do the actual monitoring.  My
problem is that I'm not sure how to go about this.

From what I understand, fork actually creates a duplicate (clone) of the
current program and runs it.  Based on the pid, you can determine if
you're the parent or the child.  I may be able to use this, but it won't
allow me to spawn the seperate processes that need to run.

System spawns the process but blocks and waits for a return?  Great, but
I need to spawn, get the pid, and monitor on my own and not via a system
call...

Exec spawns and runs this new program, forgetting the old one...  In
essence, the old one ceases to run ...  (I think ... feel free to
correct me)

I can't see to figure out how to spawn a new process, return the pid,
and be able to monitor this new process on my own ...

Any ideas?

Thanks,

-- 
---
Jason H. Frisvold
Senior ATM Engineer
Penteledata Engineering
[EMAIL PROTECTED]
RedHat Certified - RHCE # 807302349405893
---
Something mysterious is formed, born in the silent void. Waiting alone
and unmoving, it is at once still and yet in constant motion. It is the
source of all programs. I do not know its name, so I will call it the
Tao of Programming.

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




RE: sorting Numeric OR Character data

2002-11-18 Thread Wagner, David --- Senior Programmer Analyst --- WGO
Maybe one of the higher gurus might know of something, but if the
data can be interweaved(ie, the key can be 1, 2, 3 and ab, dc, ed), then
without looking at the data first or keeping some kind of counter, it would
be from my perspective rough to do.

Wags ;)

-Original Message-
From: Balint, Jess [mailto:[EMAIL PROTECTED]]
Sent: Monday, November 18, 2002 12:38
To: 'Wagner, David --- Senior Programmer Analyst --- WGO'
Cc: '[EMAIL PROTECTED]'
Subject: RE: sorting Numeric OR Character data


 If you want to see the data, then you would need to explain 
 what you want.
 

Sorry if I was not clear. I would like to know if there is a block
equivalent to { $a = $b } AND { $a cmp $b } at the same time. If I use the
cmp style, my numbers get sort asciibetically and if I use the = I can use
characters.

Since the sort is inside of a subroutine, I need to be able to use both
types of data.

Thanks.

jess


**
This message contains information that is confidential
and proprietary to FedEx Freight or its affiliates.
It is intended only for the recipient named and for
the express purpose(s) described therein.
Any other use is prohibited.



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Re: Use of Search::Dict

2002-11-18 Thread Peter Scott
In article 000f01c28d8e$ed4e4f80$[EMAIL PROTECTED],
 [EMAIL PROTECTED] (Tin-Shan Chau) writes:
--Boundary_(ID_G2riuUEo9lO985lfAtLnbg)
Content-type: text/plain; charset=iso-8859-1
Content-transfer-encoding: 7BIT

Can anyone point me to an example of how to use the above module? 

use Search::Dict;
open my $fh, /usr/dict/words or die $!;
my $lookfor = shift;
look $fh, $lookfor;
print Found:  . $fh;
close $fh;

% ./example perl
Found: permalloy

Some of my questions are:

1. How should the input file be opened (as a text file or binary)?

Text.

2. Do all lines have to have the same length?

No.

3. Once I get the return line position (if I get that far), how do I retrieve the 
line?

FILEHANDLE

-- 
Peter Scott
http://www.perldebugged.com

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Flatfile database sorting in Perl

2002-11-18 Thread Gavin Laking
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

Hi folks,

One of my scripts uses a home-brewed flatfile database to store
information, and I've run up against a problem when I wish to sort
columns of data.

An example of the database file:
(items,fruit,date)

16,apples,20021118-1725
22,bananas,20021118-1648
4,grapes,20021118-1921

To open and place the items into an array, I do this (formatted so that
some mail client doesn't make it *really* unreadable :-P ) :

open ('FILE',$databaseFile) || die;
@dbfile = FILE;
for ($a = 0; $a  @dbfile; $a++) {(
$items[$a],
$fruit[$a],
$date[$a],
$chop)=split(/,/,$dbfile[$a]);}

With a little pretty printing can show us the database in 3D. I'm not
going to include the code for pretty printing here as it is unimportant,
but the output I think is:

[0]16,[0]apples,[0]20021118-1725
[1]22,[1]bananas,[1]20021118-1648
[2]4,[2]grapes,[2]20021118-1921

Now my problem is that I can sort the database by 'items', both
ascending and descending order:

(ascending)
@dboutfile = sort {($a =~ /(\d+)/)[0] = ($b =~ /(\d+)/)[0]} @dbfile;

(descending)
@dboutfile = sort {($b =~ /(\d+)/)[0] = ($a =~ /(\d+)/)[0]} @dbfile;

But I can't seem to sort the database by any of the other fields. I've
tried incrementing the '0's and changing '\d+' to '\w+' but I can't get
it into reverse alphabetical or chronological order or any other sort
type other than ascending or descending 'items' order.

Does anybody know what I'm waffling about, and can solve this problem,
or am I really blessed with programmers illiteracy? Thanks all,

GL

- -- 
Gavin Laking - Web Development Daemon

http://www.gavinlaking.co.uk
- --
-BEGIN PGP SIGNATURE-
Version: GnuPG v1.0.6 (GNU/Linux)

iD8DBQE92WE1aMak7Ylvm3ARAu7NAKDusbcH57Uw0QfN8mdECRwMaAFXrACbBkPv
w1FOeSr0d4tGI+tB68DY/Ic=
=V5tW
-END PGP SIGNATURE-

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Re: Flatfile database sorting in Perl

2002-11-18 Thread John W. Krahn
Gavin Laking wrote:
 
 One of my scripts uses a home-brewed flatfile database to store
 information, and I've run up against a problem when I wish to sort
 columns of data.
 
 An example of the database file:
 (items,fruit,date)
 
 16,apples,20021118-1725
 22,bananas,20021118-1648
 4,grapes,20021118-1921
 
 To open and place the items into an array, I do this (formatted so that
 some mail client doesn't make it *really* unreadable :-P ) :
 
 open ('FILE',$databaseFile) || die;
 @dbfile = FILE;
 for ($a = 0; $a  @dbfile; $a++) {(
 $items[$a],
 $fruit[$a],
 $date[$a],
 $chop)=split(/,/,$dbfile[$a]);}
 
 With a little pretty printing can show us the database in 3D. I'm not
 going to include the code for pretty printing here as it is unimportant,
 but the output I think is:
 
 [0]16,[0]apples,[0]20021118-1725
 [1]22,[1]bananas,[1]20021118-1648
 [2]4,[2]grapes,[2]20021118-1921
 
 Now my problem is that I can sort the database by 'items', both
 ascending and descending order:
 
 (ascending)
 @dboutfile = sort {($a =~ /(\d+)/)[0] = ($b =~ /(\d+)/)[0]} @dbfile;
 
 (descending)
 @dboutfile = sort {($b =~ /(\d+)/)[0] = ($a =~ /(\d+)/)[0]} @dbfile;
 
 But I can't seem to sort the database by any of the other fields. I've
 tried incrementing the '0's and changing '\d+' to '\w+' but I can't get
 it into reverse alphabetical or chronological order or any other sort
 type other than ascending or descending 'items' order.
 
 Does anybody know what I'm waffling about, and can solve this problem,
 or am I really blessed with programmers illiteracy? Thanks all,


You can make it a bit simpler if you use an array of arrays.

open( FILE, $databaseFile ) || die Cannot open $databaseFile: $!;
my @dbfile;
while ( FILE ) {
chomp;
push @dbfile, [ split /,/ ];
}

# Sort by item (ascending)
my @dboutfile = sort { $a-[0] = $b-[0] } @dbfile;

# Sort by fruit (descending)
my @dboutfile = sort { $b-[1] cmp $a-[1] } @dbfile;

# Sort by date (descending) then by item (ascending) then by fruit
(ascending)

my @dboutfile = sort { $b-[2] cmp $a-[2] or
   $a-[0] = $b-[0] or
   $a-[1] cmp $b-[1]   } @dbfile;



John
-- 
use Perl;
program
fulfillment

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Re: System/Exec/Fork ... Help!

2002-11-18 Thread Alan Cameron
On 18 Nov 2002 15:21:26 -0500, Jason Frisvold [EMAIL PROTECTED] wrote:

[snip]

 I can't see to figure out how to spawn a new process, return the pid,
 and be able to monitor this new process on my own ...

The general form would be something like:

my $pid = fork();

if ($pid) {
# I am in the Parent here, do monitoring of the child
} else {
# I am in the child here.. check stuff and send it to the parent
exit 0;  # Don't want to continue past what the child should do
}

Note 1: Error checking is left as an exercise for the reader.
Note 2: If you need more than one child, wrap the whole thing in a loop
of some sort, and use next inside the if()

-- 
Mother is the name for GOD on the lips and
hearts of all children.  - Eric Draven

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




eval help needed.

2002-11-18 Thread Steve
I have this code running under Windows 98 using ActiveState:
The file copy is working okay.  What isn't working is the eval system 
call.  Eudora is never executed and run, BUT the copy always happens.  How 
can I get Eudora to be called?  Is it possible at all?

use File::Copy;
use File::DosGlob qw(glob);
eval {
system(`D:/EudoraPro/Eudora.exe`)
};
print $@;
unless ($@) {
copy($_,'z:/mail_test') foreach glob 'D:/EudoraPro/*.mbx';
copy($_,'z:/mail_test') foreach glob 'D:/EudoraPro/*.toc';
}



-

The three most dangerous things are a programmer with a soldering iron, a 
manager who codes, and a user who gets ideas.



--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: references and printing

2002-11-18 Thread Todd W


John W. Krahn wrote:

Paul wrote:


--- Julien Motch [EMAIL PROTECTED] wrote:


#The next line printsd the reference why ?
print(the host which you are connecteed to is $pop-Host()\n); #
Mail::POP3Client=HASH(0x8153a8c)-Host()


Inside the quotes, the - operator is taken as printable characters.



No, it is not.

$ perl -le' $x-{one} = HELLO; print Test $x-{one} test'
Test HELLO test



Thats a hash lookup. The op tried to call a method in double quotes. I 
dont know exactly what happens, I'd say that since the interpreter saw 
that there was NOT a block { } after the dereference operator it 
decided to take the - as prinable characters.

Todd W.


--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: references and printing

2002-11-18 Thread John W. Krahn
Todd W wrote:
 
 John W. Krahn wrote:
  Paul wrote:
 
 --- Julien Motch [EMAIL PROTECTED] wrote:
 
 #The next line printsd the reference why ?
 print(the host which you are connecteed to is $pop-Host()\n); #
 Mail::POP3Client=HASH(0x8153a8c)-Host()
 
 Inside the quotes, the - operator is taken as printable characters.
 
  No, it is not.
 
  $ perl -le' $x-{one} = HELLO; print Test $x-{one} test'
  Test HELLO test
 
 Thats a hash lookup. The op tried to call a method in double quotes. I
 dont know exactly what happens, I'd say that since the interpreter saw
 that there was NOT a block { } after the dereference operator it
 decided to take the - as prinable characters.

The problem is not with the - operator, the problem is that only a
scalar or array will interpolate in a double quoted string.  Since
-method() in $ref-method() cannot be interpolated only the scalar
part is interpolated and the rest is just printed as is.

$ perl -le'$, = , ;
$x = {zero = 1};
$y = [2];
$z = sub { 3 };
print  $x-{zero}, $y-[0], $z-();
print $x-{zero}, $y-[0], $z-();
print $x-{zero}, $y-[0], @{[$z-()]};
'
1, 2, 3
1, 2, CODE(0x8100398)-()
1, 2, 3



John
-- 
use Perl;
program
fulfillment

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




unlink in ActiveState Perl 5.6.0

2002-11-18 Thread Anshul Chhabra
Hi all
   Has anybody used unlink in ActiveState Perl 5.6.0 (on Windows)? It does
not seem to be working for me.

thanks in advance
Anshul



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




RE: unlink in ActiveState Perl 5.6.0

2002-11-18 Thread Timothy Johnson

What build are you using?  You should probably be using ActivePerl 5.6.1
build 633.  I've used unlink on Win32 with no problems.  Perhaps you can
post your code?

-Original Message-
From: Anshul Chhabra [mailto:[EMAIL PROTECTED]]
Sent: Monday, November 18, 2002 5:18 PM
To: beginner perl
Subject: unlink in ActiveState Perl 5.6.0 


Hi all
   Has anybody used unlink in ActiveState Perl 5.6.0 (on Windows)? It does
not seem to be working for me.

thanks in advance
Anshul



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




RE: eval help needed.

2002-11-18 Thread Steve
Well what I want to do is backup my Eudora mailboxes, and I have that part 
working, but I wanna automate it so that every time I close Eudora the 
files get copied.  A suggestion was that I could wrap the call to Eudora in 
an eval and just call Eudora from the Perl Script.


At 07:23 PM 11/18/02 , Peter Kappus wrote:
I've never played with it, but I think what you need is the perl win32 OLE
libaray...basically, it gives you VBScript-like access to win32 objects and
applications via perl!

check it out:
http://aspn.activestate.com/ASPN/Perl/Products/ActivePerl/site/lib/Win32/OLE
.html

I'm not sure what you're trying to do with Eudora, or if it even supports
OLE (I don't do much windows programming) but the link above should be a
good starting point.

best regards,
-Peter

ps.  here's the demo for how they start excel...you can probably do
something similar with Eudora



--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Re: unlink in ActiveState Perl 5.6.0

2002-11-18 Thread Anshul Chhabra


I am using Build 623. My code is given below. Basically, for processing I
need to create some temp files. After I use them, I want to delete the file.
But the unlink does not work.


require 'AddHeaderToBody.pl';
require 'AddFooterToBody.pl';

$argvLen = @ARGV ;

$inputDir = $ARGV[0] ;
$outputDir = $ARGV[1] ;
$templateDir = $ARGV[2] ;

$argvLen == 3 || die Insufficient arguments , USAGE:\n PostProcess.pl
Input directory Output Directory Template Directory ;

# Need to make sure that output directory exists
 (-d $outputDir ) || die $outputDir does not exist ;
 (-d $templateDir) || die $templateDir does not exist ;

# Need to have a tempfile for processing
$tempFile0 = postProcesstemp.tmp0 ;
while ( -e $tempFile0){
$tempFile0 = $tempFile0 . .0 ;
}

print Final tempFile0 = $tempFile0 \n ;

# Need to have second tempfile
$tempFile1 = postProcesstemp.tmp1 ;
while ( -e $tempFile1){
$tempFile1 = $tempFile1 . .1 ;
}

print Final tempFile1 = $tempFile1\n ;

#We need to look into all jsp files in the input directory


while ($nextName = $inputDir/*.jsp ){
#We have got the input jsp file - we need to add header to it
print \nProcessing $nextName ... ;
$justFileName = $nextName ;
$justFileName =~ s#.*/## ;
$tempfile =
addHeaderToBody($nextName,$templateDir/Header.txt,$tempFile0) ;

addFooterToBody($tempFile, $templateDir/Footer.txt,
$outputDir/$justFileName ) ;

unlink($tempFile0) ;

#if ( -e $tempFile0) {
#   die $tempFile0 still exists!!! ;
#}
#die postProcesstemp.tmp0 was deleted ;

}

-Original Message-
From: Timothy Johnson [mailto:[EMAIL PROTECTED]]
Sent: Monday, November 18, 2002 5:21 PM
To: 'Anshul Chhabra'; beginner perl
Subject: RE: unlink in ActiveState Perl 5.6.0



What build are you using?  You should probably be using ActivePerl 5.6.1
build 633.  I've used unlink on Win32 with no problems.  Perhaps you can
post your code?

-Original Message-
From: Anshul Chhabra [mailto:[EMAIL PROTECTED]]
Sent: Monday, November 18, 2002 5:18 PM
To: beginner perl
Subject: unlink in ActiveState Perl 5.6.0


Hi all
   Has anybody used unlink in ActiveState Perl 5.6.0 (on Windows)? It does
not seem to be working for me.

thanks in advance
Anshul



--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




RE: unlink in ActiveState Perl 5.6.0

2002-11-18 Thread Beau E. Cox
Hi -

This is avoiding your question about unlink (sorry),
but you may want to use a CPAN module to get temp files.
I have used (and am very happy with) File::Temp. This
module does the tedious work of getting a temp file
name and cleans up after itself.

Aloha = Beau.

PS: Unlink has worked fine for me (ActivePerl 5.6.1-633)
when I have used it.

-Original Message-
From: Anshul Chhabra [mailto:[EMAIL PROTECTED]]
Sent: Monday, November 18, 2002 5:13 PM
To: beginner perl
Subject: Re: unlink in ActiveState Perl 5.6.0




I am using Build 623. My code is given below. Basically, for processing I
need to create some temp files. After I use them, I want to delete the file.
But the unlink does not work.


require 'AddHeaderToBody.pl';
require 'AddFooterToBody.pl';

$argvLen = @ARGV ;

$inputDir = $ARGV[0] ;
$outputDir = $ARGV[1] ;
$templateDir = $ARGV[2] ;

$argvLen == 3 || die Insufficient arguments , USAGE:\n PostProcess.pl
Input directory Output Directory Template Directory ;

# Need to make sure that output directory exists
 (-d $outputDir ) || die $outputDir does not exist ;
 (-d $templateDir) || die $templateDir does not exist ;

# Need to have a tempfile for processing
$tempFile0 = postProcesstemp.tmp0 ;
while ( -e $tempFile0){
$tempFile0 = $tempFile0 . .0 ;
}

print Final tempFile0 = $tempFile0 \n ;

# Need to have second tempfile
$tempFile1 = postProcesstemp.tmp1 ;
while ( -e $tempFile1){
$tempFile1 = $tempFile1 . .1 ;
}

print Final tempFile1 = $tempFile1\n ;

#We need to look into all jsp files in the input directory


while ($nextName = $inputDir/*.jsp ){
#We have got the input jsp file - we need to add header to it
print \nProcessing $nextName ... ;
$justFileName = $nextName ;
$justFileName =~ s#.*/## ;
$tempfile =
addHeaderToBody($nextName,$templateDir/Header.txt,$tempFile0) ;

addFooterToBody($tempFile, $templateDir/Footer.txt,
$outputDir/$justFileName ) ;

unlink($tempFile0) ;

#if ( -e $tempFile0) {
#   die $tempFile0 still exists!!! ;
#}
#die postProcesstemp.tmp0 was deleted ;

}

-Original Message-
From: Timothy Johnson [mailto:[EMAIL PROTECTED]]
Sent: Monday, November 18, 2002 5:21 PM
To: 'Anshul Chhabra'; beginner perl
Subject: RE: unlink in ActiveState Perl 5.6.0



What build are you using?  You should probably be using ActivePerl 5.6.1
build 633.  I've used unlink on Win32 with no problems.  Perhaps you can
post your code?

-Original Message-
From: Anshul Chhabra [mailto:[EMAIL PROTECTED]]
Sent: Monday, November 18, 2002 5:18 PM
To: beginner perl
Subject: unlink in ActiveState Perl 5.6.0


Hi all
   Has anybody used unlink in ActiveState Perl 5.6.0 (on Windows)? It does
not seem to be working for me.

thanks in advance
Anshul



--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Big hash question.

2002-11-18 Thread mark
Hi,

I am trying to make hash of delivery zones that allows me to maintain a
record of a zone for every postal code based on the first three digits of
each zip.  Being new to perl I have a few questions about the logical
approach.

Should I list zones as the name component with zips as a list of values and
try to work through the values to establish a zip's zone identity.

%zone={
one = [370,422..430,476,490..500]
two= [200..232,388]

Also, is it possible to utilize ranges from within the value or name of hash
variables?

etc.



Or should list all the possible zips as the name component with it's
corresponding value? (ouch!)

%zone = {370,one,422,one,423,one,424,one, etc999,whatever}


What are pros and cons of my different options... if there is any?

Thanks,
Mark


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




FILTER

2002-11-18 Thread Javeed SAR
Hi,


Can i filter incoming e-mails.
 I am using exchange server (outlook) on win2k.
For example if i have  send  a mail with an attachement to a particular id
say [EMAIL PROTECTED] , i want the perl scipt to see that it move the attachement
to local drive of my system.
Is it possible.??


Regards 
j@veed








Re: system function

2002-11-18 Thread Mark Goland
 system (('tunctl',-u,$buf) | ('awk',print,$2) );

you can also try this
system (tunctl,-u,$buf | awk,print,$2  );

- Original Message - 
From: Timothy Johnson [EMAIL PROTECTED]
To: [EMAIL PROTECTED]; [EMAIL PROTECTED]
Sent: Monday, November 18, 2002 2:40 AM
Subject: RE: system function


 
 Try using backticks instead of system.
 
 my @array = `command line`;
 
 -Original Message-
 From: [EMAIL PROTECTED]
 To: [EMAIL PROTECTED]
 Sent: 11/17/02 5:50 AM
 Subject: system function
 
 Hi, i'd like to know how i can get a return sting from a command and
 pass it
 to awk program.
 I have tried:
 #!/usr/bin/perl 
 
 system (('tunctl',-u,$buf) | ('awk',print,$2) );
 
 tunctl write a string in STDERR like this:
 Set 'tap1' persistent and owned by uid $buf
 
 I like to pass this string to awk and print only 'tap1'.
 How can i do this?
 
 Thanks in advance payment to all those that will answer to this
 message, Michele.
 
 -- 
 To unsubscribe, e-mail: [EMAIL PROTECTED]
 For additional commands, e-mail: [EMAIL PROTECTED]
 
 -- 
 To unsubscribe, e-mail: [EMAIL PROTECTED]
 For additional commands, e-mail: [EMAIL PROTECTED]
 

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]