RE: How to Install Perl 5.8

2002-09-30 Thread Timothy Johnson


If you are using WinNT, I would seriously suggest waiting until ActiveState
puts out a stable version of 5.8.  Until then I'd stick with ActivePerl
5.6.1 build 633.  It really is the most stable version of Perl for all Win32
platforms, and comes with PPM, which is a great way to get started with
modules.

-Original Message-
From: Ajay Singh Tomar (RBIN/EDC3) *
[mailto:[EMAIL PROTECTED]]
Sent: Monday, September 30, 2002 11:26 PM
To: [EMAIL PROTECTED]
Subject: How to Install Perl 5.8


Hello,

I have downloaded and extracted stable.tar from www.cpan.org for version
5.8. I have older version of Perl i.e., 5.003. How to uninstall and install
5.8 on WinNT?

Regards,
Ajay


-Original Message-
From: Timothy Johnson [mailto:[EMAIL PROTECTED]]
Sent: Tuesday, October 01, 2002 11:50 AM
To: '[EMAIL PROTECTED]'; [EMAIL PROTECTED]
Subject: RE: Install Question 



What distribution of Perl are you using?  What operating system are you
using?

-Original Message-
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]]
Sent: Monday, September 30, 2002 8:07 PM
To: [EMAIL PROTECTED]
Subject: Install Question 


Hi:  I have both perl 5.6.1 and perl 5.6.0 on my system.

What're the steps to remove them, and prepare for install of perl 5.8?

When I run locate perl 5.6.0, I get a list of files.  Is this the way to 
do it?  File by file?
Thanks for any help in advance.
Tom


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




Re: another regx ...

2002-09-30 Thread John W. Krahn

"John W. Krahn" wrote:
> 
> my ( $ref, $numt, $id, $ext ) = $PATH[ 7 ] =~ /(\w)-(\d{7})-(\d{2}).(\w+)/;


Sorry, that should be:

my ( $ref, $numt, $id, $ext ) = $PATH[ 7 ] =~ /(\w)-(\d{7})-(\d{2})\.(\w+)/;



John
-- 
use Perl;
program
fulfillment

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




How to Install Perl 5.8

2002-09-30 Thread Ajay Singh Tomar (RBIN/EDC3) *

Hello,

I have downloaded and extracted stable.tar from www.cpan.org for version 5.8. I have 
older version of Perl i.e., 5.003. How to uninstall and install 5.8 on WinNT?

Regards,
Ajay


-Original Message-
From: Timothy Johnson [mailto:[EMAIL PROTECTED]]
Sent: Tuesday, October 01, 2002 11:50 AM
To: '[EMAIL PROTECTED]'; [EMAIL PROTECTED]
Subject: RE: Install Question 



What distribution of Perl are you using?  What operating system are you
using?

-Original Message-
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]]
Sent: Monday, September 30, 2002 8:07 PM
To: [EMAIL PROTECTED]
Subject: Install Question 


Hi:  I have both perl 5.6.1 and perl 5.6.0 on my system.

What're the steps to remove them, and prepare for install of perl 5.8?

When I run locate perl 5.6.0, I get a list of files.  Is this the way to 
do it?  File by file?
Thanks for any help in advance.
Tom


-- 
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: Install Question

2002-09-30 Thread Timothy Johnson


What distribution of Perl are you using?  What operating system are you
using?

-Original Message-
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]]
Sent: Monday, September 30, 2002 8:07 PM
To: [EMAIL PROTECTED]
Subject: Install Question 


Hi:  I have both perl 5.6.1 and perl 5.6.0 on my system.

What're the steps to remove them, and prepare for install of perl 5.8?

When I run locate perl 5.6.0, I get a list of files.  Is this the way to 
do it?  File by file?
Thanks for any help in advance.
Tom


-- 
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: another regx ...

2002-09-30 Thread John W. Krahn

Jerry Preston wrote:
> 
> Hi!

Hello,

> I am getting no where on this and it is not that hard.
> I am trying to break down the following:
> 
> D-2165033-10.TKB61a
> 
> into
> 
> D   2165033   10
> 
> and
> 
> 4-2175587-08.TKB63a
> 
> into
> 4   2175587  08
> 
> using
> 
> (( $ref, $numt, $id, $ext ) = $PATH[ 7 ] ) =~
> /\w-(\d{7})-(\d{2}).[\w+|\d+]/;
> 
> What am I doing wring?

You need parentheses around the \w character class at the beginning and
the character class at the end.  The character class [\w+|\d+] matches a
_single_ character that is either \w (A-Za-z0-9_) or a plus sign (+) or
a vertical bar (|) or \d (0-9) or a plus sign (+).  Since you probably
don't want to match a plus sign or a vertical bar you shouldn't include
them in the character class.  Since the \w character class includes the
\d character class there is no reason to use them both in the same
character class.

my ( $ref, $numt, $id, $ext ) = $PATH[ 7 ] =~
/(\w)-(\d{7})-(\d{2}).(\w+)/;

Or you could do it this way:

my ( $ref, $numt, $id, $ext ) = split /[-.]/, $PATH[ 7 ];



John
-- 
use Perl;
program
fulfillment

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




Re: What Type Of Data Structure Is This?

2002-09-30 Thread John W. Krahn

Ken Hammer wrote:
> 
>  A strange question.
> 
>  I'm using the following data structure to
> store information from a data base query:
> 
> $tablename{"$table"} = {
> "table_name"=> ["$table"],
> "index_name"=> ["$index_name"],
> "columns"   => ["@column_name"],
> "type"  => ["$index_type"],
> "tablespace"=> ["$tablespace_name"]
> 
>  This works great

Are you sure?  None of the quotation marks are required and the ones
around the array are changing the array to a space separated scalar.

$tablename{$table} = {
table_name => [ $table ],
index_name => [ $index_name ],
columns=> [ @column_name ],
type   => [ $index_type ],
tablespace => [ $tablespace_name ]


> and I can later extract the info
> from this structure.

$table_name   = $tablename{$table}{'table_name'}[0];
$index_name   = $tablename{$table}{'index_name'}[0];
@column_names = @{$tablename{$table}{'index_name'}};
$index_type   = $tablename{$table}{'type'}[0];
$space_name   = $tablename{$table}{'tablespace'}[0];

Read up on data structures and references:
perldoc perldata
perldoc perldsc
perldoc perllol
perldoc perlref


> I have 2 questions. What type of
> structure is this

A Hash of Hashes of Arrays


> and how do I add to it?

$tablename{$table}{'table_name'}[0] = $table_name;
$tablename{$table}{'index_name'}[0] = $index_name;
@{$tablename{$table}{'index_name'}} = @column_names;
$tablename{$table}{'type'}[0]   = $index_type;
$tablename{$table}{'tablespace'}[0] = $space_name;



>  When I try to add more info from a subsequent query like
> this:
> 
> $tablename{$table} = {
> "con_name"  =>  ["$constraint_name"],
> "con_type"  =>  ["$type"],
> "rem_con_name"  =>  ["$r_constraint_name"],
> "created_by"=>  ["$generated"]
> };
> 
>  I lose all the previous information, so that only the above
> is now stored.
>  What have I done, how do I do what I want, and am I in over my head?

$tablename{$table}{'con_name'} = [ $constraint_name ];
$tablename{$table}{'con_type'} = [ $type ];
$tablename{$table}{'rem_con_name'} = [ $r_constraint_name ];
$tablename{$table}{'created_by'}   = [ $generated ];



John
-- 
use Perl;
program
fulfillment

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




Install Question

2002-09-30 Thread [EMAIL PROTECTED]

Hi:  I have both perl 5.6.1 and perl 5.6.0 on my system.

What're the steps to remove them, and prepare for install of perl 5.8?

When I run locate perl 5.6.0, I get a list of files.  Is this the way to 
do it?  File by file?
Thanks for any help in advance.
Tom


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




Re: SQL Table Rows

2002-09-30 Thread Hengky


> > How is it possible to cycle through an SQL table row by row, without having
> > to increment an ID by 1 in a while loop and go
> > SELECT * FROM table WHERE id=$id
> > ?
> > And how can I find out how many rows are in the table?
> > 

i hope this one can help you i'm using MySQL on my server

$sth = $dbh->prepare("Select * from TableName;");
$sth->execute;

$countrow = 0;
while(@FieldTable = $sth->fetchrow_array()) {
# Do Some Action Here;
$countrow++;
 }

print "Total Existing Data on Table TableName = $countrow \n";


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




Re: Comparison: finding if a value is gt some value AND lt another

2002-09-30 Thread eric-perl

On Fri, 27 Sep 2002, Jeff 'japhy' Pinyan wrote:
> On Sep 27, [EMAIL PROTECTED] said:
> >Is there a simple way to find if a variable's value is within a range?
> >  if (1 < $x < 5) { print 'foo'; }
> >...or do I have to join two separate comparisons using the logical AND
> >operator? e.g.,
> >  if (1 < $x and $x < 5) { print 'foo'; }
> 
> You have to do that for now.

Many thanks!

-- 
Eric P.
Sunnyvale, CA


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




Re: Condition Evaluation

2002-09-30 Thread eric-perl

I found my mistake: I misread the line number in the error message. DOH!!!
The complaints were related to the block that prints individualized error
messages:


unless (defined $directory && defined $comment && defined $max_rows &&
defined $max_cols && defined $lg_dim && $lg_dim =~ m/[1-9][0-9]?/ &&
(!defined $saturation || abs($saturation) < 100)) { 

 print "Specify a directory to scan (e.g., --directory /etc)\n" unless
$directory;

 print "Provide a comment for the photos (e.g., --comment foobar)\n" 
unless $comment;

 print "Specify the number of rows and columns in the indexes (e.g., 
--cols 5 --rows 5)\n" unless ($max_rows && $max_cols);

 print "Specify a number between -99 and 99 for the image saturation value
(e.g., --saturation -50)\n" unless (abs($saturation) < 100);

 print "Specify a number between 1 and 99 for the images\' final size as a
percentage of the beginning size (e.g., --largedim 75)\n" unless
($lg_dim > 0 && $lg_dim < 100);

 exit;
}


I've added a test for "defined-ness" to the conditional statement

  print "foobar" unless (defined $foo && abs($foo) > 100)'

and everything works fine now.  Thanks for all the help!

--
Eric P.
Sunnyvale, CA


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




Re: Condition Evaluation

2002-09-30 Thread eric-perl

On Mon, 30 Sep 2002, Michael Fowler wrote:
> I cannot duplicate your problem.  Given the code:
> 
> perl -wle 'print "hi" if defined $bar && (!defined $foo || abs($foo)
>< 100)'
> 
> I see no 'Use of uninitialized value' warnings, and no print.  Are you
> certain the code you posted is what you're actually using?  Is there
> relevant code prior to what you posted, such as initializations of your
> variables?

The snippet that I included in the message was a reduced version of the
script. I've attached the script to this message. (I hope that this isn't
a breach of etiquete.) Here's the first 20 lines or so...

#!/usr/bin/perl -w

use Text::Template;
use Image::Magick;
use Getopt::Long;
use File::Path;
use FindBin qw($Bin);
use POSIX;

use strict;
use vars qw($comment $directory $max_rows $max_cols $lg_dim $saturation
$normal $last_index $indiv_template $index_template @files @html_files
@old_indexes);

GetOptions(
'comment=s' => \$comment,
'directory=s'   => \$directory,
'rows=i'=> \$max_rows,
'cols=i'=> \$max_cols,
'largedim=i'=> \$lg_dim,
'normalize' => \$normal,
'saturation:i'  => \$saturation
);

unless (defined $directory && defined $comment && defined $max_rows && 
  defined $max_cols && defined $lg_dim && $lg_dim =~ m/[1-9][0-9]?/ && 
  (!defined $saturation || abs($saturation) < 100)) {
# print individual error messages
exit;
}

# continue if all req'd variables were defined and the optional variables
# were within tolerances

-- Eric P.
Sunnyvale, CA


#!/usr/bin/perl -w

use Text::Template;
use Image::Magick;
use Getopt::Long;
use File::Path;
use FindBin qw($Bin);
use POSIX;

use strict;
use vars qw($comment $directory $max_rows $max_cols $lg_dim $saturation $normal 
$last_index $indiv_template $index_template @files @html_files @old_indexes);
my $copyright = 'Copyright 2002, Fun 4-Wheel Drive Association\nPretorious Networks - 
www.Pretorious.net';

GetOptions(
'comment=s' => \$comment,
'directory=s'   => \$directory,
'rows=i'=> \$max_rows,
'cols=i'=> \$max_cols,
'largedim=i'=> \$lg_dim,
'normalize' => \$normal,
'saturation:i'  => \$saturation
);

unless (defined $directory && defined $comment && defined $max_rows && defined 
$max_cols && defined $lg_dim && $lg_dim =~ m/[1-9][0-9]?/ && (!defined $saturation || 
abs($saturation) < 100)) { 
print "Specify a directory to scan (e.g., --directory /etc)\n" unless 
$directory;
print "Provide a comment for the photos (e.g., --comment foobar)\n" unless 
$comment;
print "Specify the number of rows and columns in the indexes (e.g., --cols 5 
--rows 5)\n" unless ($max_rows && $max_cols);
print "Specify a number between -99 and 99 for the image saturation value 
(e.g., --saturation -50)\n" unless (abs($saturation) < 100);
print "Specify a number between 1 and 99 for the images\' final size as a 
percentage of the beginning size (e.g., --largedim 75)\n" unless ($lg_dim > 0 && 
$lg_dim < 100);
exit;
}

unless (-d "$Bin/$directory" or ($directory =~ m|^/| and -d $directory)) {
print "Invalid directory: $directory\nDirectory $directory must exist within 
$Bin\n";
exit;
} else {
# Strip any trailing-slashes from $directory
$directory =~ s|/$||;

opendir(DIR, $directory) or die "Could not open $directory: $!\n";
# Create an array of the image files' names
# Create a parallel array of HTML file names
# Create an array of old index-#.html files to remove
for (readdir(DIR)) {
next unless ( -f "$directory/$_");
if ((my $file_base = $_) =~ s/\.(jpg|gif)$/\.html/i) {
push (@files, $_);
push (@html_files, "$file_base.html");
next;
}
push (@old_indexes, "$directory/$_") if (m/html$/);
}
closedir(DIR) or die "Could not close $directory: $!\n";

# Calculate the number of index files to create
$last_index = ceil((scalar @files) / ($max_rows * $max_cols));

rmtree([@old_indexes, "$directory/html", "$directory/sm_images", 
"$directory/lg_images"]);
mkpath(["$directory/html", "$directory/sm_images", "$directory/lg_images"]) or 
die "Could not create subdirectories within $directory: $!";

$index_template = Text::Template->new(
TYPE=> 'FILE',
SOURCE  => "$Bin/index_template.tmpl"
);

$indiv_template = Text::Template->new(
TYPE=> 'FILE',
SOURCE  => "$Bin/indiv_template.tmpl"
);
}

my ($prev_href, $next_href, $prev_html, $next_html, $file_list, $index_hyperlist);
my $curr_index = 1;

for (my $x = 0 ; $files[$x] ; $

Re: Anyone want to help modify a script?

2002-09-30 Thread david

Eric Gregory wrote:

> Ok, I've got this script which I pulled off of a website for rotating
> apache logfiles.  But since I'm runnig numberous sites on my server it
> doesn't quite do what I need.
> 
> It works just fine for a single set of logfiles for instance if the files
> are in /logs/test in the example below.  but what I have is a number of
> subdirectories under /logs/test like /logs/test/site1, /logs/test/site2,
> /logs/test/site3
> 
> I'd like the script to go to each directory under the test directory and
> rotate the logs there, how do I do this.
> 

have you try the File::Find module where it can traverse a directory and all 
it's sub directories? example:

#!/usr/bin/perl -w
use strict;
use File::Find;

find(\&process,'/');

sub process{
print "I found $_ in $Fild::Find::dir\n";
#-- also $Fild::Find::filename is the complete path if you
#-- don't need the directory and the filename separately
}

__END__

please read perldoc File::Find

david

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




Re: Last day of Month

2002-09-30 Thread david

Charlie Farinella wrote:

> I have an error popping up in an application that runs monthly reports
> and everymonth seems to leave off the last day's entries.
> 
> The subroutine that determines the last day of the month is here:
> 
> sub GetLastDayOfMonth {
> my( $sec, $min, $hours, $mday, $mon, $year ) = localtime( $_[0] );
> 
> return timelocal( 59, 59, 23, $monthDays[$mon], $mon, $year );
> }
> 
> This is over my head and I'm hoping someone might look at this and point
> out any errors they might see.  Either an explanation of what's going on
> here, or a pointer to appropriate documentation would also be
> appreciated.
> 
> thanks.
> 

try the Date::Manip module out:

#!/usr/bin/perl -w

use strict;
use Date::Manip;

print Date_DaysInMonth(12,2002),"\n"; #-- number of days in Dec 2002

__END__

or you can also try this:

#!/usr/bin/perl -w
use strict;
use Time::Local

my ($month,$year) = (localtime)[4..5];

if($month == 11){
$month = 0;
$year += 1;
}else{
$month++;
}

my $seconds = timelocal(0,0,0,1,$month,$year);
$seconds -= 3600;

my $day = (localtime($seconds))[3];

print "$day\n";

__END__

if you don't want to use another module.

david

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




Can someone help me.

2002-09-30 Thread Bootscat

I'm setting up a list for free and pro members.
I want the pro members to be able to mail daily. I have this part working.

 I want the free members to only be able to mail every 4 Days to the list.

 Using the localtime(time) =
(second,minute,hour,day-of-month,month,year,day-of-week,day-of-year)

Can someone tell me how to code it to only allow it to mail
every 3 days?

Here's the code I already have working. I'm just adding a free members to
mail every 4 Days. I have it checking the LSend file to see when mail was last sent 
like this.
if($lastsend eq "$date"){

If work geat for everyday mailings.

But how do I have it check the LSEND to work for every 3 or 4 days?

> my ($sec,$min,$hour,$dom,$mon,$year,$dow,$doy) = localtime;
> if ( not $doy % 3 ) {
>   sendmail();

Any light you could shed on this would be great.

Thanks and God Bless
Dan

# SEND MAIL TO LIST MEMBERS #

sub send{
print $q->header;
&checklogin;
&header;
if ($banner eq "yes") {&banner1;}
print qq|



Send Your Message To The
Entire Safelist Using The Form Below



From:
$sub
($first)


Subject:




Enter Your Message
Below:






 






|;

&footer;

unlink "$cgiroot/data/lsend/addys.txt";

open (NFILE, ">$cgiroot/data/lsend/addys.txt");
flock(NFILE, 2);

opendir (DIR, "$cgiroot/data/members");
@files = grep { /.txt/ } readdir(DIR);
close (DIR);

foreach $file (@files){
open (MEMDATA, "$cgiroot/data/members/$file");flock(MEMDATA, 2);(@memlines)
= ();flock(MEMDATA, 8);close (MEMDATA);
foreach $memline (@memlines){
($mempass,$memfirst,$memlast,$mememail,$memsub,$memjoined,$memlastsend,$memc
ode,$memconfirm,$status,$extra2,$extra3) = split (/\|/, $memline);
}
($memuser,@junk) = split (/\./, $file);
if(($status !~ /vacation/i) && ($memcode eq "")){
print NFILE "$memsub|$memfirst|$memuser|$mempass|\n";
}else{}
}

flock(NFILE, 8);
close (NFILE);

exit;
}

# MAIL MESSAGE TO LIST MEMBERS ##

sub dosend{
print $q->header;
&checklogin;
&getdate;
&header;
if ($banner eq "yes") {&banner1;}
if($subject eq ""){print qq|You forgot to enter a subject! try
again...|;exit;}
if($message eq ""){print qq|You forgot to enter a message! try
again...|;exit;}

$length=length($message);
if ($length > 2500){
print qq|


Your message is too large!  Maximum message length is 2500 bytes. Your
message is $length bytes long. Please shorten it, and try again.

|;
exit;}

if($lastsend eq "$date"){
print qq|


You cannot send a message right now!


You will have to wait at least 24
hours before you can send again.


click here to continue


|;
exit;
}
if ($status =~ /vacation/i){
print qq|


You cannot send a message right now!


Your account is in Vacation
status.


click here to continue|;
exit;
}
if($code ne ""){
print qq|


You cannot send a message right now!


You have not validated your
subscription email address yet.


click here to continue \|
resend validation code


|;
}else{

print qq|


Emailing Results Will Be Displayed Below!

Wait until you see "The
Emailing Is Now Complete!" at the bottom, Do not hit refresh!



|;


open (LSEND, "$cgiroot/data/lsend/addys.txt");
flock(LSEND, 2);
(@lines) = ();
flock(LSEND, 8);
close (LSEND);

foreach $line (@lines){
($mlist,$mname,$muser,$mpass) = split (/\|/, $line);

open(MAIL,"|$sendmail -t");
print MAIL "Return-path: <$adress>\n";
print MAIL "From: $admin ($listname)\n";
print MAIL "To: $mlist\n";
print MAIL "Reply-To: $sub ($first)\n";
print MAIL "Subject: $subject\n\n";

print MAIL "$top_note\n";
print MAIL
"\n\
n";
print MAIL "$message\n\n";
print MAIL
"\n"
;
print MAIL "$bot_note\n";
print MAIL "To remove yourself from the list,
$htmldir/members.cgi?action=bounced&username=$muser&password=$mpass\n";
close (MAIL);
}

unlink "$cgiroot/data/members/$username.txt";

open (MFILE, ">$cgiroot/data/members/$username.txt");
flock(MFILE, 2);
print MFILE
"$password|$first|$last|$email|$sub|$joined|$date|$code|$confirm|$status|$ex
tra2|$extra3|\n";
flock(MFILE, 8);
close (MFILE);

unlink "$cgiroot/data/lsend/$username.txt";

open (NFILE, ">$cgiroot/data/lsend/$username.txt");
flock(NFILE, 2);
print NFILE "$subject\n\n$message\n";
flock(NFILE, 8);
close (NFILE);

print qq|


http://businessworldlist.com/images/bwlbanner.gif"; alt= "Leads,
Leads, Leads!" border="0" width="468" height="60">


The Emailing Is Now
Complete!


click here to continue


|;
}
&footer;
exit;
}

 CHECK CURRENT DATE #

sub getdate{
if($_[0] eq ""){
$testtime = time;
}else{
$testtime = $_[0];
}
($sec,$min,$hour,$mday,$mon,$year) = (localtime($testtime))[0,1,2,3,4,5];
$mon = $mon + 1;
if($month eq "1"){$month = "01";}if($month eq "2"){$month = "02";}if($month
eq "3"){$month = "03";}if($month eq "4"){$month = "04";}if($month eq
"5"){$month = "05";}if($month eq "6"){$month = "06";}if($mon

Re: "Or" Syntax

2002-09-30 Thread Michael Fowler

On Mon, Sep 30, 2002 at 02:37:52PM -0500, Lance Prais wrote:

[original code, slightly reformatted]
if ($partition eq "Public"){
open(PUBLIC_ALERTSFILE,">$public_alerts_index_txt_filename");
print PUBLIC_ALERTSFILE"$oid". "::" ."$title". "::" .."$partition". "::" 
."$date\n";
close(PUBLIC_ALERTSFILE)|| die "can't close $file: $!";
}

if ($partition eq any(qw/"Public" "OPSEC SDK")){
open(OPSEC_ALERTSFILE,">$opsec_alerts_index_txt_filename");
print OPSEC_ALERTSFILE"$oid". "::" ."$title". "::" .."$partition". "::" ."$date\n";
close(OPSEC_ALERTSFILE)|| die "can't close $file: $!";
}

if ($partition eq any(qw/"Public" "OPSEC SDK" "Gold/Platinum")){
open(ADVANCED_ALERTSFILE,">$advanced_alerts_index_txt_filename");
print ADVANCED_ALERTSFILE"$oid". "::" ."$title". "::" .."$partition". "::" 
."$date\n";
close(ADVANCED_ALERTSFILE)|| die "can't close $file: $!";
}

if ($partition eq any(qw/"Public" "OPSEC SDK" "Gold/Platinum" "CSP")){
open(CSP_ALERTSFILE,">$csp_alerts_index_txt_filename");
print CSP_ALERTSFILE"$oid". "::" ."$title". "::" .."$partition". "::" ."$date\n";
close(CSP_ALERTSFILE)|| die "can't close $file: $!";
}
[end original code]


Ok, for one, I don't think Janek intended you to actually use the
Quantum::Superpositions module in your production code.  It was just one
method of doing it.  $partition eq 'Public' || $partition eq 'OPSEC SDK' is
very likely faster, and doesn't require an external module to implement.

qw/"Public" "OPSEC SDK"/ will not give you what you intended.  It results
in, effectively, the literal list ('"Public", '"OPSEC', 'SDK"').  See
perldoc -f qw, and the reference it points to.

Did you really intend for a line in every file to be added if $partition eq
'Public'?  That's what happens with your code.

Each open in your code truncates the current file to 0 before appending new
text, and isn't checked for failure.  I doubt you wanted to truncate the
file, and you should always check your open.

There are various methods for making your code much less redundant.  The way
I would choose would probably go something like this:

my %partitions = (
'Public'=>  [$public_alerts_index_txt_filename,
 $opsec_alerts_index_txt_filename,
 $advanced_alerts_index_txt_filename,
 $csp_alerts_index_txt_filename],
'OPSEC SDK' =>  [$opsec_alerts_index_txt_filename,
 $advanced_alerts_index_txt_filename,
 $csp_alerts_index_txt_filename],
'Gold/Platinum' =>  [$advanced_alerts_index_txt_filename,
 $csp_alerts_index_txt_filename],
'CSP'   =>  [$csp_alerts_index_txt_filename],
);

foreach my $filename (@{ $partitions{$partition} }) {
open(FILE, ">>$filename")
|| die("Unable to open file \"$filename\": \l$!.\n");

print FILE "$oid\::$title\::$partition\::$date\n";

close(FILE)
|| die("Unable to close file \"$filename\": \l$!.\n");
}


Even if you don't like that solution, you should compare it to your code and
see what optimizations, clarifications, correct code, etc. you can glean
from it.  For example, the open mode causes the print to append to the file,
rather than overwrite it, and the open is checked.


Michael
--
Administrator  www.shoebox.net
Programmer, System Administrator   www.gallanttech.com
--

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




Re: CGI Script and getting the PID

2002-09-30 Thread david

Jessee Parker wrote:

> Hi all, I've run into a bit of a problem. I need to see if a program is
> currently running. If it is, I want to display this on a web page that
> tells the status of the program (either on or off). The script I created
> which is probably longer than it needs to be, basically issues a system(ps
> -A) call and writes it out to a file which in turns gets parsed through.
> This works fine from the command line. However, when I try to execute this
> same script by accessing the web page, it won't write the file to the
> directory which causes it to in turn display incorrect results. I am not
> sure what permissions a cgi-script (or the directory it resides in) should
> have so I didn't want to just try to change permissions to allow it to
> write. I may be approaching this the wrong way entirely so any help would
> be greatly appreciated!
> 
> Jessee

check out the Proc::ProcessTable module in CPAN for a replacement of your 
system(ps -A) thingy. it might prove to be easier to use and maintain and 
you don't need to create a tmp file for storing the output of ps -A.

if you really need to use a tmp file, you can try using the File::Temp 
module which can create tmp file for you and clean it up for you after your 
process is finish with it:

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

use File::Temp qw/tempfile tempdir/;

my ($tmp_handle,$tmp_file) = tempfile(DIR => tempdir(CLEANUP => 1));

#-- do whatever you need to to with $tmp_handle($tmp_file)

__END__

when your process is finished, the tmp file is cleaned up for you 
automatically. this way, you don't have to worry about the permission 
thingy.

david

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




Re: Last day of Month

2002-09-30 Thread Jenda Krynicky

From:   Charlie Farinella 
<[EMAIL PROTECTED]>
> I have an error popping up in an application that runs monthly reports
> and everymonth seems to leave off the last day's entries.
> 
> The subroutine that determines the last day of the month is here:
> 
> sub GetLastDayOfMonth {
>  my( $sec, $min, $hours, $mday, $mon, $year ) = localtime( $_[0] );
> 
>  return timelocal( 59, 59, 23, $monthDays[$mon], $mon, $year );
> }

There is not always the same number of days in a month. Think about 
February!

If I did not want to use a module I'd use this:

use Time::Local;
sub GetLastDayOfMonth {
my( $sec, $min, $hours, $mday, $mon, $year ) = localtime( defined 
$_[0] ? $_[0] : time());
if ($mon == 11) {
$mon=0;
$year++;
} else {
$mon++;
}
return timelocal( 59, 59, 23, 1, $mon, $year ) - 24*60*60;
}

That is "the first of the next month minus one day".

Jenda
=== [EMAIL PROTECTED] == http://Jenda.Krynicky.cz ==
There is a reason for living. There must be. I've seen it somewhere.
It's just that in the mess on my table ... and in my brain
I can't find it.
--- me


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




Re: Reading mail headers from mqueue

2002-09-30 Thread Michael Fowler

On Mon, Sep 30, 2002 at 03:34:10PM -0400, Scot wrote:
>  Looking to read in mail headers from /var/spool/mqueue/
> and load them into an array or hash to filter based on 
> some rules. 
> 
> I know there must be a good module out there to do this. 
> I just want  To,From,CC and Subject. given you have 
> a file with the headers in $_ 

You could probably use Mail::Internet for this.  If the mqueue is being
managed by sendmail the headers aren't going to be simply 'To', 'From',
etc., they'll have prefixes on them which will have to be stripped or
handled in some way.


Michael
--
Administrator  www.shoebox.net
Programmer, System Administrator   www.gallanttech.com
--

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




Re: Last day of Month

2002-09-30 Thread Felix Geerinckx

on Mon, 30 Sep 2002 21:38:34 GMT, Charlie Farinella wrote:
> I don't know if this is helpful.  Let me know.
>  
>> a) how this function is called, and
> 
>  if( $hashref->{'period'} eq '1' ) {
>   $starttime = GetFirstDayOfMonth( $curtime );
>   $endtime = GetLastDayOfMonth( $curtime );
>  
>> b) what's in the @monthDays array (and where it is defined).
> 
>  our @monthDays= qw( 31 28 31 30 31 30 31 31 30 31 30 31 );

This code seems OK to me? When are you running the report? On the last day 
of the month or the first day of the next month?


-- 
felix

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




Re: Condition Evaluation

2002-09-30 Thread Michael Fowler

On Mon, Sep 30, 2002 at 12:52:47PM +0800, [EMAIL PROTECTED] wrote:
[snip]
> unless (defined $directory && defined $comment && defined $max_rows && 
>   defined $max_cols && (!defined $saturation || abs($saturation) < 100)) {
> # Print error messages
>   }
> 
> WHAT'S HAPPENING:
> Without setting $saturation...
>  A. Everything works just fine if all of the *required* variables are set.
>  B. Perl complains 'Use of uninitialized value in abs' if any of the 
> *required* variables are not set.

I cannot duplicate your problem.  Given the code:

perl -wle 'print "hi" if defined $bar && (!defined $foo || abs($foo) < 100)'

I see no 'Use of uninitialized value' warnings, and no print.  Are you
certain the code you posted is what you're actually using?  Is there
relevant code prior to what you posted, such as initializations of your
variables?

 
> WHAT I EXPECT TO HAPPEN:
> Without setting $saturation...
>   I thought that evaluation of the conditional would stop at the first 
>occurence of an undefined variable and that (!$defined $saturation ||
>abs($saturation) < 100) would _not_ be evaluated i.e., The abs() 
>portion of the test would not be performed.

You are correct, this is how it would work.


Michael
--
Administrator  www.shoebox.net
Programmer, System Administrator   www.gallanttech.com
--

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




Anyone want to help modify a script?

2002-09-30 Thread eric gregory

Ok, I've got this script which I pulled off of a website for rotating apache logfiles. 
 But since I'm runnig numberous sites on my server it doesn't quite do what I need.

It works just fine for a single set of logfiles for instance if the files are in 
/logs/test in the example below.  but what I have is a number of subdirectories under 
/logs/test like /logs/test/site1, /logs/test/site2, /logs/test/site3

I'd like the script to go to each directory under the test directory and rotate the 
logs there, how do I do this.

I thought it would entail changing the $LOGPATH= parameter to something like 
/logs/test/* but no luck.

I hope I've made that clear

Any help is appreciated
Eric
Heres the script
###
#!/usr/bin/perl
 $LOGPATH='/logs/test/';
 
@LOGNAMES=('access_log','error_log','referer_log','agent_log','access.log','error.log');
  
 $PIDFILE = '/var/run/httpd.pid';
 $MAXCYCLE = 4;

 chdir $LOGPATH;  # Change to the log directory
 foreach $filename (@LOGNAMES) {
for (my $s=$MAXCYCLE; $s >= 0; $s-- ) {
$oldname = $s ? "$filename.$s" : $filename;
$newname = join(".",$filename,$s+1);
rename $oldname,$newname if -e $oldname;
}
 }
 kill 'HUP',`cat $PIDFILE`;



Re: Last day of Month

2002-09-30 Thread Charlie Farinella

On Mon, 2002-09-30 at 17:18, Felix Geerinckx wrote:
> on Mon, 30 Sep 2002 21:12:56 GMT, Charlie Farinella wrote:
> 
> > I have an error popping up in an application that runs monthly reports
> > and everymonth seems to leave off the last day's entries.
> > 
> > The subroutine that determines the last day of the month is here:
> > 
> > sub GetLastDayOfMonth {
> >  my( $sec, $min, $hours, $mday, $mon, $year ) = localtime( $_[0] );
> > 
> >  return timelocal( 59, 59, 23, $monthDays[$mon], $mon, $year );
> > }
> > 
> 
> Please tell us:

I don't know if this is helpful.  Let me know.
 
> a) how this function is called, and

if( $hashref->{'period'} eq '1' ) {
$starttime = GetFirstDayOfMonth( $curtime );
$endtime = GetLastDayOfMonth( $curtime );

> b) what's in the @monthDays array (and where it is defined).

our @monthDays= qw( 31 28 31 30 31 30 31 31 30 31 30 31 );

Thanks.
-- 

Charlie Farinella, Appropriate Solutions, Inc.
[EMAIL PROTECTED]
603-924-6079



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




Re: Can I append @INC before use

2002-09-30 Thread david

Paul Johnson wrote:

> 
> Remember that . is in @INC by default.

sorry, i use this only as an example

> 
> In this case you want the use statement after the BEGIN block.
> 
> But really you want "use lib".  It goes back to before anything that
> anyone should reasonably be using now.
> 

agree. there shouldn't be any real reason just to wrap the push @INC line 
inside a BEGIN{} when 'use lib' require less typing and accomplish pretty 
much the same thing(better)

david

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




RE: "Or" Syntax

2002-09-30 Thread Janek Schleicher

Lance Prais wrote at Mon, 30 Sep 2002 21:37:52 +0200:

>When I read about this Module it really was not clear about using it with
> strings.

It's not its [Quantum::Superposition's] main purpose.
It deals with another kind of logic handling.

However, I forgot to mention, it's perhaps better not to use in production code.
For myself, I like to use it in snippets.

> I tried it with the following code and it is causing so many problems.  If
> anyone has any Ideas it would be appreciated, I have been pounding my head
> with this for a while now.
> 
> 
>   if ($partition eq "Public"){
>   open(PUBLIC_ALERTSFILE,">$public_alerts_index_txt_filename");
>   print PUBLIC_ALERTSFILE"$oid". "::" ."$title". "::"
> .."$partition". "::" ."$date\n";
>   close(PUBLIC_ALERTSFILE)|| die "can't close 
>$file: $!";
>   }
>   if ($partition eq any(qw/"Public" "OPSEC SDK")){

qw/"Public" "OPSEC SDK"/ stands for a list of 3 elements:
"Public"
"OPSEC
SDK"

I could imagine you meant the list
('Public', 'OPSEC SDK')
instead.


The rest of the code should work.


Greetings,
Janek

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




RE: Win32::SetupSup module problems?

2002-09-30 Thread Timothy Johnson

This module is pretty old, and it is entirely possible that it does not work
with WinXP, although it's highly unlikely, since it works fine with Win2k.
Does this work for you?

use Win32::Setupsup;
use strict;

my $handle = '';

system("start Notepad");
if(Win32::Setupsup::WaitForAnyWindow("notepad",\$handle,10,100)){
   print "Notepad is open.\n";
}
#(Close the Notepad Window)
if(Win32::Setupsup::WaitForWindowClose($handle,10,100)){
   print "Notepad is closed.\n";
}


-Original Message-
From: Cacialli, Doug [mailto:[EMAIL PROTECTED]]
Sent: Monday, September 30, 2002 1:11 PM
To: '[EMAIL PROTECTED]'
Subject: Win32::SetupSup module problems?


Has anybody had any problems with the Win32::SetupSup module?  Specifically,
whenever I try to use it, my system crashes.  It's pretty weird.  I'm
running WinXP Pro, using the latest ActiveState build of Perl.  And like I
said in my last post, this is my first program; I am extremely new to this.
Any input would be great.  Thanks.
 
Doug out.
 
---
Douglas Cacialli - Data Manager / Data Analyst
Sleep and Depression Research Laboratory
University of Rochester Medical Center
300 Crittenden Blvd. - Box PSYCH
Rochester, New York 14642
Phone: (585)273-3309  Fax: (585)506-0287
   NOTE NEW FAX NUMBER   
---
 

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




RE: Last day of Month

2002-09-30 Thread Nikola Janceski

er... my bad.. typo


use Date::Calc qw(Days_in_Month);

> -Original Message-
> From: Nikola Janceski [mailto:[EMAIL PROTECTED]]
> Sent: Monday, September 30, 2002 5:17 PM
> To: 'Charlie Farinella'; Perl Beginners
> Subject: RE: Last day of Month
> 
> 
> The error you have is you didn't use the module that already 
> does this for
> you.
> 
> use Data::Calc qw(Days_in_Month);
> 
> 
> > -Original Message-
> > From: Charlie Farinella [mailto:[EMAIL PROTECTED]]
> > Sent: Monday, September 30, 2002 5:13 PM
> > To: Perl Beginners
> > Subject: Last day of Month
> > 
> > 
> > I have an error popping up in an application that runs 
> monthly reports
> > and everymonth seems to leave off the last day's entries.
> > 
> > The subroutine that determines the last day of the month is here:
> > 
> > sub GetLastDayOfMonth {
> > my( $sec, $min, $hours, $mday, $mon, $year ) = 
> > localtime( $_[0] );
> > 
> > return timelocal( 59, 59, 23, $monthDays[$mon], $mon, $year );
> > }
> > 
> > This is over my head and I'm hoping someone might look at 
> > this and point
> > out any errors they might see.  Either an explanation of 
> > what's going on
> > here, or a pointer to appropriate documentation would also be
> > appreciated.
> > 
> > thanks.
> > 
> > -- 
> > --
> > --
> > Charlie Farinella, Appropriate Solutions, Inc.
> > [EMAIL PROTECTED]
> > 603-924-6079
> > 
> > 
> > 
> > -- 
> > To unsubscribe, e-mail: [EMAIL PROTECTED]
> > For additional commands, e-mail: [EMAIL PROTECTED]
> > 
> 
> --
> --
> 
> The views and opinions expressed in this email message are 
> the sender's
> own, and do not necessarily represent the views and opinions of Summit
> Systems Inc.
> 
> 
> -- 
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> 



The views and opinions expressed in this email message are the sender's
own, and do not necessarily represent the views and opinions of Summit
Systems Inc.


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




Re: Last day of Month

2002-09-30 Thread Felix Geerinckx

on Mon, 30 Sep 2002 21:12:56 GMT, Charlie Farinella wrote:

> I have an error popping up in an application that runs monthly reports
> and everymonth seems to leave off the last day's entries.
> 
> The subroutine that determines the last day of the month is here:
> 
> sub GetLastDayOfMonth {
>  my( $sec, $min, $hours, $mday, $mon, $year ) = localtime( $_[0] );
> 
>  return timelocal( 59, 59, 23, $monthDays[$mon], $mon, $year );
> }
> 

Please tell us:

a) how this function is called, and
b) what's in the @monthDays array (and where it is defined).

-- 
felix

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




RE: Last day of Month

2002-09-30 Thread Nikola Janceski

The error you have is you didn't use the module that already does this for
you.

use Data::Calc qw(Days_in_Month);


> -Original Message-
> From: Charlie Farinella [mailto:[EMAIL PROTECTED]]
> Sent: Monday, September 30, 2002 5:13 PM
> To: Perl Beginners
> Subject: Last day of Month
> 
> 
> I have an error popping up in an application that runs monthly reports
> and everymonth seems to leave off the last day's entries.
> 
> The subroutine that determines the last day of the month is here:
> 
> sub GetLastDayOfMonth {
>   my( $sec, $min, $hours, $mday, $mon, $year ) = 
> localtime( $_[0] );
> 
>   return timelocal( 59, 59, 23, $monthDays[$mon], $mon, $year );
> }
> 
> This is over my head and I'm hoping someone might look at 
> this and point
> out any errors they might see.  Either an explanation of 
> what's going on
> here, or a pointer to appropriate documentation would also be
> appreciated.
> 
> thanks.
> 
> -- 
> --
> --
> Charlie Farinella, Appropriate Solutions, Inc.
> [EMAIL PROTECTED]
> 603-924-6079
> 
> 
> 
> -- 
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> 



The views and opinions expressed in this email message are the sender's
own, and do not necessarily represent the views and opinions of Summit
Systems Inc.


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




Re: Expect-like Perl script

2002-09-30 Thread Felix Geerinckx

on Mon, 30 Sep 2002 20:52:54 GMT, Jose Malacara wrote:

> Hello. I am interested in writing a Perl script that can do the
> following: 
> 
> 1. read a list of user defined commands from a file
> 2. telnet (or possibly ssh) to a device such as a router, login, and
> interactively issue the commands read from the command list. 3.
> return the output from the commands to STDOUT or a file 

http://search.cpan.org/author/JROGERS/Net-Telnet-3.03/lib/Net/Telnet.pm

-- 
felix

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




RE: "Or" Syntax

2002-09-30 Thread david

Lance Prais wrote:

> 
>When I read about this Module it really was not clear about using it
>with
> strings.
> 
> I tried it with the following code and it is causing so many problems.  If
> anyone has any Ideas it would be appreciated, I have been pounding my head
> with this for a while now.
> 
> 
> if ($partition eq "Public"){
> open(PUBLIC_ALERTSFILE,">$public_alerts_index_txt_filename");
>print PUBLIC_ALERTSFILE"$oid". "::" ."$title". "::"
> .."$partition". "::" ."$date\n";
> close(PUBLIC_ALERTSFILE)|| die "can't close $file: $!";
> }
> if ($partition eq any(qw/"Public" "OPSEC SDK")){
> open(OPSEC_ALERTSFILE,">$opsec_alerts_index_txt_filename");
>print OPSEC_ALERTSFILE"$oid". "::" ."$title". "::"
> .."$partition". "::" ."$date\n";
> close(OPSEC_ALERTSFILE)|| die "can't close $file: $!";
> }
> if ($partition eq any(qw/"Public" "OPSEC SDK" "Gold/Platinum")){
> 
> open(ADVANCED_ALERTSFILE,">$advanced_alerts_index_txt_filename");
>print ADVANCED_ALERTSFILE"$oid". "::" ."$title". "::"
> .."$partition". "::" ."$date\n";
> close(ADVANCED_ALERTSFILE)|| die "can't close $file: $!";
> }
> if ($partition eq any(qw/"Public" "OPSEC SDK" "Gold/Platinum" "CSP")){
> open(CSP_ALERTSFILE,">$csp_alerts_index_txt_filename");
>print CSP_ALERTSFILE"$oid". "::" ."$title". "::"
> .."$partition". "::" ."$date\n";
> close(CSP_ALERTSFILE)|| die "can't close $file: $!";
> }
> 

i don't think there is anything wrong with your "or" syntax. it does what 
you expect it to do. i can offer a few tips:

1. try print what $partition contain before any of your 'if' statement to 
see what is really there.

2. check your 'open()' calls! for example, instead of:

open(CSP_ALERTSFILE,">$csp_alters_index_txt_filename");

try:

open(CSP_ALERTSFILE,">$csp_alters_index_txt_filename") || die $!;

3. you really don't need the any(qw//) stuff for a simple 'if' statement. if 
you decided to use it anyway, i don't think you need the "" inside qw//.

hope that gives you some hints.

david

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




Last day of Month

2002-09-30 Thread Charlie Farinella

I have an error popping up in an application that runs monthly reports
and everymonth seems to leave off the last day's entries.

The subroutine that determines the last day of the month is here:

sub GetLastDayOfMonth {
my( $sec, $min, $hours, $mday, $mon, $year ) = localtime( $_[0] );

return timelocal( 59, 59, 23, $monthDays[$mon], $mon, $year );
}

This is over my head and I'm hoping someone might look at this and point
out any errors they might see.  Either an explanation of what's going on
here, or a pointer to appropriate documentation would also be
appreciated.

thanks.

-- 

Charlie Farinella, Appropriate Solutions, Inc.
[EMAIL PROTECTED]
603-924-6079



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




RE: another regx ...

2002-09-30 Thread Janek Schleicher

Nkuipers wrote at Mon, 30 Sep 2002 19:24:18 +0200:

> This idea is even simpler though not purely regex:
> 
> $yourstring =~ s/\..*//;
> @result = split /-/, $yourstring;

Or still simpler:

my ( $ref, $numt, $id, $ext ) = split /\W/, $string, 3;


Greetings,
Janek

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




Expect-like Perl script

2002-09-30 Thread Jose Malacara

Hello. I am interested in writing a Perl script that can do the following:

1. read a list of user defined commands from a file
2. telnet (or possibly ssh) to a device such as a router, login, and interactively 
issue the commands read from the command list.
3. return the output from the commands to STDOUT or a file

Idealiy the next step would be to make this web-based where users could issue the 
commands via a cgi front end and return another page with the command output.

My questions are...

1. Can this be done entirely in Perl or does it require help from something like 
Expect for the interactive command part?

2. Can someone recommend modules, if available, that can be used for this?

3. I have written an expect script that does this, but would like to write it in perl- 
partly in the interest of learning perl. If it canot be done entirely in Perl, is 
there some way to embed the Expect functions within a Perl/cgi script?

Any advice would be greatly appreciated and thanks in advance.

Jose



Re: CGI Script and getting the PID

2002-09-30 Thread Felix Geerinckx

on Mon, 30 Sep 2002 19:39:05 GMT, Jessee Parker wrote:

> Hi all, I've run into a bit of a problem. I need to see if a program
> is currently running. If it is, I want to display this on a web page
> that tells the status of the program (either on or off). The script I
> created which is probably longer than it needs to be, basically
> issues a system(ps -A) call and writes it out to a file which in
> turns gets parsed through. 

There is no need to use an intermediate file if you use a pipe:

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

 open PS, "/bin/ps -A |" or die "cannot fork: $!";
 while () {
# do your stuff
 }
 close PS;

-- 
felix

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




Condition Evaluation

2002-09-30 Thread eric-perl

Hello, All:

I'm testing to determine that a list of variables has been set and 
am baffled by how this conditional is evaluating:

CODE SNIPPET:
GetOptions(
'comment=s' => \$comment,   # Req'd arg
'directory=s'   => \$directory, # Req'd arg
'rows=i'=> \$max_rows,  # Req'd arg
'cols=i'=> \$max_cols,  # Req'd arg
'saturation:i'  => \$saturation # Optional arg
);

unless (defined $directory && defined $comment && defined $max_rows && 
  defined $max_cols && (!defined $saturation || abs($saturation) < 100)) {
# Print error messages
  }

WHAT'S HAPPENING:
Without setting $saturation...
 A. Everything works just fine if all of the *required* variables are set.
 B. Perl complains 'Use of uninitialized value in abs' if any of the 
*required* variables are not set.

WHAT I EXPECT TO HAPPEN:
Without setting $saturation...
  I thought that evaluation of the conditional would stop at the first 
   occurence of an undefined variable and that (!$defined $saturation ||
   abs($saturation) < 100) would _not_ be evaluated i.e., The abs() 
   portion of the test would not be performed.

HOW CAN I:
  1. Check that each of the required variables has been set *and*then*
  2. Check the value of $saturation _only_if_it_has_been_set_?

-- 
Eric Pretorious
Sunnyvale, CA


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




Re: $1, $2, $3, ... as array

2002-09-30 Thread Jeff 'japhy' Pinyan

On Sep 30, Jenda Krynicky said:

>$text =~ s{$regexp}{
>   my $tagname = $1;
>   my %params = ('' => '%');
>   my $i = 2;
>   no strict 'refs';
>   while (defined ${$i}) {
>   $params{${$i}} = ${$i+1};
>   ...
>   $i+=2;
>   }
>   ...
>}ge
>
>
>The ${$i} and ${$i+1} is the thing I do not like.

Why not?  Perl allows you to 'no strict "refs"' for a reason.  This might
be that reason.  Otherwise, use the @- and @+ arrays like I suggested.

-- 
Jeff "japhy" Pinyan  [EMAIL PROTECTED]  http://www.pobox.com/~japhy/
RPI Acacia brother #734   http://www.perlmonks.org/   http://www.cpan.org/
** Look for "Regular Expressions in Perl" published by Manning, in 2002 **
 what does y/// stand for?   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]




Re: Printing A Hash of Hashes

2002-09-30 Thread Ken Hammer

Mark Anderson wrote:
> 
> Why are you wrapping these in arrays?  If you used:
> $tablename{$table} -> {con_name} = $constraint_name;
> $tablename{$table} -> {con_type} = $type;
> $tablename{$table} -> {rem_con_name} = $r_constraint_name;
> $tablename{$table} -> {created_by}   = $generated;
> 
> Then you would get the values in your print, instead of array indexes.
> 
  Bingo!!! That was it Mark! Thank you!

> I hope that I answered your question above.  The other option is to test
> each value to see if it is an array, and then dereference it correctly, but
> I don't think that's what you are looking for.
> 
> /\/\ark

-- 
Ken Hammer
University Of Michigan

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




Re: Printing A Hash of Hashes

2002-09-30 Thread James Edward Gray II

In your adding lines you add entries line [ $entry ], which means, make 
an array reference (the brackets) which has $entry as the first element 
of the array.  You then have a hash of hashes of arrays (for at least 
some entries).  If you meant the arrays, you'll have to add a third 
loop to the printing code to account for that level of nesting.  If you 
didn't intend to make arrays there, just drop those brackets.

James Gray

On Monday, September 30, 2002, at 02:59  PM, Ken Hammer wrote:

>
>  From a previous post I needed to identify
> a particular data structure. It is a hash of hashes.
> Now, I need to print the hash out.
>  I'm using the code from the "Programing
> Perl" 3rd edition from O'Reilly on how
> to print out the hash and of course I'm
> having a problem.
>
>  This is from Chapter 9, page 281 slighly
> changed to reflect my values:
>
> for $table ( keys %tablename) {
> print "Table Name: $table \n";
>
> for $items ( keys %{ $tablename{$table} } ) {
> print "\t$items=$tablename{$table}{$items}\n ";
>
> }
>
> print "\n";
>
>  Here are the results:
>
> Table Name: TURBINE_PERMISSION
> con_name=ARRAY(0x216de8)
> index_name=TURBINE_PERMISSION_PK
> con_type=ARRAY(0x216c8c)
> columns=PERMISSION_ID
> created_by=ARRAY(0x211a50)
> type=NORMAL
> rem_con_name=ARRAY(0x211b04)
> tablespace=CTNG
>
>  This is the code that created the hash of hashes.
> It was done in 2 parts:
>
>  First part (initilizing):
>
> $tablename{"$table"} = {
> "index_name"=> $index_name,
> "columns"   => @column_name,
> "type"  => $index_type,
> "tablespace"=> $tablespace_name
>
> };
>
>  Adding to the hash:
>
> $tablename{$table} -> {con_name} = [$constraint_name];
> $tablename{$table} -> {con_type} = [$type];
> $tablename{$table} -> {rem_con_name} = [$r_constraint_name];
> $tablename{$table} -> {created_by}   = [$generated];
>
>  The above is from the help (thank you) from a previous post.
>
>  Why am I getting the value in the first part, and the
> memory location for the second part? In other words, the key/values
> print out as expected from the initializing loop, but not from
> the "adding" part?
>
> -- 
> Ken Hammer
> University Of Michigan
>
> -- 
> 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: Printing A Hash of Hashes

2002-09-30 Thread Mark Anderson


> This is from Chapter 9, page 281 slighly
>changed to reflect my values:
>
>for $table ( keys %tablename) {
>print "Table Name: $table \n";
>
>for $items ( keys %{ $tablename{$table} } ) {
>print "\t$items=$tablename{$table}{$items}\n ";
>
>}
>
>print "\n";

That looks reasonable.

> Here are the results:
>
>Table Name: TURBINE_PERMISSION
>con_name=ARRAY(0x216de8)
>index_name=TURBINE_PERMISSION_PK
>con_type=ARRAY(0x216c8c)
>columns=PERMISSION_ID
>created_by=ARRAY(0x211a50)
>type=NORMAL
>rem_con_name=ARRAY(0x211b04)
>tablespace=CTNG

It looks like some of the values in your hash are arrays.

> This is the code that created the hash of hashes.
>It was done in 2 parts:
>
> First part (initilizing):
>
>$tablename{"$table"} = {
>"index_name"=> $index_name,
>"columns"   => @column_name,
>"type"  => $index_type,
>"tablespace"=> $tablespace_name
>
>};
>
> Adding to the hash:
>
>$tablename{$table} -> {con_name} = [$constraint_name];
>$tablename{$table} -> {con_type} = [$type];
>$tablename{$table} -> {rem_con_name} = [$r_constraint_name];
>$tablename{$table} -> {created_by}   = [$generated];
>
> The above is from the help (thank you) from a previous post.

Why are you wrapping these in arrays?  If you used:
$tablename{$table} -> {con_name} = $constraint_name;
$tablename{$table} -> {con_type} = $type;
$tablename{$table} -> {rem_con_name} = $r_constraint_name;
$tablename{$table} -> {created_by}   = $generated;

Then you would get the values in your print, instead of array indexes.

> Why am I getting the value in the first part, and the
>memory location for the second part? In other words, the key/values
>print out as expected from the initializing loop, but not from
>the "adding" part?

I hope that I answered your question above.  The other option is to test
each value to see if it is an array, and then dereference it correctly, but
I don't think that's what you are looking for.

/\/\ark


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




Win32::SetupSup module problems?

2002-09-30 Thread Cacialli, Doug








Has anybody had any problems with the Win32::SetupSup module?  Specifically, whenever I try to use it,
my system crashes.  It's
pretty weird.  I'm running WinXP Pro, using the latest ActiveState
build of Perl.  And like I said in my last post, this is
my first program; I am extremely new to this.  Any input would be great.  Thanks.

 

Doug out.

 

---

Douglas Cacialli - Data Manager / Data Analyst

Sleep and Depression Research Laboratory

University of Rochester Medical Center

300 Crittenden Blvd. - Box PSYCH

Rochester, New
  York 14642

Phone:
(585)273-3309  Fax:
(585)506-0287

   NOTE NEW FAX NUMBER   

---

 







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


Printing A Hash of Hashes

2002-09-30 Thread Ken Hammer


 From a previous post I needed to identify
a particular data structure. It is a hash of hashes. 
Now, I need to print the hash out.
 I'm using the code from the "Programing
Perl" 3rd edition from O'Reilly on how
to print out the hash and of course I'm
having a problem.

 This is from Chapter 9, page 281 slighly
changed to reflect my values:

for $table ( keys %tablename) {
print "Table Name: $table \n";

for $items ( keys %{ $tablename{$table} } ) {
print "\t$items=$tablename{$table}{$items}\n ";

}

print "\n";

 Here are the results:

Table Name: TURBINE_PERMISSION 
con_name=ARRAY(0x216de8)
index_name=TURBINE_PERMISSION_PK
con_type=ARRAY(0x216c8c)
columns=PERMISSION_ID
created_by=ARRAY(0x211a50)
type=NORMAL
rem_con_name=ARRAY(0x211b04)
tablespace=CTNG

 This is the code that created the hash of hashes.
It was done in 2 parts:

 First part (initilizing):

$tablename{"$table"} = {
"index_name"=> $index_name,
"columns"   => @column_name,
"type"  => $index_type,
"tablespace"=> $tablespace_name

};

 Adding to the hash:

$tablename{$table} -> {con_name} = [$constraint_name];
$tablename{$table} -> {con_type} = [$type];
$tablename{$table} -> {rem_con_name} = [$r_constraint_name];
$tablename{$table} -> {created_by}   = [$generated];

 The above is from the help (thank you) from a previous post.

 Why am I getting the value in the first part, and the
memory location for the second part? In other words, the key/values
print out as expected from the initializing loop, but not from
the "adding" part?

-- 
Ken Hammer
University Of Michigan

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




RE: "Or" Syntax

2002-09-30 Thread Lance Prais

David,
   Thank you for your help but I think I am not explaining myself correctly.

I am writing to four separate .txt files file where the array [2] is
assigned to the variable "$partition"

If $partition  eq "Public"  only write to a file called $public_text
If $partition eq "Public" or $partition eq "OPSEC SDK" then write to a file
called $opsec_text
If $partition eq "GOLD" or $partition eq "Public" or $partition eq "OPSEC
SDK" then write to a file called "advanced"
If $partition eq "CSP" or If $partition eq "GOLD" or $partition eq "Public"
or $partition eq "OPSEC SDK" then write to a file called "CSP"


Does that make sense?


Thank you in advance
Lance


-Original Message-
From: david [mailto:[EMAIL PROTECTED]]
Sent: Friday, September 27, 2002 12:33 PM
To: [EMAIL PROTECTED]
Subject: Re: "Or" Syntax

Lance Prais wrote:

> If I wanted to say:
>
> If a=b or a=c r a=d do this How would I do that?

don't use '=' for comparison, sue '==' for numeric comparison and 'eq' for
string

>
> I thought I could do it like this but it did not work.
>
> 1.
> If ($a=b) || ($a=c) || ($a=d)
> {
> DO this
> }

the above is syntax error. should have been:

if($a eq 'b' || $a eq 'c' || $a eq 'd'){
}

>
> 2.
> If ($a=b) || if ($a=c) ||  if ($a=d)
> {
> DO this
> }

the above is also syntax error

i notice that in your code, you sometimes have:

if($a eq 'Public'){
$b = 1;
}

if($a eq 'Public' || $a eq 'Whatever'){
$b = 2;
}

if($a eq 'Public' || $a eq 'Whatever' || $a eq 'Something'){
$b = 3;
}

now if $a is 'Public', all three of the if statement is true and the last if
statement sets $b equal to 3 which overwrites whatever is set in the first
2 if statement. i am not sure if that's really what you want or do you
mean:

if($a eq 'Public'){
}elsif($a eq 'Whatever'){
}elsif($a eq 'Something'){
}else{
}

david

--
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: What Type Of Data Structure Is This (Summary)

2002-09-30 Thread Ken Hammer


 The structure is a hash of hashes. Thanks
to:
   nkuipers <[EMAIL PROTECTED]>
   Robin Cragg <[EMAIL PROTECTED]>
   Timothy Johnson <[EMAIL PROTECTED]>

who correctly pointed this also to me. They
also provided some information on how to add
items to the array, and an easier way to 
populate the hash. I was using an anonymous
hash method.

Thanks Again

Original Post:

 A strange question.

 I'm using the following data structure to
store information from a data base query:

$tablename{"$table"} = {
"table_name"=> ["$table"],
"index_name"=> ["$index_name"],
"columns"   => ["@column_name"],
"type"  => ["$index_type"],
"tablespace"=> ["$tablespace_name"]

 This works great and I can later extract the info
from this structure. I have 2 questions. What type of
structure is this and how do I add to it?

 When I try to add more info from a subsequent query like
this:

$tablename{$table} = {
"con_name"  =>  ["$constraint_name"],
"con_type"  =>  ["$type"],
"rem_con_name"  =>  ["$r_constraint_name"],
"created_by"=>  ["$generated"]
};

 I lose all the previous information, so that only the above
is now stored.
 What have I done, how do I do what I want, and am I in over my head?

-- 
Ken Hammer
University Of Michigan

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




Reading mail headers from mqueue

2002-09-30 Thread Scot


Hi; 

 Looking to read in mail headers from /var/spool/mqueue/
and load them into an array or hash to filter based on 
some rules. 

I know there must be a good module out there to do this. 
I just want  To,From,CC and Subject. given you have 
a file with the headers in $_ 


anybody out there using Mail:: like this ?

Thanks 
Scot  


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




RE: "Or" Syntax

2002-09-30 Thread Lance Prais


   When I read about this Module it really was not clear about using it with
strings.

I tried it with the following code and it is causing so many problems.  If
anyone has any Ideas it would be appreciated, I have been pounding my head
with this for a while now.


if ($partition eq "Public"){
open(PUBLIC_ALERTSFILE,">$public_alerts_index_txt_filename");
print PUBLIC_ALERTSFILE"$oid". "::" ."$title". "::"
.."$partition". "::" ."$date\n";
close(PUBLIC_ALERTSFILE)|| die "can't close 
$file: $!";
}
if ($partition eq any(qw/"Public" "OPSEC SDK")){
open(OPSEC_ALERTSFILE,">$opsec_alerts_index_txt_filename");
print OPSEC_ALERTSFILE"$oid". "::" ."$title". "::"
.."$partition". "::" ."$date\n";
close(OPSEC_ALERTSFILE)|| die "can't close 
$file: $!";
}
if ($partition eq any(qw/"Public" "OPSEC SDK" "Gold/Platinum")){

open(ADVANCED_ALERTSFILE,">$advanced_alerts_index_txt_filename");
print ADVANCED_ALERTSFILE"$oid". "::" ."$title". "::"
.."$partition". "::" ."$date\n";
close(ADVANCED_ALERTSFILE)|| die "can't close 
$file: $!";
}
if ($partition eq any(qw/"Public" "OPSEC SDK" "Gold/Platinum" "CSP")){
open(CSP_ALERTSFILE,">$csp_alerts_index_txt_filename");
print CSP_ALERTSFILE"$oid". "::" ."$title". "::"
.."$partition". "::" ."$date\n";
close(CSP_ALERTSFILE)|| die "can't close 
$file: $!";
}

Thank you in advance

Lance

-Original Message-
From: Janek Schleicher [mailto:[EMAIL PROTECTED]]
Sent: Friday, September 27, 2002 3:16 AM
To: [EMAIL PROTECTED]
Subject: Re: "Or" Syntax

Lance Prais wrote at Fri, 27 Sep 2002 01:55:31 +0200:

> If a=b or a=c or a=d do this How would I do that?
>
> I thought I could do it like this but it did not work.
>
> 1.
> If ($a=b) || ($a=c) || ($a=d)
> {
> DO this
> }
>
> 2.
> If ($a=b) || if ($a=c) ||  if ($a=d)
> {
> DO this
> }

If there are some things to compare with for equality,
it's sometime also a good idea to use a hash for a direct lookup:

my %valid_value = map {$_ => 1} (qw/b c d));
if ($valid_value{$a}) {
   ...
}


If time doesn't play any role, but nice code does,
there's also the

use Quantum::Superpositions;
if ($a == any(qw/b c d)) {
   ...
}

way.


Greetings,
Janek


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




CGI Script and getting the PID

2002-09-30 Thread Jessee Parker

Hi all, I've run into a bit of a problem. I need to see if a program is
currently running. If it is, I want to display this on a web page that tells
the status of the program (either on or off). The script I created which is
probably longer than it needs to be, basically issues a system(ps -A) call
and writes it out to a file which in turns gets parsed through. This works
fine from the command line. However, when I try to execute this same script
by accessing the web page, it won't write the file to the directory which
causes it to in turn display incorrect results. I am not sure what
permissions a cgi-script (or the directory it resides in) should have so I
didn't want to just try to change permissions to allow it to write. I may be
approaching this the wrong way entirely so any help would be greatly
appreciated!

Jessee



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




Re: Can I append @INC before use

2002-09-30 Thread Paul Johnson

On Mon, Sep 30, 2002 at 11:25:32AM -0700, david wrote:

> what sort of error message do you get? assume i have: /home/david/perl/A.pm, 
> the following works for me:
> 
> BEGIN{
> push @INC, '/home/david/perl';
> use A;  
> }

Are you sure?

Remember that . is in @INC by default.

In this case you want the use statement after the BEGIN block.

But really you want "use lib".  It goes back to before anything that
anyone should reasonably be using now.

-- 
Paul Johnson - [EMAIL PROTECTED]
http://www.pjcj.net

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




Re: $1, $2, $3, ... as array

2002-09-30 Thread Jenda Krynicky

From: david <[EMAIL PROTECTED]>
> Jenda Krynicky wrote:
> 
> > Are the $n variables accessible as an array as well?
> > 
> > Currently I am using
> > 
> > no strict 'refs';
> > ...
> > ... ${$i} ...
> > 
> > but I don't really like that.
> > 
> > I know I can do
> > 
> > @array = ($string =~ /regexp/);
> > 
> > but I need to access the matched strings in the code in
> > s/regexp/code/ge so this is not workable.
> > 
> > So did I overpass anything?
> > 
> 
> maybe i miss you point and your question. s/regexp/code/ge, the code
> portion is not matched/search for Perl, it's purely a replacement
> string(or expression with as many / as you want). 

OK. 

I thought the difference between "I need to access the matched 
strings in the code in s/regexp/code/ge" vs. "I need to access the 
strings matched in the code in s/regexp/code/ge" is big enough :-)

This is a little like what I have:

$text =~ s{$regexp}{
my $tagname = $1;
my %params = ('' => '%');
my $i = 2;
no strict 'refs';
while (defined ${$i}) {
$params{${$i}} = ${$i+1};
...
$i+=2;
}
...
}ge


The ${$i} and ${$i+1} is the thing I do not like.

Jenda
=== [EMAIL PROTECTED] == http://Jenda.Krynicky.cz ==
There is a reason for living. There must be. I've seen it somewhere.
It's just that in the mess on my table ... and in my brain
I can't find it.
--- me


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




Re: check process state

2002-09-30 Thread david

Zentara wrote:

> 
> My top command dosn't allow for -U or $user. Maybe you
> meant to use ps ?
> 

the -U argument only exist for a certain version of top

Top version 3.4 has it in my UNIX machine

in my Linux box:

[david@panda]$ top -V
top (procps version 2.0.7)

doesn't have it.

david


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




Re: STDIN

2002-09-30 Thread david

Janfek Esquivel wrote:

> I have an HTML in which I have a text box and 2 combo boxes, what I want
> to do, is to read the information entered by text and also the informatios
> selected from the combo boxes (not always used) to compare it with the
> information on it, I already have the code to get from the database the
> information I need, but what I really need is help with the information
> entered and selected.
> Can somebody help me with this problem?
> Thanks in advance.
> 
> Janfek Esquivel.
> 
> _
> Chat with friends online, try MSN Messenger: http://messenger.msn.com

is your application a CGI application? if so, whatever the text the user 
enter into the text box is passed in as param. maybe you can check out the 
CGI module?

david

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




Re: check process state

2002-09-30 Thread david

Jean-Pierre Sylvanie wrote:

> Hi guys,
> 
> I want to do a sub that check if a process is sleeping
> or not...
> 
> I wrote the following sub, but I was wondering if it
> was possible to to it without shell calls...
> 
> Thanks,
> jp.
> 
> 
> 
> sub isSleeping{
>   
>   # get PID of process to check
>   my $pid = shift || return 0;
> 
>   # get user name
>   my $user;
>   if(`id` =~ /\((\w+)\)/) {$user=$1};
> 
>   # the 7th field (starting at 0) of top output is the state.
>   # top -b (for batch mode) -U $user (processes of $user).
>   my $state = (split /\s+/, (grep {/$pid/} `top -b -U $user`)[0])[7];
>   
>   return $state eq "sleep";
> }

i don't understand why people keep using 'ps' or 'top' and then do a bunch 
of regular expression to look for a program/process that they want. this is 
so inefficient(more coding especially the reg. portion), unsafe(if $user 
happens to be: 'whatever;rm -fr /*' and you are root, your system is gone, 
forever!), not portable(not every system use the exact same display for top 
or ps. what happen if all the ps or top change the display format? are you 
all going to re-do all of your reg. expression to match the new format? 
another change, another re-do?).

sorry about the complian! it's my only 2cent of the day. i promise. :-)

please check out the Proc::ProcessTable in CPAN. it does everything you ask 
for and much more such as 'give me all process that's using more than 50% 
of the system memory' or 'give me a list of process that have sleep for 
more than 5 minutes'... etc.

david

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




Re: Can I append @INC before use

2002-09-30 Thread david

Ramprasad A Padmanabhan wrote:

> Hello All,
> 
> I have a perl script which has
> 
> (assuming BAR.pm is in /tmp/foo/)
> 
> 
> BEGIN {
>  push @::INC , "/tmp/foo";
>  # use  BAR;  # Does not work
>  require BAR;  # Works fine
> }
> 
> Can I get to use 'use' instead of require any how
> 
> Thanx
> Ram

what sort of error message do you get? assume i have: /home/david/perl/A.pm, 
the following works for me:

BEGIN{
push @INC, '/home/david/perl';
use A;  
}

david

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




Re: $1, $2, $3, ... as array

2002-09-30 Thread david

Jenda Krynicky wrote:

> Are the $n variables accessible as an array as well?
> 
> Currently I am using
> 
> no strict 'refs';
> ...
> ... ${$i} ...
> 
> but I don't really like that.
> 
> I know I can do
> 
> @array = ($string =~ /regexp/);
> 
> but I need to access the matched strings in the code in
> s/regexp/code/ge so this is not workable.
> 
> So did I overpass anything?
> 

maybe i miss you point and your question. s/regexp/code/ge, the code portion 
is not matched/search for Perl, it's purely a replacement string(or 
expression with as many / as you want). the word 'capture' doesn't make 
much sense here. for example:

my $i = 'abcd 1234';
my $j = 'hi;

$i =~ s/abcd/($hi)/;

the '()' in replacement is not capturing anything, it's taken as it's. $i 
now become:

(hi) 1234

as i said, maybe i have miss your point, but i don't see how you can capture 
anything.

david

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




Re: how to know weather perl script is already running?

2002-09-30 Thread david

Theuerkorn Johannes wrote:

> Hello List,
> 
> i have a perl script that i have running from a cron Job. It usually opens
> every 4 hours. But sometimes it takes the script longer to execute its job
> so after cron opens up the perl script as usual, i have two perl jobs
> running. Is there any possibility to check weather the script is already
> running? Maybe i can use a system command in the crontab?
> 
> any help welcoe
> 
> greets Johannes

try the Proc::ProcessTable module. example to find a process 'running.pl':

#!/usr/bin/perl -w

use strict;
use Proc::ProcessTable;

my $t = new Proc::ProcessTable;

foreach my $p (@{$t->table}){
if($p->cmndline =~ /running\.pl/){
print $p->cmndline," already running!\n";
last;
}
}

__END__

david

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




Re: Finding if a module is already 'require'd

2002-09-30 Thread david

Ramprasad A Padmanabhan wrote:

> 
> 
> How do I find in a function if a particular module is already loaded
> 
> for eg,
> 
> sub mysub {
> my @vars = @_;
> require Data::Dumper unless ( already_required('Data::Dumper'));
> print Data::Dumper::Dumper(\@vars);
> }
> 
> I want help writing the function already_required()

if you use the compile time 'use Data::Dumper' then you don't have to worry 
abut this since Perl will complain and won't compile if the module is 
missing. if you try to do it in run time, here is one way:

sub already_required{

my $module = shift;

eval{
require $module;
};

if($@){
#-- something is wrong. $module could be missing
return 0;
}else{
#-- looks like $module is successfully loaded!
return 1;
}
}

david

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




Re: SQL Table Rows

2002-09-30 Thread david

Dan wrote:

> How is it possible to cycle through an SQL table row by row, without
> having to increment an ID by 1 in a while loop and go
> SELECT * FROM table WHERE id=$id
> ?
> And how can I find out how many rows are in the table?
> 
> Dan

have you try:

SELECT * FROM table;

and then just cycle it through with DBI like:

while(@array = $sth->fetchrow_array){
#-- @array holds a single row from table
#-- $array[0] is the first field of the row
#-- $array[1] is the second field of the row
#-- ... etc 
#-- i think you get the idea right?
}

to find out how many rows are in the table, try:

SELECT COUNT(*) FROM table;

david

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




Re: Breaking out of STDIN Question

2002-09-30 Thread david

Jenda Krynicky wrote:

>> 
>> If you want to stop input based on what the user entered on the
>> command line then you have to read ONE line at a time and not use an
>> array for input.  BTW your loop will only read numbers and not strings
>> because the test '== 0' will evaluate strings in a numerical context
>> which are always equal to 0.
> 
> Unless the string starts with a number that is not equal to zero :-)
> 

true but if you have warning enable (which i think is a good idea), Perl 
will warn you about this even the string starts with a number but doesn't 
contain purely number. so if you want to avoid those warning, you can 
disable warning (which is not recommanded) or you have to enter a pure 
number. :-)

david

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




Re: How to snip the end of a huge log file

2002-09-30 Thread david

Mark Richmond wrote:

> 
> Hi:
> 
> I have may huge log files where all I care about is the error at the end
> how can seek backwards to find my pattern and snip off the end.
> I'm looking for strings like. " Rebuilding "link" "  which
> only occur once when reading backwards but may times when reading forward.

here is one way of doing it with seek/tell. it reads the foo.txt file line 
by line from the end:

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

my @character;
open(FH,"foo.txt") || die $!;
seek(FH,(-s "foo.txt")-2,0);
while(1){

read(FH,$b,1);

if($b eq "\n"){
#-- one line. do your stuff here
print join('',@character),"\n";
@character = ();
}else{
unshift @character,$b;
}

#-- the following is for the first 2 lines from the top
seek(FH,tell(FH)-2,0);
next unless(tell(FH) == 1);

read(FH,$b,1);
unshift @character,$b;

seek(FH,0,0);
read(FH,$b,1);
unshift @character,$b;

print join('',@character),"\n";
last;
}
close(FH);

__END__

i am sure you can make the above better. :-)

david

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




Re: Permission Problems

2002-09-30 Thread david

Josh wrote:

> To clarify in my earlier posting, the part where I say,
> 
> I have played with chown but the fact is "nobody" can't chown a
> file
> that belongs to "root".  For grins I did:
> 
> chown nobody:nobody ./fooness.cfg
> chmod 666 ./fooness.cfg
> 
> I meant that I issued those commands from the command line. So even with
> the file owned by nobody and everything is world read/writable I still get
> a permission denied error.

that's interesting! even the file is world read/writable, you still have the 
permission denied error. hum... could it be that another process is locking 
up the file?

david

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




Re: check process state

2002-09-30 Thread zentara

On Mon, 30 Sep 2002 11:38:40 -0400, [EMAIL PROTECTED]
(Jean-Pierre Sylvanie) wrote:

>Hi guys,
>
>I want to do a sub that check if a process is sleeping
>or not...
>
>I wrote the following sub, but I was wondering if it
>was possible to to it without shell calls...

My top command dosn't allow for -U or $user. Maybe you
meant to use ps ?

>
>sub isSleeping{
>  
>  # get PID of process to check
>  my $pid = shift || return 0;
>
>  # get user name
>  my $user;
>  if(`id` =~ /\((\w+)\)/) {$user=$1};
>
>  # the 7th field (starting at 0) of top output is the state.
>  # top -b (for batch mode) -U $user (processes of $user).
>  my $state = (split /\s+/, (grep {/$pid/} `top -b -U $user`)[0])[7];
>  
>  return $state eq "sleep";  
>}
>

Try this Proc::ProcessTable method:
##
#!/usr/bin/perl -w
use strict;
use Proc::ProcessTable;

my $t = new Proc::ProcessTable;

foreach my $p ( @{$t->table} ){
print $p->pid,"\t",$p->state,"\t",$p->cmndline,"\n";
}
###




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




Re: pop-up window with database access

2002-09-30 Thread david

Jim Lundeen wrote:

> Hello,
> 
> I'm creating a web site for our department at my school.  We have a
> sign-up form for a society that people can join.  I want to create a
> MySQL database of university names and allow the user to click on a
> "Lookup" button on the sign-up form when they get to the field
> "University Affiliation" and the pop-up window would then go out and get
> a list of universities in the database and allow them to select the
> university they are with, then the selected value would be put in the
> correct text box on the main page form.  I would guess that
> JavaScript is involved, but I don't know.
> 
> Any help (detailed help!) would be very much appreciated by many
> students and professors from around the world!
> 
> Jimmy James

yeah. javascript seems like a good choice for this kind of client side 
pop-up window stuff. :-)

i don't know how much help we can provide here unless you tell us at least 
what have you try. what your plan is. any problems(be specific) you 
encounter.

david

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




Re: system call troubles...

2002-09-30 Thread david

Jenda Krynicky wrote:

> Windows is one example.
> 
> There you do not create a new process by forking and then changin the
> program your process executes, but by a CreateProcess():
> 
> (from MSDN)
> The CreateProcess function creates a new process and its primary
> thread. The new process runs the specified executable file in the
> security context of the calling process.
> 
> BOOL CreateProcess(
>   LPCTSTR lpApplicationName,
>   LPTSTR lpCommandLine,
>   LPSECURITY_ATTRIBUTES lpProcessAttributes,
>   LPSECURITY_ATTRIBUTES lpThreadAttributes,
>   BOOL bInheritHandles,
>   DWORD dwCreationFlags,
>   LPVOID lpEnvironment,
>   LPCTSTR lpCurrentDirectory,
>   LPSTARTUPINFO lpStartupInfo,
>   LPPROCESS_INFORMATION lpProcessInformation
> );
> 
> 
> fork() is totally alien to Windows.
> Therefore perl under Windows implements system() with
> CreateProcess(), fork() is emulated by creating thread and exec()
> uses CreateProcess() and exits the current thread or process.
> 
> This means that it's much more efficient to use system() then
> fork() & exec() under Windows.
> 
> Jenda
> P.S.: I did not look at the actual implementation of fork(), exec()
> and system() in Perl sources. This is just from what I know about
> windows and what I read in the docs and posts. But I believe I am
> about right.

Perl implement fork() internally (after 5.6.X i think) so even OS that do 
not support fork() can be fork. i am not sure if that is true on Windos or 
not.

prior to 5.6, yes fork() is implemented differently(or not implemented at 
all for some OS) but after 5.6, Perl handles this by dupping itself, which 
is very expensive according to the doc but it gives all user on all OS the 
same interface to the [U|Li]nux fork world.

david

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




Re: Searching & Storing

2002-09-30 Thread david

Henry Wong wrote:

> Ok, i've decided to skip using the Date::Manip coz its giving me lots of
> problems. Is there a way to compare dates (e.g. Thu Jun 20 12:00:00 2002)
> and sort them in order? What i've always wanted is to sort them, and
> subsequently using User's input of Start & End date to capture relevant
> logs as explained below.
> 
> Assuming that $noforlines is the no of lines the log file has, and that
> $convertedList[] contains the dates, while $user_start & $user_end
> containing the user's desired start & end date, how do i compare dates?
> The below coding doesn't seem to work right.
> 
> for ($s=0;$s<$noforlines;$s++) {
> if (($convertedList[$sian]>= $user_start)&&($convertedList[$sian]<=
> $user_end)) {
>  open (USER, ">>${filename}_REQUEST.TXT");
>  print USER "$convertedList[$sian]\t$inputList[$sian]\n";
> }
> 
> Pls advise, thanks.
> 
> Regards,
> 
> ~ HENRY WONG ~

what problem do you have with Date::Manip? :-) I found it very easy to use.

anyway, if you don't want to use Date::Manip, you can still sort/compare 
date/time. there are a couple ways(at least) of doing this:

1. compare the date/time as string. consider you have the following 2 dates:

my $date1 = '2002-12-23 21:34:45';
my $date2 = '2002-12-21 09:08:12';

you can compare them like:

if($date1 > $date2){
print "yes\n";
}else{
print "no\n";
}

which we use it as string and compare it like a string. you must remember to 
make all of your dates the same exact format. if you don't, you will run 
into problem like:

my $date1 = '2002-12-23 21:34:45';
my $date2 = '2002-2-23 02:34:12';

suddenly, $date2 is 'bigger' than $date1 but $date1 is Dec 2002 and $date1 
is only Feb 2002.

2. another way is to convert the date string into seconds with Time::Local 
and localtime. when the user enter a date, convert it to seconds and then 
compare it with whatever you parsed from the log. i would recommand you 
using this method

david

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




RE: opening MS ACCESS via the system function

2002-09-30 Thread Timothy Johnson


Check out the Win32::SetupSup module.  You should be able to open the
program via system, find the window, and send the keystrokes to it using
this module.

-Original Message-
From: Cacialli, Doug [mailto:[EMAIL PROTECTED]]
Sent: Monday, September 30, 2002 10:16 AM
To: '[EMAIL PROTECTED]'
Subject: opening MS ACCESS via the system function


Lo,

I'm attempting to write a program that will run daily, and perform the
following actions:

1. Open a database in MS Access 2002, 
2. Execute a program in SAS v8.02 that will, simply put, do a lot of
statistical analyses and compare the current database to the backup from the
night before to identify any changes, and
3. Generate a txt report summarizing the analyses and send the report to a
handful of users via email.

The problem is this: I have user-level security B.S. on the MS Access
database.  In order for SAS to do its things, the Access database needs to
be open, which I was going to do via the perl system function.  However, I
can't open the database without providing Access with a logon and password.

Does anyone have any ideas or suggestions here?  Is there a way to send the
logon and password when I invoke the Access via system?  I know there's a
DBD::ODBC module that I can use to get at the data, but I'm pretty sure that
it won't open the database.  ANY suggestions or ideas would be appreciated.
This is my first program in perl.  Thanks.

Doug out.

---
Douglas Cacialli - Data Manager / Data Analyst
Sleep and Depression Research Laboratory
University of Rochester Medical Center
300 Crittenden Blvd. - Box PSYCH
Rochester, New York 14642
Phone: (585)273-3309  Fax: (585)506-0287
   NOTE NEW FAX NUMBER   
---

-- 
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: another regx ...

2002-09-30 Thread nkuipers

This idea is even simpler though not purely regex:

$yourstring =~ s/\..*//;
@result = split /-/, $yourstring;


>= Original Message From "Mark Anderson" <[EMAIL PROTECTED]> =
>-Original Question-
>
>D-2165033-10.TKB61a => D   2165033   10
>
>and
>
>4-2175587-08.TKB63a => 4   2175587  08
>
>using
>
>(( $ref, $numt, $id, $ext ) = $PATH[ 7 ] ) =~
>/\w-(\d{7})-(\d{2}).[\w+|\d+]/;
>
>What am I doing wring?


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




Re: Searching & Storing

2002-09-30 Thread david

Henry Wong wrote:

> Hi all, I tried using the below codes provided but i got an error saying
> "Can't locate Date/Manip.pm in @INC...etc". I reckon that the Date::Manip
> do not exist in my library. Any other alternatives for my problem below?
> 
> 
> Regards,
> 

you just have to install Date::Manip. it's very easy to install. it's a 
stand alone module written entirely in Perl and do not requires any other 
external module.

try install it this way:

perl -MCPAN -e 'install Date::Manip'

if that doesn't work, do the following:

1. download Date::Manip from CPAN manually
2. untar it like tar -zxf 
3. cd  directory
4. perl Makefile.PL
5. make
6. make test
7. make install
8. make clean

run the above as 'root' and it should install without error.

david

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




opening MS ACCESS via the system function

2002-09-30 Thread Cacialli, Doug

Lo,

I'm attempting to write a program that will run daily, and perform the
following actions:

1. Open a database in MS Access 2002, 
2. Execute a program in SAS v8.02 that will, simply put, do a lot of
statistical analyses and compare the current database to the backup from the
night before to identify any changes, and
3. Generate a txt report summarizing the analyses and send the report to a
handful of users via email.

The problem is this: I have user-level security B.S. on the MS Access
database.  In order for SAS to do its things, the Access database needs to
be open, which I was going to do via the perl system function.  However, I
can't open the database without providing Access with a logon and password.

Does anyone have any ideas or suggestions here?  Is there a way to send the
logon and password when I invoke the Access via system?  I know there's a
DBD::ODBC module that I can use to get at the data, but I'm pretty sure that
it won't open the database.  ANY suggestions or ideas would be appreciated.
This is my first program in perl.  Thanks.

Doug out.

---
Douglas Cacialli - Data Manager / Data Analyst
Sleep and Depression Research Laboratory
University of Rochester Medical Center
300 Crittenden Blvd. - Box PSYCH
Rochester, New York 14642
Phone: (585)273-3309  Fax: (585)506-0287
   NOTE NEW FAX NUMBER   
---

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




RE: another regx ...

2002-09-30 Thread Mark Anderson

-Original Question-

D-2165033-10.TKB61a => D   2165033   10

and

4-2175587-08.TKB63a => 4   2175587  08

using

(( $ref, $numt, $id, $ext ) = $PATH[ 7 ] ) =~
/\w-(\d{7})-(\d{2}).[\w+|\d+]/;

What am I doing wring?

-My Response-
Your parens are in the wrong place.
You aren't capturing the word (\w) character at the start.
You're capturing four variables, but you only show breaking down into three.
The . in your regexp represents any byte, not a literal period, for that you
need \.
[\w+|\d+] is confusing, since digits are included in \w, just use it.

Try:

($ref,$numt,$id,$ext) = ($PATH[7] =~ /(\w)-(\d{7})-(\d{2})\.(\w+)/);



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




another regx ...

2002-09-30 Thread Jerry Preston

Hi!

I am getting no where on this and it is not that hard.

I am trying to break down the following:

D-2165033-10.TKB61a

into

D   2165033   10

and

4-2175587-08.TKB63a

into
4   2175587  08

using

(( $ref, $numt, $id, $ext ) = $PATH[ 7 ] ) =~
/\w-(\d{7})-(\d{2}).[\w+|\d+]/;

What am I doing wring?

Thanks,

Jerry





Weekly posting statistics - 39/2002

2002-09-30 Thread Felix Geerinckx

Weekly posting statistics for perl.beginners - week 39 of 2002.

>From Monday 2002-09-23 to Sunday 2002-09-29 there were 
483 articles posted (22798 lines) by 136 authors, giving an average 
3.55 articles per author, and an average article length of 47 lpa.
The average number of articles per day was 69.

There were 109 (23%) original articles, and 374 (77%) replies
(articles that started with 'RE:' in their subject line).

60 (44%) authors posted only one article.

The authors top-10 by number of articles is as follows:

 All/Ori Lines  lpa  Author

  47/01896   40  [EMAIL PROTECTED] (David)
  21/0 831   39  [EMAIL PROTECTED] (John W. Krahn)
  21/0 800   38  [EMAIL PROTECTED] (Michael Fowler)
  17/0 661   38  [EMAIL PROTECTED] (Sudarshan Raghavan)
  14/0 834   59  [EMAIL PROTECTED] (Timothy Johnson)
  14/0 537   38  [EMAIL PROTECTED] (Jenda Krynicky)
  14/0 463   33  [EMAIL PROTECTED] (Janek Schleicher)
  13/0 403   31  [EMAIL PROTECTED] (Jeff 'Japhy' Pinyan)
  12/1 284   23  [EMAIL PROTECTED] (Nkuipers)
   9/2 446   49  [EMAIL PROTECTED] (James Edward Gray ...

-- 
felix

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




RE: check process state

2002-09-30 Thread Kipp, James

you could use the Proc::ProcessTable module

> -Original Message-
> From: Sylvanie, Jean-Pierre [mailto:[EMAIL PROTECTED]]
> Sent: Monday, September 30, 2002 11:39 AM
> To: '[EMAIL PROTECTED]'
> Subject: check process state
> 
> 
> Hi guys,
> 
> I want to do a sub that check if a process is sleeping
> or not...
> 
> I wrote the following sub, but I was wondering if it
> was possible to to it without shell calls...
> 
> Thanks,
> jp.
> 
> 
> 
> sub isSleeping{
>   
>   # get PID of process to check
>   my $pid = shift || return 0;
> 
>   # get user name
>   my $user;
>   if(`id` =~ /\((\w+)\)/) {$user=$1};
> 
>   # the 7th field (starting at 0) of top output is the state.
>   # top -b (for batch mode) -U $user (processes of $user).
>   my $state = (split /\s+/, (grep {/$pid/} `top -b -U $user`)[0])[7];
>   
>   return $state eq "sleep";  
> }
> 
> 
> 
> -- 
> 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]




STDIN

2002-09-30 Thread Janfek Esquivel

I have an HTML in which I have a text box and 2 combo boxes, what I want to 
do, is to read the information entered by text and also the informatios 
selected from the combo boxes (not always used) to compare it with the 
information on it, I already have the code to get from the database the 
information I need, but what I really need is help with the information 
entered and selected.
Can somebody help me with this problem?
Thanks in advance.

Janfek Esquivel.

_
Chat with friends online, try MSN Messenger: http://messenger.msn.com


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




RE: What Type Of Data Structure Is This?

2002-09-30 Thread Timothy Johnson


What you have is a hash of hashes, the values of which is a reference to a
hash of arrays.  The original scalar is a reference to an anonymous hash.
The value of each hash key is a reference to an anonymous array.  The reason
why what you tried doesn't work is that you are assigning a reference to a
new anonymous hash instead of adding to the one you have.  Try something
like this:

%{$tablename{$table}}{con_name} = [$constraint_name];

or

$tablename{$table}->{con_name} = [$constraint_name];

The first example dereferences the anonymous hash and then accesses the key,
and the second one accesses the key indirectly (and is easier to read IMHO).

One question, though.  Why are you creating anonymous arrays that have only
one element?

Couldn't "table_name => [$table]" be more easily written as "$table_name =>
$table"?

-Original Message-
From: Ken Hammer [mailto:[EMAIL PROTECTED]]
Sent: Monday, September 30, 2002 8:24 AM
To: [EMAIL PROTECTED]
Subject: What Type Of Data Structure Is This?



 A strange question.

 I'm using the following data structure to
store information from a data base query:

$tablename{"$table"} = {
"table_name"=> ["$table"],
"index_name"=> ["$index_name"],
"columns"   => ["@column_name"],
"type"  => ["$index_type"],
"tablespace"=> ["$tablespace_name"]

 This works great and I can later extract the info
from this structure. I have 2 questions. What type of
structure is this and how do I add to it?

 When I try to add more info from a subsequent query like
this:

$tablename{$table} = {
"con_name"  =>  ["$constraint_name"],
"con_type"  =>  ["$type"],
"rem_con_name"  =>  ["$r_constraint_name"],
"created_by"=>  ["$generated"]
};

 I lose all the previous information, so that only the above
is now stored.
 What have I done, how do I do what I want, and am I in over my head?

-- 
Ken

-- 
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: What Type Of Data Structure Is This?

2002-09-30 Thread Robin Cragg

Hi Ken,

the reason you lose your data is simple. You have something of the form:

$myscalar = "A weird hested hash";

you then try to add an entry by doing:

$myscalar = "Some other data";

What you look at it like that, it's clear what is going wrong. What you 
want is:

$tablename{$table}{"con_name"} = ["constraint_name"];





R


At 11:24 30/09/2002 -0400, Ken Hammer wrote:

>  A strange question.
>
>  I'm using the following data structure to
>store information from a data base query:
>
>$tablename{"$table"} = {
> "table_name"=> ["$table"],
> "index_name"=> ["$index_name"],
> "columns"   => ["@column_name"],
> "type"  => ["$index_type"],
> "tablespace"=> ["$tablespace_name"]
>
>  This works great and I can later extract the info
>from this structure. I have 2 questions. What type of
>structure is this and how do I add to it?
>
>  When I try to add more info from a subsequent query like
>this:
>
>$tablename{$table} = {
> "con_name"  =>  ["$constraint_name"],
> "con_type"  =>  ["$type"],
> "rem_con_name"  =>  ["$r_constraint_name"],
> "created_by"=>  ["$generated"]
> };
>
>  I lose all the previous information, so that only the above
>is now stored.
>  What have I done, how do I do what I want, and am I in over my head?
>
>--
>Ken
>
>--
>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: What Type Of Data Structure Is This?

2002-09-30 Thread nkuipers

>$tablename{"$table"} = {
>"table_name"=> ["$table"],
>"index_name"=> ["$index_name"],
>"columns"   => ["@column_name"],
>"type"  => ["$index_type"],
>"tablespace"=> ["$tablespace_name"]
>
> This works great and I can later extract the info
>from this structure. I have 2 questions. What type of
>structure is this and how do I add to it?
>
> When I try to add more info from a subsequent query like
>this:
>
>$tablename{$table} = {
>"con_name"  =>  ["$constraint_name"],
>"con_type"  =>  ["$type"],
>"rem_con_name"  =>  ["$r_constraint_name"],
>"created_by"=>  ["$generated"]
>};
>
> I lose all the previous information, so that only the above
>is now stored.
> What have I done, how do I do what I want, and am I in over my head?

For one thing, at least in the case of scalar values, why are you loading the 
scalars in anonymous arrays?  Why not just have "con_name" => 
"$constraint_name" for example?  Also, you could only be clobbering previous 
contents if $table already exists in the overall hash.  Otherwise $table is 
created as a new key and there should be no problem.  So you need to use a 
check, something like

if (exists $tablename{$table}) {...next (or whatever)...}
else { $tablename{$table} = ... }

Check out chapter 9 of the Camel 3rd edition for how to load and access nested 
data structures.  In my opinion it just gets to be to much of a hassle after 3 
levels of nesting.  So try to re-think your approach if it's too much to deal 
with, or check out the various Data modules on CPAN.

Regards,

Nathanael Kuipers


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




check process state

2002-09-30 Thread Sylvanie, Jean-Pierre

Hi guys,

I want to do a sub that check if a process is sleeping
or not...

I wrote the following sub, but I was wondering if it
was possible to to it without shell calls...

Thanks,
jp.



sub isSleeping{
  
  # get PID of process to check
  my $pid = shift || return 0;

  # get user name
  my $user;
  if(`id` =~ /\((\w+)\)/) {$user=$1};

  # the 7th field (starting at 0) of top output is the state.
  # top -b (for batch mode) -U $user (processes of $user).
  my $state = (split /\s+/, (grep {/$pid/} `top -b -U $user`)[0])[7];
  
  return $state eq "sleep";  
}



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




What Type Of Data Structure Is This?

2002-09-30 Thread Ken Hammer


 A strange question.

 I'm using the following data structure to
store information from a data base query:

$tablename{"$table"} = {
"table_name"=> ["$table"],
"index_name"=> ["$index_name"],
"columns"   => ["@column_name"],
"type"  => ["$index_type"],
"tablespace"=> ["$tablespace_name"]

 This works great and I can later extract the info
from this structure. I have 2 questions. What type of
structure is this and how do I add to it?

 When I try to add more info from a subsequent query like
this:

$tablename{$table} = {
"con_name"  =>  ["$constraint_name"],
"con_type"  =>  ["$type"],
"rem_con_name"  =>  ["$r_constraint_name"],
"created_by"=>  ["$generated"]
};

 I lose all the previous information, so that only the above
is now stored.
 What have I done, how do I do what I want, and am I in over my head?

-- 
Ken

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




RE: Microsoft Exchange

2002-09-30 Thread Timothy Johnson


There is a new module that was just introduced called Win32::Exchange that
can do that very easily.  If you are using ActiveState's ActivePerl then you
can get it via PPM at Dave Roth's repository.

PPM> set repository dave http://www.roth.net/perl/packages
PPM> set save
PPM> install win32-exchange



-Original Message-
From: Ramprasad A Padmanabhan [mailto:[EMAIL PROTECTED]]
Sent: Monday, September 30, 2002 6:02 AM
To: [EMAIL PROTECTED]; Steve
Cc: [EMAIL PROTECTED]
Subject: Re: Microsoft Exchange


Steve wrote:
> Can anyone tell me if it's possible to create a mailbox
> in Exchange 5.5 from perl?
> 
>   Thanks,
>Steve
> 
> 

I Dont think that will be the straightforward
Why dont u use a mailer and send the mails using SMTP instead of 
directly creating the mailbox

U could use Net::SMTP if you do care

Ram


-- 
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: AW: Exiting loop to higher level

2002-09-30 Thread James Edward Gray II

Sorry, but this isn't accurate.  Try it and I think you'll be 
surprised.  The next() subroutine takes you to the next iteration of 
the enclosing LOOP.  Control statements, like if, are not loops and 
thus have nothing to do with where next() sends you.

When you do have two loops and want to break to the outer one, you can 
use a label.

LABEL:  while (SOMETHING) {
while (SOMETHING_ELSE) {
next LABEL if SOME_REASON;  # breaks to the first loop
}
}

But, this is not needed in your example, if I'm understanding your 
question correctly.  Good luck.

James Gray

On Monday, September 30, 2002, at 09:45  AM, Hughes, James wrote:

> Thanks,
>
> but I need something that will take me past the first "if" 
> statement...
> Something that itterates past the if, and tells the while to go on 
> with the
> next lump of data...
> "next" will only break the inner "if" loop.
>
> best regards,
>
> James Hughes
>
>
>
> -Ursprungliche Nachricht-
> Von: James Edward Gray II [mailto:[EMAIL PROTECTED]]
> Gesendet: Montag, 30. September 2002 16:34
> An: Hughes, James
> Cc: [EMAIL PROTECTED]; Jones, Jeremy
> Betreff: Re: Exiting loop to higher level
>
>
> Drop the double.  'next' is what you're looking for.
>
> James Gray
>
> On Monday, September 30, 2002, at 09:28  AM, Hughes, James wrote:
>
>> Hi folks,
>>
>>
>> Quick question I left my books at home. I am sure I'e seen a way
>> to next
>> a loop to a higher level.
>>
>>
>> Let me explain..
>>
>>
>> while <> {
>>
>>  if ($_ =~ /something I need to find/) {
>>
>>  if ($_=~/something that tells me I need to look
> elsewhere/)
>> {
>>  doublenext; # exits to next itteration of while
>> loop :-) Bypassing higher IF.
>>  }
>>  else {
>>  do something cool;
>>  }
>>  }
>>  else  {
>>  do something less cool;
>>  }
>>
>> }
>>
>> I know there is not a function "doublenext", but what can I do to get
>> the
>> functionality of the fabled "doublenext"?
>>
>> Thanks.
>>
>> At work having writers block
>>
>>
>>
>> James Hughes
>>
>>
>> -- 
>> 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]




AW: Exiting loop to higher level

2002-09-30 Thread Hughes, James

Thanks, 

but I need something that will take me past the first "if" statement...
Something that itterates past the if, and tells the while to go on with the
next lump of data...
"next" will only break the inner "if" loop.

best regards,

James Hughes



-Ursprungliche Nachricht-
Von: James Edward Gray II [mailto:[EMAIL PROTECTED]]
Gesendet: Montag, 30. September 2002 16:34
An: Hughes, James
Cc: [EMAIL PROTECTED]; Jones, Jeremy
Betreff: Re: Exiting loop to higher level


Drop the double.  'next' is what you're looking for.

James Gray

On Monday, September 30, 2002, at 09:28  AM, Hughes, James wrote:

> Hi folks,
>
>
> Quick question I left my books at home. I am sure I'e seen a way 
> to next
> a loop to a higher level.
>
>
> Let me explain..
>
>
> while <> {
>
>   if ($_ =~ /something I need to find/) {
>
>   if ($_=~/something that tells me I need to look 
elsewhere/)
> {
>   doublenext; # exits to next itteration of while
> loop :-) Bypassing higher IF.
>   }
>   else {
>   do something cool;
>   }
>   }
>   else  {
>   do something less cool;
>   }
>
> }
>
> I know there is not a function "doublenext", but what can I do to get 
> the
> functionality of the fabled "doublenext"?
>
> Thanks.
>
> At work having writers block
>
>
>
> James Hughes
>
>
> -- 
> 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: $1, $2, $3, ... as array

2002-09-30 Thread Jeff 'japhy' Pinyan

On Sep 30, Jenda Krynicky said:

>Are the $n variables accessible as an array as well?

You can use the @- and @+ arrays (which hold offsets) to do your work:

  for (0 .. $#-) {
# do something with substr($X, $-[$_], $+[$_] - $-[$_])
  }

-- 
Jeff "japhy" Pinyan  [EMAIL PROTECTED]  http://www.pobox.com/~japhy/
RPI Acacia brother #734   http://www.perlmonks.org/   http://www.cpan.org/
** Look for "Regular Expressions in Perl" published by Manning, in 2002 **
 what does y/// stand for?   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]




Re: Exiting loop to higher level

2002-09-30 Thread James Edward Gray II

Drop the double.  'next' is what you're looking for.

James Gray

On Monday, September 30, 2002, at 09:28  AM, Hughes, James wrote:

> Hi folks,
>
>
> Quick question I left my books at home. I am sure I'e seen a way 
> to next
> a loop to a higher level.
>
>
> Let me explain..
>
>
> while <> {
>
>   if ($_ =~ /something I need to find/) {
>
>   if ($_=~/something that tells me I need to look elsewhere/)
> {
>   doublenext; # exits to next itteration of while
> loop :-) Bypassing higher IF.
>   }
>   else {
>   do something cool;
>   }
>   }
>   else  {
>   do something less cool;
>   }
>
> }
>
> I know there is not a function "doublenext", but what can I do to get 
> the
> functionality of the fabled "doublenext"?
>
> Thanks.
>
> At work having writers block
>
>
>
> James Hughes
>
>
> -- 
> 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]




Exiting loop to higher level

2002-09-30 Thread Hughes, James

Hi folks,


Quick question I left my books at home. I am sure I'e seen a way to next
a loop to a higher level.


Let me explain..


while <> {

if ($_ =~ /something I need to find/) { 

if ($_=~/something that tells me I need to look elsewhere/)
{
doublenext; # exits to next itteration of while
loop :-) Bypassing higher IF.
}
else {
do something cool;
}
}
else  {
do something less cool;
}

}

I know there is not a function "doublenext", but what can I do to get the
functionality of the fabled "doublenext"?

Thanks.

At work having writers block



James Hughes


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




AW: AW: how to know weather perl script is already running?

2002-09-30 Thread Theuerkorn Johannes

Jea, thats it! Thats exactly what i had in mind! 

Thank you very much! This List and it´s members are excellent!

Greets Johannes

-Ursprüngliche Nachricht-
Von: Robin Cragg [mailto:[EMAIL PROTECTED]]
Gesendet: Montag, 30. September 2002 15:10
An: Theuerkorn Johannes
Betreff: Re: AW: how to know weather perl script is already running?


Hi,

firstly, the problem with your script is most likely that your path is 
wrong (don't forget the `` or system open a shell and then run the command. 
That means you should try to specify all the patsh in your command line. 
Secondly, I would not use grep if I were you.

ps -wfaux | grep myproc

will produce two lines. The first is myprog, the second is \_ grep 
myprog.  :-)  Linux is cute like that. It's much simpler to do it all in 
PERL. I would do the PS too, but I've not seen a module for it yet. This 
code works.


open PS, "/bin/ps -wwfaux |";
@PS = ;
close PS;

my $flag = 0;

foreach (@PS) {
 $flag++ if (/$0/);
}


die "$0: Process already running!\n" if ($flag > 1);

while (1) {
 sleep 10;
}

It's also neater to use $0 so you can change your script name.


R


At 14:35 30/09/2002 +0200, you wrote:
>Hi Robin, that was the way i wanted to do it, but i got problems with it. I
>tried to use:
>
>#!/bin/sh
>if ! [`ps ax|grep "perl /home/user1/DiREx/generate_database/"`]
>then `scripttorun`
>fi
>
>but it returns the following error:
>
>./call_script: [23038: command not found
>
>It seems to use the returned process id as command...
>
>So how to write such a script?
>
>Greets Johannes
>
>-Ursprüngliche Nachricht-
>Von: Robin Cragg [mailto:[EMAIL PROTECTED]]
>Gesendet: Montag, 30. September 2002 14:25
>An: Theuerkorn Johannes; '[EMAIL PROTECTED]'
>Betreff: Re: how to know weather perl script is already running?
>
>
>There are two easy ways...
>
>
>If your file creates a lock file when it starts and removes it when it
>finishes, a chec to see if the file exists will tell you if the script is
>already running./
>
>On linux / unix systems do a ps and looks for any occurrances of your
>script name. If there are more than one, then die
>
>
>R
>
>
>At 11:18 30/09/2002 +0200, Theuerkorn Johannes wrote:
> >Hello List,
> >
> >i have a perl script that i have running from a cron Job. It usually opens
> >every 4 hours. But sometimes it takes the script longer to execute its job
> >so after cron opens up the perl script as usual, i have two perl jobs
>running.
> >Is there any possibility to check weather the script is already running?
> >Maybe i can use a system command in the crontab?
> >
> >any help welcoe
> >
> >greets Johannes
> >
> >--
> >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: SQL Table Rows

2002-09-30 Thread Cleiton L. Siqueira

Dan,

In MySQL I don't know how you can do, but I believe that in theory is the same thing.

#!/usr/bin/perl

use Pg;
$db= Pg::connectdb("dbname=database");
open (FILE, ">>/var/log/file.log");

$result = $db->exec("SELECT * FROM table;");
for($i=0;$i<$result->ntuples;$i++) {

$id = $result->getvalue($i,0);
$myid2 = $result->getvalue($i,1);
$myid3 = $result->getvalue($i,2);
print FILE "Line nº $i: $id - myid2 - myid3\n";

}
close(FILE);

Na Sunday, 29 de September de 2002 às 09:54:36 PM, dan escreveu:

> right, this is like an outline to what i want to be able to achieve..
> 
> -- my table ---
> row # : id , myid2 , myid3
> ---
> row 1 : 1 , item 1 , item 2
> row 2 : 2 , item 3 , item 4
> row 3 : 3 , item 5 , item 6
> row 4 : 4 , item 7 , item 8
> 
> I'm using DBI mysql..
> 
> What i want to be able to do, is search through the table using the row
> number, rather than the column id, "myid1", "myid2", and "myid3". this is
> how i'm currently going through the database row by row to get all the
> information:
> 
> __ START __
> $id = 1;
> $sth = $dbh->prepare("SELECT * FROM table WHERE id=$id");
> $sth->execute;
> @ary = $sth->fetchrow_array;
> while ($ary[0] ne "") {
> # here i set up the variables which contain the data from the table,
> which will be used later on,
> $id++;
> $sth = $dbh->prepare("SELECT * FROM table WHERE id=$id");
> $sth->execute;
> @ary = $sth->fetchrow_array;
> }
> __ END __
> that's all very well if all id's are there, but if say ID 2 was deleted
> because the information was no longer needed, the while loop would break
> straight after ID 1, since there's no data corresponding to ID 2. The table
> would end up like this:
> 
> -- my table ---
> row # : id , myid2 , myid3
> ---
> row 1 : 1 , item 1 , item 2
> row 2 : 3 , item 5 , item 6
> row 3 : 4 , item 7 , item 8
> 
> what i want to be able to do is go through the table row by row and select
> all the data from each row, rather than have to select by id. any better
> clues now?
> 
> and how is it possible to find out how many rows a table has?
> 
> Dan
> 
> 
> "Cleiton L. Siqueira" <[EMAIL PROTECTED]> wrote in message
> [EMAIL PROTECTED]">news:[EMAIL PROTECTED]...
> > Dear Dan,
> >
> > I don't know if I understood what you really want. Therefore I will try to
> help, ok.
> >
> > I use Postgres as Database.
> >
> > You can find out how many rows have in a table after you run a SQL like
> this.
> >
> > #!/usr/bin/perl
> >
> > use Pg;
> > $db= Pg::connectdb("dbname=database");
> >
> > # This is a way to do it.
> >
> > $result = $db->exec("SELECT * FROM table;");
> > $number_of_row = $result->ntuples;
> > print $number_of_row;
> >
> > # This is another way to do it.
> >
> > $result = $db->exec("SELECT count(*) FROM table;");
> > $number_of_row = $result->getvalue(0, 0);
> > print $number_of_row;
> >
> > Best regards,
> >
> > Na Sunday, 29 de September de 2002 às 09:44:40 PM, dan escreveu:
> >
> > > How is it possible to cycle through an SQL table row by row, without
> having
> > > to increment an ID by 1 in a while loop and go
> > > SELECT * FROM table WHERE id=$id
> > > ?
> > > And how can I find out how many rows are in the table?
> > >
> > > Dan
> > >
> > >
> > >
> > > --
> > > To unsubscribe, e-mail: [EMAIL PROTECTED]
> > > For additional commands, e-mail: [EMAIL PROTECTED]
> > >
> > >
> > >
> >
> >
> >
> > Cleiton L. Siqueira
> > Colégio Monjolo
> > [EMAIL PROTECTED]
> > (0xx45) 520-1915
> >
> > Esta mensagem foi enviada pelo sistema MONJOLO WEBMAIL
> >
> > http://www.colegiomonjolo.com.br
> >
> 
> 
> 
> -- 
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> 
> 
> 



Cleiton L. Siqueira
Colégio Monjolo
[EMAIL PROTECTED]
(0xx45) 520-1915

Esta mensagem foi enviada pelo sistema MONJOLO WEBMAIL

http://www.colegiomonjolo.com.br


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




RE: how to know weather perl script is already running?

2002-09-30 Thread Jeff AA


> -Original Message-
> From: Theuerkorn Johannes [mailto:[EMAIL PROTECTED]] 
> Sent: 30 September 2002 10:18
> To: '[EMAIL PROTECTED]'
> Subject: how to know weather perl script is already running?
> 
> 
> Hello List,
> 
> i have a perl script that i have running from a cron Job. It 
> usually opens every 4 hours. But sometimes it takes the 
> script longer to execute its job so after cron opens up the 
> perl script as usual, i have two perl jobs running.
> Is there any possibility to check weather the script is 
> already running? Maybe i can use a system command in the crontab?
> 
> any help welcoe 
> 
> greets Johannes
> 
> -- 

We use the following subs to do this on Linux:
example call:

# In your main program:
# This will exit 0 if there are no available instances
my $instance = getInstance("reporter",3); # maximum of 3 reporters



#

-
# Get an instance name and lock
# Used to control the maximum number of instances for a specified
process
# e.g.  reporter.pl
sub getInstance {
  my $name  = shift;
  my $max   = shift;
  my $msg   = '';

  $max ||= 1;
  $msg ||= "No available instances for '$name' [maximum $max already
locked]";

  my $locked = '';
  foreach my $instance ( 1..$max ) {
my $token = "$name$instance";
$locked = $token if lockToken($token);
last if $locked;
  }

  # Note that we die gracefully
  print "\n$msg\n"  unless $locked;
  exit 0 unless $locked;

  return $locked;
}
#

-
sub lockToken {
  my $token = shift;

  mkdir "/var/lock" unless -d "/var/lock";
  mkdir "/var/lock/mylocks" unless -d "/var/lock/mylocks";

  my $token_file = "/var/lock/mylocks/$token";
  open(FH, ">$token_file") ||
LogFatal("Cannot open token locking file '$token_file' for writing:
$OS_ERROR");

  # Return success or failure depending on whether we can exclusively
lock the file
  return flock(FH, LOCK_EX | LOCK_NB);

}



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




Re: Can Someone Help Me?

2002-09-30 Thread Frank Wiles

 .--[ Bootscat wrote (2002/09/30 at 09:13:19) ]--
 | 
 |  I'm setting up a list for free and pro members.
 |  I want the pro members to be able to mail daily. I have this part working.
 |  
 |  I want the free members to only be able to mail every 4 Days to the list.
 |  
 |  Using the localtime(time) = 
 |  (second,minute,hour,day-of-month,month,year,day-of-week,day-of-year) 
 |  
 |  Can someone tell me how to code it to only allow it to mail every 3 days?
 |  
 `-

Without knowing how your E-mail mailing list software works, this 
may not even be possible.  However to for an easy way to get every
third day I would suggest you look at Date::Calc or Date::Manip
modules on cpan.org as they have several easy functions for working
with dates. 

 -
   Frank Wiles <[EMAIL PROTECTED]>
   http://frank.wiles.org
 -


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




RE: SQL Table Rows

2002-09-30 Thread Jeff AA

> -Original Message-
> From: dan [mailto:[EMAIL PROTECTED]] 
> Sent: 30 September 2002 13:55
> To: [EMAIL PROTECTED]
> Subject: Re: SQL Table Rows
> 
> 
snip

> __ START __
> $id = 1;
> $sth = $dbh->prepare("SELECT * FROM table WHERE id=$id");
> $sth->execute;
> @ary = $sth->fetchrow_array;
> while ($ary[0] ne "") {
> # here i set up the variables which contain the data from 
> the table,
> which will be used later on,
> $id++;
> $sth = $dbh->prepare("SELECT * FROM table WHERE id=$id");
> $sth->execute;
> @ary = $sth->fetchrow_array;
> }
> __ END __
> that's all very well if all id's are there, but if say ID 2 
> was deleted
> because the information was no longer needed, the while loop 
> would break
> straight after ID 1, since there's no data corresponding to 
> ID 2. The table

maybe you really mean something like this:

$sth = $dbh->prepare("SELECT * FROM table");
$sth->execute;
while ( my ( @ary ) = $sth->fetchrow_array ) {
  # set up your variables
  # and do your processing
  print "Got: @ary\n";
}

There is no WHERE clause on the select - you will get every row back,
and there is no need to execute another select, you just iterate through
processing each row.

This is the simplest solution that I could make, cutting and pasting
your own code.

Depending on what you are really doing, look at the fetchrow_hash - you
can then work with named fields, more robust and easier to maintain.

regards
Jeff


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




Re: SQL Table Rows

2002-09-30 Thread Gary Stainburn

Hi Dan,

I'm used to PostgreSQL, but using DBI, that shouldn't matter for what we're 
doing.

On Monday 30 Sep 2002 1:54 pm, dan wrote:
> right, this is like an outline to what i want to be able to achieve..
>
> -- my table ---
> row # : id , myid2 , myid3
> ---
> row 1 : 1 , item 1 , item 2
> row 2 : 2 , item 3 , item 4
> row 3 : 3 , item 5 , item 6
> row 4 : 4 , item 7 , item 8
> 
> I'm using DBI mysql..
>
> What i want to be able to do, is search through the table using the row
> number, rather than the column id, "myid1", "myid2", and "myid3". this is
> how i'm currently going through the database row by row to get all the
> information:
>
> __ START __
> $id = 1;
> $sth = $dbh->prepare("SELECT * FROM table WHERE id=$id");
> $sth->execute;
> @ary = $sth->fetchrow_array;
> while ($ary[0] ne "") {
> # here i set up the variables which contain the data from the table,
> which will be used later on,
> $id++;
> $sth = $dbh->prepare("SELECT * FROM table WHERE id=$id");
> $sth->execute;
> @ary = $sth->fetchrow_array;
> }
> __ END __

$sth=$dbh->prepare("SELECT * from table;");
$sth->execute || die "select failed: $DBI::errstr";
while (@ary=$sth->fetchrow_array) {
  # do your stuff
}

I've not tested this, but that's all you should need to do.

Gary

> that's all very well if all id's are there, but if say ID 2 was deleted
> because the information was no longer needed, the while loop would break
> straight after ID 1, since there's no data corresponding to ID 2. The table
> would end up like this:
>
> -- my table ---
> row # : id , myid2 , myid3
> ---
> row 1 : 1 , item 1 , item 2
> row 2 : 3 , item 5 , item 6
> row 3 : 4 , item 7 , item 8
> 
> what i want to be able to do is go through the table row by row and select
> all the data from each row, rather than have to select by id. any better
> clues now?
>
> and how is it possible to find out how many rows a table has?
>
> Dan
>
>
> "Cleiton L. Siqueira" <[EMAIL PROTECTED]> wrote in message
> [EMAIL PROTECTED]">news:[EMAIL PROTECTED]...
>
> > Dear Dan,
> >
> > I don't know if I understood what you really want. Therefore I will try
> > to
>
> help, ok.
>
> > I use Postgres as Database.
> >
> > You can find out how many rows have in a table after you run a SQL like
>
> this.
>
> > #!/usr/bin/perl
> >
> > use Pg;
> > $db= Pg::connectdb("dbname=database");
> >
> > # This is a way to do it.
> >
> > $result = $db->exec("SELECT * FROM table;");
> > $number_of_row = $result->ntuples;
> > print $number_of_row;
> >
> > # This is another way to do it.
> >
> > $result = $db->exec("SELECT count(*) FROM table;");
> > $number_of_row = $result->getvalue(0, 0);
> > print $number_of_row;
> >
> > Best regards,
> >
> > Na Sunday, 29 de September de 2002 às 09:44:40 PM, dan escreveu:
> > > How is it possible to cycle through an SQL table row by row, without
>
> having
>
> > > to increment an ID by 1 in a while loop and go
> > > SELECT * FROM table WHERE id=$id
> > > ?
> > > And how can I find out how many rows are in the table?
> > >
> > > Dan
> > >
> > >
> > >
> > > --
> > > To unsubscribe, e-mail: [EMAIL PROTECTED]
> > > For additional commands, e-mail: [EMAIL PROTECTED]
> >
> > Cleiton L. Siqueira
> > Colégio Monjolo
> > [EMAIL PROTECTED]
> > (0xx45) 520-1915
> >
> > Esta mensagem foi enviada pelo sistema MONJOLO WEBMAIL
> >
> > http://www.colegiomonjolo.com.br

-- 
Gary Stainburn
 
This email does not contain private or confidential material as it
may be snooped on by interested government parties for unknown
and undisclosed purposes - Regulation of Investigatory Powers Act, 2000 


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




Can Someone Help Me?

2002-09-30 Thread Bootscat

I'm setting up a list for free and pro members.
I want the pro members to be able to mail daily. I have this part working.

I want the free members to only be able to mail every 4 Days to the list.

Using the localtime(time) = 
(second,minute,hour,day-of-month,month,year,day-of-week,day-of-year) 

Can someone tell me how to code it to only allow it to mail every 3 days?

Thanks
Dan



RE: Can I append @INC before use

2002-09-30 Thread NYIMI Jose (BMB)

set PERL5LIB environment varible to 
/tmp/foo then you will be able to use 'use BAR;'

Or give a look at

'perldoc lib'

José.


> -Original Message-
> From: Ramprasad A Padmanabhan [mailto:[EMAIL PROTECTED]] 
> Sent: Monday, September 30, 2002 2:53 PM
> To: [EMAIL PROTECTED]
> Subject: Can I append @INC before use 
> 
> 
> Hello All,
> 
> I have a perl script which has
> 
> (assuming BAR.pm is in /tmp/foo/)
> 
> 
> BEGIN {
>  push @::INC , "/tmp/foo";
>  # use  BAR;  # Does not work
>  require BAR;  # Works fine
> }
> 
> Can I get to use 'use' instead of require any how
> 
> Thanx
> Ram
> 
> 
> -- 
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> 
> 


 DISCLAIMER 

"This e-mail and any attachment thereto may contain information which is confidential 
and/or protected by intellectual property rights and are intended for the sole use of 
the recipient(s) named above. 
Any use of the information contained herein (including, but not limited to, total or 
partial reproduction, communication or distribution in any form) by other persons than 
the designated recipient(s) is prohibited. 
If you have received this e-mail in error, please notify the sender either by 
telephone or by e-mail and delete the material from any computer".

Thank you for your cooperation.

For further information about Proximus mobile phone services please see our website at 
http://www.proximus.be or refer to any Proximus agent.


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




Re: NET::Netrc

2002-09-30 Thread Ramprasad A Padmanabhan

I havent used this module but look at catching errors

it "could be"  something  like this
  $mach = Net::Netrc->lookup('Name') || die Net::Netrc->error()

Bye the way you have you created your .netrc file




William Black wrote:
> Hello All,
> 
> I'm trying to use the Netrc module to read from the netrc file.  Anyone 
> familiar with it?  Below is the code.  I'm getting an error stating
> 
> Can't call method "password" on an undefined value at ftp.pl line 28.
> 
> Here is the code.  Anyone see the problem.
> 
> #Get the username and passwd of the remote mach.
> $mach = Net::Netrc->lookup('Name');
> 
> 28:$usr = $mach->login();
> #$passwd = $mach->password();
> 
> print"The usr is -> $usr\n";
> #print"The passwd is -> $passwd\n";
> 
> 
> 
> 
> William Black
> 
> 
> 
> _
> MSN Photos is the easiest way to share and print your photos: 
> http://photos.msn.com/support/worldwide.aspx
> 



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




Re: Postgres Select

2002-09-30 Thread Cleiton L. Siqueira

Dear friend, 

I don't know if I've figured out what you want, but I've written a script for you. 
You can test it! 
Warning!!! I didn't test it, ok! 

So. It's the following. 

#!/usr/bin/perl 

use Pg; 

# In  you must change to your database name. 

$conn = Pg::connectdb("dbname="); 
open (YES, ">>/var/log/this_customer_are.log"); 
open (NO, ">>/var/log/this_customer_arent.log"); 

# In  and  you must to change to first table and coluna of your 
database. 
# In  and  you must to change to second table and coluna of your 
database. 

$result_first = $conn->exec("select * from  order by ;"); 
$result_second = $conn->exec("select * from  order by ;"); 

for($i=0;$i<$result_first->ntuples;$i++) { 

$customer_number_first = $result_first->getvalue($i, ); 
for($count=0;$count<$result_second->ntuples;$count++) { 

$customer_number_second = $result_first->getvalue($count, ); 
if ($customer_number_first == $customer_number_second) { 

$costumer_found = 1; 

} else { 

$costumer_found = 0; 

} 

} 

if ($costumer_found == 1) { 

print YES "$customer_number_first\n"; 

} elsif ($costumer_found == 0) { 

print NO "$customer_number_first\n"; 

} 

} 
close(YES); 
close(NO); 

Best regards, 




Cleiton L. Siqueira
Colégio Monjolo
[EMAIL PROTECTED]
(0xx45) 520-1915

Esta mensagem foi enviada pelo sistema MONJOLO WEBMAIL

http://www.colegiomonjolo.com.br


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




Re: SQL Table Rows

2002-09-30 Thread dan

right, this is like an outline to what i want to be able to achieve..

-- my table ---
row # : id , myid2 , myid3
---
row 1 : 1 , item 1 , item 2
row 2 : 2 , item 3 , item 4
row 3 : 3 , item 5 , item 6
row 4 : 4 , item 7 , item 8

I'm using DBI mysql..

What i want to be able to do, is search through the table using the row
number, rather than the column id, "myid1", "myid2", and "myid3". this is
how i'm currently going through the database row by row to get all the
information:

__ START __
$id = 1;
$sth = $dbh->prepare("SELECT * FROM table WHERE id=$id");
$sth->execute;
@ary = $sth->fetchrow_array;
while ($ary[0] ne "") {
# here i set up the variables which contain the data from the table,
which will be used later on,
$id++;
$sth = $dbh->prepare("SELECT * FROM table WHERE id=$id");
$sth->execute;
@ary = $sth->fetchrow_array;
}
__ END __
that's all very well if all id's are there, but if say ID 2 was deleted
because the information was no longer needed, the while loop would break
straight after ID 1, since there's no data corresponding to ID 2. The table
would end up like this:

-- my table ---
row # : id , myid2 , myid3
---
row 1 : 1 , item 1 , item 2
row 2 : 3 , item 5 , item 6
row 3 : 4 , item 7 , item 8

what i want to be able to do is go through the table row by row and select
all the data from each row, rather than have to select by id. any better
clues now?

and how is it possible to find out how many rows a table has?

Dan


"Cleiton L. Siqueira" <[EMAIL PROTECTED]> wrote in message
[EMAIL PROTECTED]">news:[EMAIL PROTECTED]...
> Dear Dan,
>
> I don't know if I understood what you really want. Therefore I will try to
help, ok.
>
> I use Postgres as Database.
>
> You can find out how many rows have in a table after you run a SQL like
this.
>
> #!/usr/bin/perl
>
> use Pg;
> $db= Pg::connectdb("dbname=database");
>
> # This is a way to do it.
>
> $result = $db->exec("SELECT * FROM table;");
> $number_of_row = $result->ntuples;
> print $number_of_row;
>
> # This is another way to do it.
>
> $result = $db->exec("SELECT count(*) FROM table;");
> $number_of_row = $result->getvalue(0, 0);
> print $number_of_row;
>
> Best regards,
>
> Na Sunday, 29 de September de 2002 às 09:44:40 PM, dan escreveu:
>
> > How is it possible to cycle through an SQL table row by row, without
having
> > to increment an ID by 1 in a while loop and go
> > SELECT * FROM table WHERE id=$id
> > ?
> > And how can I find out how many rows are in the table?
> >
> > Dan
> >
> >
> >
> > --
> > To unsubscribe, e-mail: [EMAIL PROTECTED]
> > For additional commands, e-mail: [EMAIL PROTECTED]
> >
> >
> >
>
>
>
> Cleiton L. Siqueira
> Colégio Monjolo
> [EMAIL PROTECTED]
> (0xx45) 520-1915
>
> Esta mensagem foi enviada pelo sistema MONJOLO WEBMAIL
>
> http://www.colegiomonjolo.com.br
>



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




re: NET::Netrc

2002-09-30 Thread William Black

Hello All,

I'm trying to use the Netrc module to read from the netrc file.  Anyone 
familiar with it?  Below is the code.  I'm getting an error stating

Can't call method "password" on an undefined value at ftp.pl line 28.

Here is the code.  Anyone see the problem.

#Get the username and passwd of the remote mach.
$mach = Net::Netrc->lookup('Name');

28:$usr = $mach->login();
#$passwd = $mach->password();

print"The usr is -> $usr\n";
#print"The passwd is -> $passwd\n";




William Black



_
MSN Photos is the easiest way to share and print your photos: 
http://photos.msn.com/support/worldwide.aspx


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




Re: Microsoft Exchange

2002-09-30 Thread Ramprasad A Padmanabhan

Steve wrote:
> Can anyone tell me if it's possible to create a mailbox
> in Exchange 5.5 from perl?
> 
>   Thanks,
>Steve
> 
> 

I Dont think that will be the straightforward
Why dont u use a mailer and send the mails using SMTP instead of 
directly creating the mailbox

U could use Net::SMTP if you do care

Ram


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




Re: Finding if a module is already 'require'd

2002-09-30 Thread Jenda Krynicky

From:   Ramprasad A Padmanabhan <[EMAIL PROTECTED]>
> How do I find in a function if a particular module is already loaded

Look at the %INC hash.

Jenda
=== [EMAIL PROTECTED] == http://Jenda.Krynicky.cz ==
There is a reason for living. There must be. I've seen it somewhere.
It's just that in the mess on my table ... and in my brain
I can't find it.
--- me


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




Can I append @INC before use

2002-09-30 Thread Ramprasad A Padmanabhan

Hello All,

I have a perl script which has

(assuming BAR.pm is in /tmp/foo/)


BEGIN {
 push @::INC , "/tmp/foo";
 # use  BAR;  # Does not work
 require BAR;  # Works fine
}

Can I get to use 'use' instead of require any how

Thanx
Ram


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




Re: SQL Table Rows

2002-09-30 Thread Cleiton L. Siqueira

Dear Dan,

I don't know if I understood what you really want. Therefore I will try to help, ok.

I use Postgres as Database.

You can find out how many rows have in a table after you run a SQL like this.

#!/usr/bin/perl

use Pg;
$db= Pg::connectdb("dbname=database");

# This is a way to do it.

$result = $db->exec("SELECT * FROM table;");
$number_of_row = $result->ntuples;
print $number_of_row;

# This is another way to do it.

$result = $db->exec("SELECT count(*) FROM table;");
$number_of_row = $result->getvalue(0, 0);
print $number_of_row;

Best regards,

Na Sunday, 29 de September de 2002 às 09:44:40 PM, dan escreveu:

> How is it possible to cycle through an SQL table row by row, without having
> to increment an ID by 1 in a while loop and go
> SELECT * FROM table WHERE id=$id
> ?
> And how can I find out how many rows are in the table?
> 
> Dan
> 
> 
> 
> -- 
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> 
> 
> 



Cleiton L. Siqueira
Colégio Monjolo
[EMAIL PROTECTED]
(0xx45) 520-1915

Esta mensagem foi enviada pelo sistema MONJOLO WEBMAIL

http://www.colegiomonjolo.com.br


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




Re: how to know weather perl script is already running?

2002-09-30 Thread Robin Cragg

There are two easy ways...


If your file creates a lock file when it starts and removes it when it 
finishes, a chec to see if the file exists will tell you if the script is 
already running./

On linux / unix systems do a ps and looks for any occurrances of your 
script name. If there are more than one, then die


R


At 11:18 30/09/2002 +0200, Theuerkorn Johannes wrote:
>Hello List,
>
>i have a perl script that i have running from a cron Job. It usually opens 
>every 4 hours. But sometimes it takes the script longer to execute its job 
>so after cron opens up the perl script as usual, i have two perl jobs running.
>Is there any possibility to check weather the script is already running? 
>Maybe i can use a system command in the crontab?
>
>any help welcoe
>
>greets Johannes
>
>--
>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]




  1   2   >