Re: cgi_lib'maxdata

2003-10-28 Thread SRef
P Libardi wrote:
Hi, I've the need to limit the amount of data a user can send through
POST method. Actually I've just added the following instruction:
cgi_lib'maxdata = 1;
Is this enough? What happens if a user sends data which overflow this
limit? And what about size limit for data sent through GET method or any
other method?
Thanks, Paolo
Why not try before you ask ?

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


cgi:mail program

2003-10-28 Thread Gautham Hegde



hi
i have a form in which various fields r filled comments,name,email id(mailto:)..etc
then i have to mail the contents in the form to the persons mail id in the 
form
how to parse the form and arrange the contents to beappeared inthe 
mail
plzz its urgent
looking forward for u r reply
gautham
"Have a heart that never hardens, and a temper that never tires, and a 
touch that never hurts." 

Blank Bkgrd.gif

Re: cgi_lib'maxdata

2003-10-28 Thread p . libardi
On martedì 28 ottobre 2003, alle 10:15, SRef wrote:
 P Libardi wrote:
 Hi, I've the need to limit the amount of data a user can send through
 POST method. Actually I've just added the following instruction:
 cgi_lib'maxdata = 1;
 Is this enough? What happens if a user sends data which overflow this
 limit? And what about size limit for data sent through GET method or any
 other method?
 Thanks, Paolo
 
 Why not try before you ask ?

I though this mailing list was for beginners, and as I've started using
CGI Perl just a week ago, I'm not still so able to send POST oversized
for an hacking attack, to try my scripts. I searched the net for the
informations I asked about, but wasn't able to find any more than what I
wrote in my mail. So thnaks for your hint, I tried anything I was able
to try, then I asked the mailing list for an help.
Paolo

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



capturing output of a shell comand

2003-10-28 Thread BetaGamma

Hi everyone

I have been trying to capture the output of a shell command (say ls or echo *) in a 
variable but all i have been able to capture is the return status of system comman 
which is 0.

I also tried changing the default output handler from STDOUT to the  filehandle of a 
file I have created hoping tha the optput of my chell command will be captured by the 
new filehandler but all in vain.

This problem is killing me.

Please help.

Thanks

Pawan



-
Do you Yahoo!?
Exclusive Video Premiere - Britney Spears

Re: cgi_lib'maxdata

2003-10-28 Thread fliptop
On Tue, 28 Oct 2003 at 10:52, [EMAIL PROTECTED] opined:

:On martedì 28 ottobre 2003, alle 10:15, SRef wrote:
: Why not try before you ask ?
:
:I though this mailing list was for beginners, and as I've started using
:CGI Perl just a week ago, I'm not still so able to send POST oversized
:for an hacking attack, to try my scripts. I searched the net for the
:informations I asked about, but wasn't able to find any more than what I
:wrote in my mail. So thnaks for your hint, I tried anything I was able
:to try, then I asked the mailing list for an help.

if you're a perl cgi beginner, you should be using the CGI.pm module.

http://search.cpan.org/~lds/CGI.pm-3.00/

read the documentation about the $CGI::POST_MAX variable.  it's used to 
limit the amount of data that can be posted.


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



CGI::Framework?

2003-10-28 Thread PerlDiscuss - Perl Newsgroups and mailing lists
Where can I find documentation, tutorials, examples for CGI::Framework -
the cpan documentation is not enough for me :)


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



CGI::Framework?

2003-10-28 Thread PerlDiscuss - Perl Newsgroups and mailing lists
Hello!

I'm going to write my first perl script and I need Session handling,
authentification and a simple cgi application.

I tried to use CGI::Framework but I hardly find any documentation about
this module except the one at cpan. I tried the example but when I submit
from my enterusername htm the Application doesn't call the
validate_enterusername like it is told in the documentation.


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



Re: Issue

2003-10-28 Thread Rob Dixon
Bruce Phillip wrote:

  Thanks for the feedback, The only thing is that $O^ will only
  work if the scripts are going to be invoke on that system.

  My plans are to run the perl script from one location and go
  and discover the systems and their configuration. I'll be using
  Net::Telnet module to do this with to connect to systems in
  order to get those configs.


Hi Bruce.

The $^O variable indicates the platform on which the currently
executing version of perl was built. If you're running Perl on
a different platform from the one where it was built then I
don't think it's likely to work too well! Does anybody know
different?

Cheers,

Rob



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



capturing output of a shell comand

2003-10-28 Thread BetaGamma
Hi everyone
I have been trying to capture the output of a shell command (say ls or 
echo *) in a variable but all i have been able to capture is the return 
status of system comman which is 0.
I also tried changing the default output handler from STDOUT to the  
filehandle of a file I have created hoping tha the optput of my chell 
command will be captured by the new filehandler but all in vain.
This problem is killing me.
Please help.
Thanks
Pawan



-
Do you Yahoo!?
Exclusive Video Premiere - Britney Spears

Re: capturing output of a shell comand

2003-10-28 Thread Rob Dixon
Pawan wrote:

 I have been trying to capture the output of a shell command (say
 ls or echo *) in a variable but all i have been able to capture
 is the return status of system comman which is 0.

 I also tried changing the defaulT output handler from STDOUT to
 the filehandle of a file I have created hoping tha the optput of
 my shell command will be captured by the new filehandler but all
 in vain.

 This problem is killing me.

 Please help.

Hi Pawan.

What you need is backtick quotes:

  `ls`

or

  qx(ls)

which is the same thing. It does the same as system in that it
executes a shell command, but instead of the exit status it
returns the text that the command output to its STDOUT. In list
context the return value will be a list of lines (still with
their trailing newlines) and in scalar context it will be a
single scalar value containing all of the output.

Be careful though: it's usually better to write Perl code
than to rely on the output from an an external utility.

HTH,

Rob



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



RE: Opening a new shell

2003-10-28 Thread rau

 -Original Message-
 From: Anthony J Segelhorst [mailto:[EMAIL PROTECTED]
 Sent: Monday, October 27, 2003 5:50 PM
 To: [EMAIL PROTECTED]
 Subject: Opening a new shell


 I am strapped for time on the run time on a perl script I have been
 working on.

 I was wondering if it is possible to open another shell within a perl
 script that will call another script that uses another processes.

 If I call script B from script A, script A will not complete
 until script
 B is done running.  Is there a way to run script B within
 another shell or
 process?

But you want to run them in parallel? You will need threads.



 `c:\temp\scripta.pl`;

 unix?  Guess not, since you are using backslashes in your file name.
 try: system('c:/temp/scripta.pl ');

 The backticks imply you want to wait for the script to return some
 output, system may make more sense here.  Also, it is ok to use forward
 slashes in your perl script, even in Windows.

 Mark

 --
 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: downloading a mp3 file using LWP::simple

2003-10-28 Thread [EMAIL PROTECTED]
[EMAIL PROTECTED] wrote:
using the following code I get a distorted file , I used the sockets and 
the result is the same here is the LWP code i used
use strict;
use LWP::Simple;
my $url =http://xxx.xxx.com/Amazing_Grace.mp3; ;
my $html = get($url) ;
print $html;
exit(0);

I think that the tranfer was made in ascii .
any help would be greatly appreciated .
thks n rgds
succeeded with getstore
thks n rgds
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


finding out my IP address..

2003-10-28 Thread Kevin . Bewley
Hi,
   I'm trying to find my IP address from within Perl for eth0 and ppp0.
Currently I run a regex on the output of ifconfig to extract his data -
but, I'd like to do this from within Perl and it strikes me that this
should be possible.

HELP!

Kev



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



logging

2003-10-28 Thread PerlDiscuss - Perl Newsgroups and mailing lists
My co-worker wrote a perl script on a WIN 2000 Advance server that
monitors my E10K 8 Unix domains. It executes every 15 minutes and then the
output attempts are logged in the /var/adm/messages on my unix domains
each time. How do I redirect this output to another log of its own to keep
it from filling up the /var/adm/messages file?

The output from the /var/adm/messages follow:

Oct 26 03:49:14 grouper telnetd[4653]: [ID 682499 daemon.info] ttloop: 
read: Connection reset by peer

 Jay


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



RE: Opening a new shell

2003-10-28 Thread Anthony J Segelhorst
I do not think I need to run them in parallel.  I just need scripta.pl to 
finish in under 60 seconds and scriptb.pl can take as long as it needs to. 
 Scriptb.pl is only called when scripta.pl needs to call it.


I got some info on this:  % perldoc -f fork 

I am confused about the syntax of the fork though.  Does anyone have any 
examples?


Anthony J Segelhorst
Enterprise Systems Management Team
Phone: 937-495-1876
Email: [EMAIL PROTECTED]





[EMAIL PROTECTED]
10/28/2003 03:44 AM

 
To: [EMAIL PROTECTED]
cc: [EMAIL PROTECTED], [EMAIL PROTECTED]
Subject:RE: Opening a new shell



 -Original Message-
 From: Anthony J Segelhorst [mailto:[EMAIL PROTECTED]
 Sent: Monday, October 27, 2003 5:50 PM
 To: [EMAIL PROTECTED]
 Subject: Opening a new shell


 I am strapped for time on the run time on a perl script I have been
 working on.

 I was wondering if it is possible to open another shell within a perl
 script that will call another script that uses another processes.

 If I call script B from script A, script A will not complete
 until script
 B is done running.  Is there a way to run script B within
 another shell or
 process?

But you want to run them in parallel? You will need threads.



 `c:\temp\scripta.pl`;

 unix?  Guess not, since you are using backslashes in your file name.
 try: system('c:/temp/scripta.pl ');

 The backticks imply you want to wait for the script to return some
 output, system may make more sense here.  Also, it is ok to use forward
 slashes in your perl script, even in Windows.

 Mark

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





This email has been scanned for all viruses by the MessageLabs SkyScan
service.___





This email has been scanned for all viruses by the MessageLabs SkyScan
service.___

Note:  Please update your email address for this user to reflect the
new MeadWestvaco Corporation.  MeadWestvaco employee email addresses
are in the format of [EMAIL PROTECTED] 

This electronic message contains information from MeadWestvaco
Corporation or subsidiary companies, which may be confidential,
privileged or otherwise protected from disclosure.  The
information is intended to be used solely by the recipient(s)
named.  If you are not an intended recipient, be aware that
any review, disclosure, copying, distribution or use of this
transmission or its contents is prohibited.  If you have
received this transmission in error, please notify MeadWestvaco
immediately at [EMAIL PROTECTED]
___

RE: Issue

2003-10-28 Thread Bruce_Phillip
Bob,

 I appreciate your feed back but you clearly don't understand.

 The perl script I'll be running will be executed only from one
 Location and that is from my laptop. I'll be connected to a network
 In which the script will be using Net::Telnet module to communicate
 To the other systems. No need to put any scripts on any other machine
 Period

 So the $^O variable will only work if you run A PERL SCRIPT on that
 System. The purpose of the script is to discover what systems are on
 A given network. 

 Again I don't need to run perl on multiple machines. That will totally
 Defeat the purpose of the scripts. If you don't know about CPAN then
 Look at http://www.cpan.org. That is where I got the Net::Telnet module 
 from.

Phillip

-Original Message-
From: Rob Dixon [mailto:[EMAIL PROTECTED] 
Sent: Tuesday, October 28, 2003 12:54 AM
To: [EMAIL PROTECTED]
Subject: Re: Issue
Hi Bruce.

The $^O variable indicates the platform on which the currently
executing version of perl was built. If you're running Perl on
a different platform from the one where it was built then I
don't think it's likely to work too well! Does anybody know
different?

Cheers,


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



Re: Opening a new shell

2003-10-28 Thread Rob Dixon
Anthony, Mark. Please bottom-post so that people can understand
the conversation. Thanks.

Anthony J Segelhorst wrote:

 Mark wrote:
 
  Anthony J Segelhorst wrote:
 
   I am strapped for time on the run time on a perl script I
   have been working on.
  
   I was wondering if it is possible to open another shell
   within a perl script that will call another script that
   uses another processes.
  
   If I call script B from script A, script A will not
   complete until script B is done running.  Is there a way
   to run script B within another shell or process?
 
  But you want to run them in parallel? You will need threads.

 I do not think I need to run them in parallel.  I just need
 scripta.pl to finish in under 60 seconds and scriptb.pl can
 take as long as it needs to.  Scriptb.pl is only called when
 scripta.pl needs to call it.

 I got some info on this:  % perldoc -f fork

 I am confused about the syntax of the fork though.  Does
 anyone have any examples?

Hi Anthony.

Can you explain why you want to shell out to another Perl
process? I gathered from your description that you wanted to
speed up your application by accessing a bottleneck in parallel.
If your new process is started synchronously then you will gain
no speed advantage.

What version of Perl are you working with? Perl v5.8 has much
enhanced multithreading functionality.

Cheers,

Rob



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



Re: logging

2003-10-28 Thread Wiggins d Anconia


 My co-worker wrote a perl script on a WIN 2000 Advance server that
 monitors my E10K 8 Unix domains. It executes every 15 minutes and then the
 output attempts are logged in the /var/adm/messages on my unix domains
 each time. How do I redirect this output to another log of its own to keep
 it from filling up the /var/adm/messages file?
 
 The output from the /var/adm/messages follow:
 
 Oct 26 03:49:14 grouper telnetd[4653]: [ID 682499 daemon.info] ttloop: 
 read: Connection reset by peer
 

Wow, that is ironic, a windows box monitoring a unix domain who would
have thunk it. 

This will probably somewhat depend on how the Perl script is written,
presumably if you are writing to adm/messages and since it is over the
network then the script is logging via syslog?  In which case the syslog
configuration should be able to provide the mechanism for catching the
messages and routing them to a different log.  But the above seems to
come from telnetd? Which I don't fully understand...  Have you looked
into re-configuring syslog?

http://danconia.org


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



Re: Issue

2003-10-28 Thread Gary Stainburn
On Monday 27 Oct 2003 7:32 pm, [EMAIL PROTECTED] wrote:
 Hi,

   I'm trying to accomplish some task using perl. So let
   me describe what I have.

   I have several systems of the following:

   Unix:
 Sun - Solaris
 HP - HPUX

   Windows:
 Dell - Windows 2k

  Each of these OS's have specific commands that are specific
  not only to the OS but to the hardware as well. Wouldn't it be
  better if I created a header file that contains these commands
  and assigned them to a common variable?

  Example:
 $memory = 'prtconf | grep Memory | awk '{print $3}'

[snip]

Hi Philip,

I'd try something like (asuming $detail is part of the header returned from 
the Net::telnet connect)

my %whichos=('Solarix'='sol','Aix'='aix','microsoft'='W2K');
my %commands=('sol'={'memory'='prtconf | grep Memory | awk '{print $3}',
  'diskfree'='..'}
  'aix'={'memory'='...',
  'diskfree'='..'}
  'W2k'={'memory'='',
  'diskfree'='..'});

my $OS='';
foreach my $regex (keys %whichos) {
  $OS=$whichos{$regex} if ($details=~/$regex/i);
}
die cannot find OS unless  ( $OS  defined {$commands{$OS});

then simply use %commands{$OS}{memory} to get the command you want


 Phillip Bruce
 ISC Consultant, System Architect
 Location: Dublin, CA
 * Cell: 408-476-8658
 * Office: 925-560-7853
 AIM: OkieUnix

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



Re: Issue

2003-10-28 Thread Rob Dixon
[EMAIL PROTECTED] wrote:

 Rob Dixon wrote:
 
  Bob Showalter wrote:
  
   This sounds fine in principle. Many of the standard Perl
   modules do this kind of thing. You use the built-in $^O
   variable to detect the operating system. If you want to
   see
   an example, do 'perldoc -m Cwd' to browse the source code
   of the Cwd module.
  
   Instead of command_header.pl, consider making a
   full-fledged module. It isn't hard. Start by reading
   'perldoc perlmod'.
  
   Also, read 'perldoc perlport' for general info on writing
   cross-platform perl.
 
  The $^O variable indicates the platform on which the
  currently executing version of perl was built. If you're
  running Perl on a different platform from the one where it
  was built then I don't think it's likely to work too well!
  Does anybody know different?

 I appreciate your feed back but you clearly don't understand.

 The perl script I'll be running will be executed only from one
 Location and that is from my laptop. I'll be connected to a
 network In which the script will be using Net::Telnet module
 to communicate To the other systems. No need to put any
 scripts on any other machine Period

 So the $^O variable will only work if you run A PERL SCRIPT on
 that System. The purpose of the script is to discover what
 systems are on A given network.

 Again I don't need to run perl on multiple machines. That will
 totally Defeat the purpose of the scripts. If you don't know
 about CPAN then Look at http://www.cpan.org. That is where I
 got the Net::Telnet module from.

I know that Bob knows about the CPAN. He will also know about
the 'Net::Telnet' module that you're using. What both he and I
'clearly' didn't understand was that you were using it: you make
no mention of it in your original post.

If you are running 'A PERL SCRIPT' on a machine that somehow has
remote access to an external system, and your question is about
that external system, then surely it makes sense to explain the
mechanism of that access?

Your answer, at this stage, is to open an interactive telnet
session on your laptop to any one of your remote systems. If you
can establish the type of that system from the session then you
can do the same thing from Perl.

Let us know if you need any more help.

Rob





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



our vs. use vars

2003-10-28 Thread Dan Muey
Howdy group,

In developing a module and I am torn.

I want to use the newer our $variable; but to make it work 
with pre 5.6 Perl (or whatever version our appeared in) I 
have to do the use vars qw($variable); method

So I was wanting some input about pros and cons of using 
either since on the surface they appear to do the same thing 
except that use vars is backwards compatable.

Any input on our vs. use vars ?? Pro,con, neutral ??

TIA

Dan

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



Re: Opening a new shell

2003-10-28 Thread Anthony J Segelhorst
Anthony, Mark. Please bottom-post so that people can understand
the conversation. Thanks.

Anthony J Segelhorst wrote:

 Mark wrote:
 
  Anthony J Segelhorst wrote:
 
   I am strapped for time on the run time on a perl script I
   have been working on.
  
   I was wondering if it is possible to open another shell
   within a perl script that will call another script that
   uses another processes.
  
   If I call script B from script A, script A will not
   complete until script B is done running.  Is there a way
   to run script B within another shell or process?
 
  But you want to run them in parallel? You will need threads.

 I do not think I need to run them in parallel.  I just need
 scripta.pl to finish in under 60 seconds and scriptb.pl can
 take as long as it needs to.  Scriptb.pl is only called when
 scripta.pl needs to call it.

 I got some info on this:  % perldoc -f fork

 I am confused about the syntax of the fork though.  Does
 anyone have any examples?

Hi Anthony.

Can you explain why you want to shell out to another Perl
process? I gathered from your description that you wanted to
speed up your application by accessing a bottleneck in parallel.
If your new process is started synchronously then you will gain
no speed advantage.

What version of Perl are you working with? Perl v5.8 has much
enhanced multithreading functionality.

Cheers,

Rob


Basically I am writing the script to monitor services on Windows Servers 
using net start and it reads in a config file, that the end user builds. I 
want to attempt tp restart the service using a net start Service Name, 
but the monitoring product I am importing the script into, only allows me 
to have a window of 60 seconds to run a script.  This is the reason I am 
wanting to call an external script and the original script does not wait 
on the service to restart.

The section where I restart the service, is where I need to call the 
external script, and have this script keep running without waiting on any 
return values:

Code

$servicestatus = 1;
$lcf_tools = $ENV{LCF_TOOLSDIR};
$logfile = 
$ENV{LCF_DATDIR}\\LCFNEW\\Tmw2k\\Service_Monitor\\service_monitor.log;
$netstart = $ENV{LCF_DATDIR}\\LCFNEW\\Tmw2k\\bin\\net start;
$LOGMAX = 5;
$threshold = c:\\SRV\\tools\\ITM\\mwv-service-monitor.conf;
($dev,$inode,$mode,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime,$ctime,$blksize,$blocks) 
= stat($logfile);
if ( $size  $LOGMAX ) {
system ( del $logfile );
open( LOGFILE,  $logfile );
}
else { open( LOGFILE,  $logfile ); }
###
#
#MAIN
#
#
##
open(IN,$threshold) or DefaultAction();
print LOGFILE **\n;
$date = Date;
print LOGFILE $date\n;
print LOGFILE This server has a config file in use. $threshold\n;
while((defined(IN))  ($line=IN)){
chomp $line;
if ($line eq ){
}
else{ 
($service,$severity,$group) = split(@, $line);
#   $service =~ tr/[A-Z]/[a-z]/;
@linecountarray = `$netstart |$lcf_tools\\grep $service 
|$lcf_tools\\wc -l`;
#loops through foreach only one time
foreach $linetemp (@linecountarray){
($linecount) = split( , $linetemp);
$output = ;
AnalyzeService($service);
#$output set from AnalyzeService
}
 
if (length($output) != 0){
print $output;
print LOGFILE The results from the script 
are:\n;
print LOGFILE $output\n;
print LOGFILE **\n;
}
}
 
}
#if all services in config running prints OK
if($servicestatus == 1){
print OK\n;
print LOGFILE The results from the script are:\n;
print LOGFILE OK\n;
print LOGFILE **\n;
}



exit(0);

#if no config file exits, because there are no services to monitor
sub DefaultAction{
print LOGFILE **\n;
$date = Date;
print LOGFILE $date\n;
print LOGFILE There is no config file for this server\n;
print LOGFILE With no config file, there is no services 
to monitor\n;
print LOGFILE Now exiting\n;
print OK\n;
 
exit(0);
}

#$linecount== - |grep wc -l returned 0 and service not running
sub AnalyzeService{
if ($linecount == 0){
$servicestatus = 0;
print LOGFILE The service named $service is NOT 
started\n;
$output = WinService,$severity,$service,$group;;
#Try to restart service
#
#THIS is where I need to call an external script that does the net start 
and this script just keeps going.
`$netstart $service /y`;
print 

Re: our vs. use vars

2003-10-28 Thread Rob Dixon
Dan Muey wrote:

 In developing a module and I am torn.

 I want to use the newer our $variable; but to make it work
 with pre 5.6 Perl (or whatever version our appeared in) I
 have to do the use vars qw($variable); method

 So I was wanting some input about pros and cons of using
 either since on the surface they appear to do the same thing
 except that use vars is backwards compatable.

 Any input on our vs. use vars ?? Pro,con, neutral ??

Hi Dan.

The main issue about 'our' as opposed to 'use vars' is that
the of scope. 'use vars' compiles to a BEGIN block which,
wherever it is used, makes the package variables visible
throughout the file. An 'our' declaration provides access
to a package variable up to the end of the current block
or file.

You can safely use 'our' in place of 'use vars', but not
necessarily vice versa.

HTH,

Rob



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



RE: Issue

2003-10-28 Thread Bruce_Phillip
Bob,

  Thanks for the help but again your failing to understand.

  The perl script it self will use Net::Telnet with the script
  I run on this laptop that will be connected to a network.
  The perl module Net::Telnet will issue the telnet session
  Within the perl script.

  Gary Stainburn was closer to what I was trying to obtain with
  The perl script.

my $telnet = Net::Telnet-new(HOST = $ipaddr);
$telnet-login(USER,$PASS);

# Get the host name of system
#
  my @lines = $telnet-cmd($HOSTCMD);
  my $csv = Text::CSV-new;
  if ( $csv-parse(@lines) ){
 my @field = $csv-fields;
 for $host (@field){
   print OUT_FH $host,,, $ipaddr;
   print Found Host...\n;
 }
   }
 
Without looping the above perl script works. The variable $HOSTCMD would be
in this case the $HOSTCMD is uname -n that much of it works ok. But I think
Gary has pointed out something for me to look at.

Phillip
-Original Message-
From: Rob Dixon [mailto:[EMAIL PROTECTED] 
Sent: Tuesday, October 28, 2003 8:44 AM
To: [EMAIL PROTECTED]
Subject: Re: Issue

[EMAIL PROTECTED] wrote:

 Rob Dixon wrote:
 
  Bob Showalter wrote:
  
   This sounds fine in principle. Many of the standard Perl
   modules do this kind of thing. You use the built-in $^O
   variable to detect the operating system. If you want to
   see
   an example, do 'perldoc -m Cwd' to browse the source code
   of the Cwd module.
  
   Instead of command_header.pl, consider making a
   full-fledged module. It isn't hard. Start by reading
   'perldoc perlmod'.
  
   Also, read 'perldoc perlport' for general info on writing
   cross-platform perl.
 
  The $^O variable indicates the platform on which the
  currently executing version of perl was built. If you're
  running Perl on a different platform from the one where it
  was built then I don't think it's likely to work too well!
  Does anybody know different?

 I appreciate your feed back but you clearly don't understand.

 The perl script I'll be running will be executed only from one
 Location and that is from my laptop. I'll be connected to a
 network In which the script will be using Net::Telnet module
 to communicate To the other systems. No need to put any
 scripts on any other machine Period

 So the $^O variable will only work if you run A PERL SCRIPT on
 that System. The purpose of the script is to discover what
 systems are on A given network.

 Again I don't need to run perl on multiple machines. That will
 totally Defeat the purpose of the scripts. If you don't know
 about CPAN then Look at http://www.cpan.org. That is where I
 got the Net::Telnet module from.

I know that Bob knows about the CPAN. He will also know about
the 'Net::Telnet' module that you're using. What both he and I
'clearly' didn't understand was that you were using it: you make
no mention of it in your original post.

If you are running 'A PERL SCRIPT' on a machine that somehow has
remote access to an external system, and your question is about
that external system, then surely it makes sense to explain the
mechanism of that access?

Your answer, at this stage, is to open an interactive telnet
session on your laptop to any one of your remote systems. If you
can establish the type of that system from the session then you
can do the same thing from Perl.

Let us know if you need any more help.

Rob





-- 
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: Opening a new shell

2003-10-28 Thread Rob Dixon
Anthony J Segelhorst wrote:

 Basically I am writing the script to monitor services on Windows Servers
 using net start and it reads in a config file, that the end user builds. I
 want to attempt tp restart the service using a net start Service Name,
 but the monitoring product I am importing the script into, only allows me
 to have a window of 60 seconds to run a script.  This is the reason I am
 wanting to call an external script and the original script does not wait
 on the service to restart.

So it's purely a per-process accounting limit?

My first thought is to harrass your system manager, but I'll keep
thinking! You certainly shouldn't have to write code to disguise a
legitimate use of the system.

Rob



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



RE: Opening a new shell

2003-10-28 Thread Tim Johnson

Check out the Win32::Process module.  It should be able to do what you want.

-Original Message-
From: Rob Dixon [mailto:[EMAIL PROTECTED] 
Sent: Tuesday, October 28, 2003 9:18 AM
To: [EMAIL PROTECTED]
Subject: Re: Opening a new shell


Anthony J Segelhorst wrote:

 Basically I am writing the script to monitor services on Windows 
 Servers using net start and it reads in a config file, that the end 
 user builds. I want to attempt tp restart the service using a net 
 start Service Name, but the monitoring product I am importing the 
 script into, only allows me to have a window of 60 seconds to run a 
 script.  This is the reason I am wanting to call an external script 
 and the original script does not wait on the service to restart.

So it's purely a per-process accounting limit?

My first thought is to harrass your system manager, but I'll keep thinking!
You certainly shouldn't have to write code to disguise a legitimate use of
the system.

Rob



-- 
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: our vs. use vars

2003-10-28 Thread Dan Muey


 Dan Muey wrote:
 
  In developing a module and I am torn.
 
  I want to use the newer our $variable; but to make it work with pre 
  5.6 Perl (or whatever version our appeared in) I have to do the use 
  vars qw($variable); method
 
  So I was wanting some input about pros and cons of using 
 either since 
  on the surface they appear to do the same thing except that 
 use vars 
  is backwards compatable.
 
  Any input on our vs. use vars ?? Pro,con, neutral ??
 
 Hi Dan.
 
 The main issue about 'our' as opposed to 'use vars' is that
 the of scope. 'use vars' compiles to a BEGIN block which, 
 wherever it is used, makes the package variables visible 
 throughout the file. An 'our' declaration provides access to 
 a package variable up to the end of the current block or file.
 
 You can safely use 'our' in place of 'use vars', but not 
 necessarily vice versa.

Hey Rob, 

Yes that's helps a lot. 
So I'm still stuck with wanting to do our but needing backward compatibility.

I wonder if I should check the version and do our if it's 5.6 and do use 
vars if it's older.
Except the BEGIN stuff would probably make it not work as expected.

Or I could do two versions of the module and folks could install which one they 
need based on their Perl version.

Or I could say upgrade your Perl! and just do our! :)

Thanks Rob for the info, very helpful as usual!

Dan

 
 HTH,
 
 Rob
 
 
 
 -- 
 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: our vs. use vars

2003-10-28 Thread Rob Dixon
Dan Muey wrote:

 Rob Dixon wrote:
 
  Dan Muey wrote:
  
   In developing a module and I am torn.
  
   I want to use the newer our $variable; but to make it work
   with pre 5.6 Perl (or whatever version our appeared in) I
   have to do the use vars qw($variable); method
  
   So I was wanting some input about pros and cons of using
   either since on the surface they appear to do the same
   thing except that use vars is backwards compatable.
  
   Any input on our vs. use vars ?? Pro,con, neutral ??
 
  The main issue about 'our' as opposed to 'use vars' is that
  the of scope. 'use vars' compiles to a BEGIN block which,
  wherever it is used, makes the package variables visible
  throughout the file. An 'our' declaration provides access to
  a package variable up to the end of the current block or
  file.
 
  You can safely use 'our' in place of 'use vars', but not
  necessarily vice versa.

 Yes that's helps a lot. So I'm still stuck with wanting to do
 our but needing backward compatibility.

 I wonder if I should check the version and do our if it's 5.6
 and do use vars if it's older. Except the BEGIN stuff would
 probably make it not work as expected. Or I could do two
 versions of the module and folks could install which one they
 need based on their Perl version.

 Or I could say upgrade your Perl! and just do our! :)

I'd say to use 'our' for all new stuff, but make sure that any
shared code uses it only at the head of the program with all the
other BEGIN-like code.

If it doesn't work send them to me :)

Rob



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



Re: our vs. use vars

2003-10-28 Thread Steve Grazzini
On Tue, Oct 28, 2003 at 10:52:16AM -0600, Dan Muey wrote:
 I want to use the newer our $variable; but to make it work 
 with pre 5.6 Perl (or whatever version our appeared in) I 
 have to do the use vars qw($variable); method
 
 So I was wanting some input about pros and cons of using 
 either since on the surface they appear to do the same thing 
 except that use vars is backwards compatable.

use vars and our do roughly the same thing.  They both let you
use package variables under strict without fully-qualifying.

All these code snippets pass strict, and they each set the package
variable $foo ($A::foo, $B::foo, and $C::foo).

use strict;

{
  package A;
  use vars qw($foo);
  $foo = 'A::foo';
}

{
  package B;
  our $foo;
  $foo = 'B::foo';
}

{
  package C;
  $C::foo = 'C::foo';# fully-qualifying
}

The main practical difference is, like you said, that our is
new in 5.6.  So if you want to support perl5.005_03 (which is still
in relatively wide use) you have to use vars instead.

But use vars and our work differently, and there are some
subtle differences in their behavior.

First of all, use vars does its magic by twiddling the symbol
table, marking the $foo variable as imported.  Since the symbol
table is global, you can use $foo any time you are in the package
that imported it -- even if you're in a different block or file.

package A;
use strict;

{ use vars qw($foo) }
$foo = 'A::foo';   # different block; no problem

And for the same reason, a use vars declaration doesn't extend
across two packages in the same block or file.

package A;
use strict;

use vars qw($foo);

package B;
$foo = 'B::foo';   # different package: ERROR

On the other hand, our does its magic by creating a lexical 
symbol (like a my variable) that is aliased to the package 
variable of the same name.  Since lexical symbols are only visible
in the scope (block, file, or eval) where they were declared, the
our declaration doesn't exist outside this block.

package A;
use strict;

{ our $foo; }
$foo = 'A::foo';   # different lexical scope: ERROR

And when you have several packages in the same lexical scope, the
our declaration extends across them.

package A;
use strict;

our $foo;  # alias to $A::foo

package B;
$foo = 'A::foo';   # STILL refers to $A::foo

-- 
Steve

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



IRC bot in perl?

2003-10-28 Thread David O'Dell
Can anyone recommend the best way to do this in Perl.
There are a lot of modules out there and also IO::Socket.
Just looking for a good starting place.
Thanks



RE: our vs. use vars

2003-10-28 Thread Dan Muey
 use vars and our do roughly the same thing.  They both 
 let you use package variables under strict without fully-qualifying.
 
 All these code snippets pass strict, and they each set the 
 package variable $foo ($A::foo, $B::foo, and $C::foo).
 
 use strict;
 
 {
   package A;
   use vars qw($foo);
   $foo = 'A::foo';
 }
 
 {
   package B;
   our $foo;
   $foo = 'B::foo';
 }
 
 {
   package C;
   $C::foo = 'C::foo';# fully-qualifying
 }
 
 The main practical difference is, like you said, that our 
 is new in 5.6.  So if you want to support perl5.005_03 (which 
 is still in relatively wide use) you have to use vars instead.
 
 But use vars and our work differently, and there are some 
 subtle differences in their behavior.
 
 First of all, use vars does its magic by twiddling the 
 symbol table, marking the $foo variable as imported.  Since 
 the symbol table is global, you can use $foo any time you are 
 in the package that imported it -- even if you're in a 
 different block or file.
 
 package A;
 use strict;
 
 { use vars qw($foo) }
 $foo = 'A::foo';   # different block; no problem
 
 And for the same reason, a use vars declaration doesn't 
 extend across two packages in the same block or file.
 
 package A;
 use strict;
 
 use vars qw($foo);
 
 package B;
 $foo = 'B::foo';   # different package: ERROR
 
 On the other hand, our does its magic by creating a lexical 
 symbol (like a my variable) that is aliased to the package 
 variable of the same name.  Since lexical symbols are only 
 visible in the scope (block, file, or eval) where they were 
 declared, the our declaration doesn't exist outside this block.
 
 package A;
 use strict;
 
 { our $foo; }
 $foo = 'A::foo';   # different lexical scope: ERROR
 
 And when you have several packages in the same lexical scope, 
 the our declaration extends across them.
 
 package A;
 use strict;
 
 our $foo;  # alias to $A::foo
 
 package B;
 $foo = 'A::foo';   # STILL refers to $A::foo
 
 -- 

Thanks Steve, 

Very imformative and helpful!

I'll read over hwta you and Rob said and let it soak in and go from there!

Thanks again,

Dan

 Steve
 

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



RE: FQN from references

2003-10-28 Thread Gupta, Sharad
Hi D',

I agree whatever you are saying. 
But i need to support somebody's code without annoying users by breaking their old 
code which depends on this interface.

Yes, i can expand the scope of the routine now and let users pass in the additional 
information.
But again if i can guess it somehow, why to make it mandatory in the interface.

-Sharad  

 -Original Message-
 From: Wiggins d'Anconia [mailto:[EMAIL PROTECTED]
 Sent: Wednesday, October 22, 2003 8:53 PM
 To: Gupta, Sharad
 Cc: [EMAIL PROTECTED]
 Subject: Re: FQN from references
 
 
 Gupta, Sharad wrote:
  I can't store it somewhere. I have a routine to which a 
 user can pass a coderef.
  And in that routine i want to know the full name of that coderef.
  
  -Sharad
 
 But in that case isn't it just a design issue, to me it would 
 make more 
 sense to pass the name of the routine and call it directly from the 
 symbol table rather than passing the code ref, or pass both 
 the ref and 
 its' name, since they are really independent pieces of 
 information you 
 don't *need* one to use the other, it would limit the ability 
 of the sub 
 if you are passing a code ref, and it is expecting a code ref 
  and sub 
 name in the same argument, since presumably if you want the 
 code to call 
 it as a subroutine an anonymous code ref should work in the 
 same manner 
 as any other code ref, but it won't have a name, so you are really 
 wanting a code ref with a name as your argument, but at 
 that point it 
 makes more sense to break that into a code ref, and a name
 
 But then, obviously I haven't seen the rest of the code..
 
 http://danconia.org
 
  
  
 -Original Message-
 From: Wiggins d'Anconia [mailto:[EMAIL PROTECTED]
 Sent: Wednesday, October 22, 2003 6:23 PM
 To: Gupta, Sharad
 Cc: [EMAIL PROTECTED]
 Subject: Re: FQN from references
 
 
 Gupta, Sharad wrote:
 
 Hi All,
 
 How do i know the full name of a variable from its reference??.
 
 Say i have a routine defined like this:
 
 package Bar;
 sub foo {};
 
 And then i say:
 my $x = \foo;
 
 Now from this coderef ($x) i want to know its fully 
 
 qualified name which would be somthing like Bar::Foo. 
 
 Is there a way to do that.??.
 
 
 Where do you want to know it? Presumably if you have set it 
 then you 
 should know it already, if it is set dynamically you still 
 have to have 
 the name somewhere that you can access, then it is just a matter of 
 storing it smartly, aka rather than using
 
 my $x = \foo;
 
 Why not:
 
 my %handler;
 $handler{'Bar::Foo'} = \foo;
 
 Now you can access the reference and have its name at the 
 same time. The 
 problem comes in with inheritance because maybe $y wants to call $x 
 (foo) and thinks it is in Bar but it really is in Baz, does 
 this mean it 
 shouldn't be called, or just that it was inherited and it is 
 ok to call?
 
 Within foo, there is __PACKAGE__ which will give you Bar...
 
 You may also want to have a look at Symbol Tables in perldoc 
 perlmod
 
 Gurus, am I missing out on something??  ;-)
 
 http://danconia.org
 
 
  
  
  
 
 

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



dealing with dates

2003-10-28 Thread Steve Main


Hello list,

I am having a problem coming up with a solution to compare and find the
difference between two dates.

One of the dates is a GMT date while the other is PST(or PDT) so my
first
Problem is converting the local date to GMT which is fine unless I want
to automagically detect the hour back or ahead.  So I guess my
question is does anyone have a slick way to convert a date to GMT and a
way to get the number of days between the two dates?

Thanks

Steve


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



RE: our vs. use vars

2003-10-28 Thread Dan Muey
Hmm ok, what would be nice is to do something like this:
 (I have a function that returns true if the perl version is the same or higher than 
the specified number)

package Monkey;

use strict;

if(gotperlv(5.6)) {
our $bar
our $foo;
} else {
use vars qw($bar $foo);
}

Except the ours would only apply to that black and wouldn't do too much good 
if I'm understanding this right. And also would it not always do the use vars
since it gets done in the BEGIN black ?

So the trick is how to I pull that off and make the ours 
as if I'd done

package Monkey;

our $bar;
our $foo;

if gotperlv(5.6) returned true and 

package Monkey;

use vars qw($foo $bar);

If it returns false.

Maybe I'm just crazy but it seems there should be a way!

Dan

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



Re: IRC bot in perl?

2003-10-28 Thread Wiggins d Anconia
 
 Can anyone recommend the best way to do this in Perl.
 There are a lot of modules out there and also IO::Socket.
 Just looking for a good starting place.
 Thanks
 
 
 

http://poe.perl.org/?POE_Cookbook

Particularly the IRC Programming section.

http://danconia.org

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



How Do I initialize an empty array

2003-10-28 Thread perl
How Do I initialize an empty array so thtat I don't get an unitiialized
error?

...
my @rows;

I thought I could do something like @rows = new (); but it's not working.

thanks


-
eMail solutions by 
http://www.swanmail.com

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



RE: our vs. use vars

2003-10-28 Thread Wiggins d Anconia
Many of your questions lately have been wrapped around
scoping/packages/symbol tables, etc. have you had a read through:

http://perl.plover.com/FAQs/Namespaces.html

??  I found it most informative.

http://danconia.org

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



Re: our vs. use vars

2003-10-28 Thread Steve Grazzini
On Tue, Oct 28, 2003 at 12:14:05PM -0600, Dan Muey wrote:
 Hmm ok, what would be nice is to do something like this:
 (I have a function that returns true if the perl version is the same or
 higher than the specified number)
 
 package Monkey;
 
 use strict;
 
 if(gotperlv(5.6)) {
   our $bar
   our $foo;
 } else {
   use vars qw($bar $foo);
 }
 
 Except the ours would only apply to that black and wouldn't do too 
 much good if I'm understanding this right. And also would it not always
 do the use vars since it gets done in the BEGIN black ?

Yep -- you're right on both counts.  If you want to support older
versions of perl ($]  5.006) you just have to use vars and forget 
about our.

If you don't care about older perls (and 5.005_03 is getting kind
of mouldy) then do something like

use 5.006;

use base qw(Exporter);
our @EXPORT = qw(...);

-- 
Steve

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



Re: How Do I initialize an empty array

2003-10-28 Thread Wiggins d Anconia


 How Do I initialize an empty array so thtat I don't get an unitiialized
 error?
 
 ...
 my @rows;
 
 I thought I could do something like @rows = new (); but it's not working.
 

Drop the 'new':

my @rows = ();

http://danconia.org

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



Re: How Do I initialize an empty array

2003-10-28 Thread Wiggins d Anconia


 
 
  How Do I initialize an empty array so thtat I don't get an unitiialized
  error?
  
  ...
  my @rows;
  
  I thought I could do something like @rows = new (); but it's not
working.
  
 
 Drop the 'new':
 
 my @rows = ();
 

Are you sure you are getting the warning on the array or on the elements
of the array you are using?  In which case you can check for
definedness, before using the value, 

perldoc -f defined

or if you know the length of the array ahead of time:

my @rows = ('','','');

For a three element array

http://danconia.org

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



Re: How Do I initialize an empty array

2003-10-28 Thread perl
thanks. it works.
@rows=();

--


 How Do I initialize an empty array so thtat I don't get an unitiialized
 error?

 ...
 my @rows;

 I thought I could do something like @rows = new (); but it's not
 working.


 Drop the 'new':

 my @rows = ();

 http://danconia.org




-
eMail solutions by 
http://www.swanmail.com

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



RE: dealing with dates

2003-10-28 Thread Tim Johnson

You could always use something like Time::Local to break the dates down to
time() format and then subtract 8 hours or whatever you need to do, then
subtract one date from the other.

-Original Message-
From: Steve Main [mailto:[EMAIL PROTECTED] 
Sent: Tuesday, October 28, 2003 10:15 AM
To: [EMAIL PROTECTED]
Subject: dealing with dates




Hello list,

I am having a problem coming up with a solution to compare and find the
difference between two dates.

One of the dates is a GMT date while the other is PST(or PDT) so my first
Problem is converting the local date to GMT which is fine unless I want to
automagically detect the hour back or ahead.  So I guess my question is
does anyone have a slick way to convert a date to GMT and a way to get the
number of days between the two dates?

Thanks

Steve


-- 
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: How Do I initialize an empty array

2003-10-28 Thread Rob Dixon
[EMAIL PROTECTED] wrote:

 How Do I initialize an empty array so thtat I don't get an unitiialized
 error?

 ...
 my @rows;

 I thought I could do something like @rows = new (); but it's not working.

You don't.

  my @rows;

declares an array, which is initially empty. If you put
something into it and want it back like it was, then

  @rows = ()

will empty it again.

If you're getting 'Use of uninitialized value' then it's
because you're using an element of the array that hasn't
been assigned (or has been asigned with 'undef').

Rob



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



RE: our vs. use vars

2003-10-28 Thread Dan Muey
 On Tue, Oct 28, 2003 at 12:14:05PM -0600, Dan Muey wrote:
  Hmm ok, what would be nice is to do something like this:
  (I have a function that returns true if the perl version is 
 the same 
  or higher than the specified number)
  
  package Monkey;
  
  use strict;
  
  if(gotperlv(5.6)) {
  our $bar
  our $foo;
  } else {
  use vars qw($bar $foo);
  }
  
  Except the ours would only apply to that black and wouldn't do too
  much good if I'm understanding this right. And also would 
 it not always
  do the use vars since it gets done in the BEGIN black ?
 
 Yep -- you're right on both counts.  If you want to support 
 older versions of perl ($]  5.006) you just have to use 
 vars and forget 
 about our.
 
 If you don't care about older perls (and 5.005_03 is getting 
 kind of mouldy) then do something like
 
 use 5.006;
 
 use base qw(Exporter);

And that brings up another issue:
what is the difference between:
our @ISA = qw(Exporter);
and
use base qw(Exporter);

Is one more compatible with certain versions or better or worse ??
It seems use base would be better since it handles @ISA and will do a better job at it 
than I.
A little OT but why not!

Dan

 our @EXPORT = qw(...);
 
 -- 
 Steve
 

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



RE: dealing with dates

2003-10-28 Thread Harter, Douglas
Do a search on www.cpan.org for Date::Pcalc. This is a whole series of Perl functions 
dealing with date calculations. (And I didn't even write them.)



 -Original Message-
 From: Steve Main [mailto:[EMAIL PROTECTED]
 Sent: Tuesday, October 28, 2003 1:15 PM
 To: [EMAIL PROTECTED]
 Subject: dealing with dates
 
 
 
 
 Hello list,
 
 I am having a problem coming up with a solution to compare 
 and find the
 difference between two dates.
 
 One of the dates is a GMT date while the other is PST(or PDT) so my
 first
 Problem is converting the local date to GMT which is fine 
 unless I want
 to automagically detect the hour back or ahead.  So I guess my
 question is does anyone have a slick way to convert a date to 
 GMT and a
 way to get the number of days between the two dates?
 
 Thanks
 
 Steve
 
 
 -- 
 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: our vs. use vars

2003-10-28 Thread Steve Grazzini
On Tue, Oct 28, 2003 at 01:44:58PM -0600, Dan Muey wrote:
 If you don't care about older perls (and 5.005_03 is getting 
 kind of mouldy) then do something like
 
 use 5.006;
 
 use base qw(Exporter);
 
 And that brings up another issue:
 what is the difference between:
   our @ISA = qw(Exporter);
 and
   use base qw(Exporter);
 
 Is one more compatible with certain versions or better or worse ??

Don't forget that all these pragmatic modules have manpages:

% perldoc base

 It seems use base would be better since it handles @ISA and will do a 
 better job at it than I.

I'm sure you would have done a fine job.  :-)

But the use base approach will also require() the module, so it
can reduce the amount of boilerplate at the top of your module.

#
# this is more readable...
#
package Foo;
use base qw(Exporter Dynaloader);

#
# than this
#
package Foo;
require Exporter;
require Dynaloader;
our @ISA = qw(Exporter Dynaloader);

-- 
Steve

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



RE: our vs. use vars

2003-10-28 Thread Dan Muey
 On Tue, Oct 28, 2003 at 01:44:58PM -0600, Dan Muey wrote:
  If you don't care about older perls (and 5.005_03 is getting
  kind of mouldy) then do something like
  
  use 5.006;
  
  use base qw(Exporter);
  
  And that brings up another issue:
  what is the difference between:
  our @ISA = qw(Exporter);
  and
  use base qw(Exporter);
  
  Is one more compatible with certain versions or better or worse ??
 
 Don't forget that all these pragmatic modules have manpages:
 
 % perldoc base
 
  It seems use base would be better since it handles @ISA and 
 will do a
  better job at it than I.
 
 I'm sure you would have done a fine job.  :-)

Thanks for the vote of confidence!

 
 But the use base approach will also require() the module, 
 so it can reduce the amount of boilerplate at the top of your module.
 
 #
 # this is more readable...
 #
 package Foo;
 use base qw(Exporter Dynaloader);
 
 #
 # than this
 #
 package Foo;
 require Exporter;
 require Dynaloader;
 our @ISA = qw(Exporter Dynaloader);

That's what I figured, thanks fo rthe sanity check, I think I've got it!

 
 -- 
 Steve
 

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



Net::SMTP auth()

2003-10-28 Thread Dan Muey
Any one know at what point one needs to do auth() in a standard Net::SMTP session?

 Do I do it first thing after new or ??

I'm currently doing:

new()
mail()
to()
data()
datasend()
quit()

So where do I put auth() in all that?

Thanks!

Dan

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



Re: array of elements

2003-10-28 Thread Andrew Gaffney
Steve Grazzini wrote:
On Mon, Oct 27, 2003 at 09:52:20PM -0600, Andrew Gaffney wrote:

I have an array of keywords that I need to generate. I have 2 separate 
input files. The first one contains the defaults. The second input file 
contains additions and overrides. For example, first input:

key1 key2 key3 key4 key5 key6 key7

second input:

-key3 -key5 key8 key9

end result:

key1 key2 key4 key6 key7 key8 key9

What is the easiest/fastest way to do this?


my @array = do { 
local @ARGV = qw(default.txt override.txt);
local $^I;

my %params;
while () {
foreach (split) {
if (s/^-//) {
delete $params{$_};
}
else {
$params{$_}++
}
}
}
sort keys %params;
};
Thank you.

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


RE: Net::SMTP auth()

2003-10-28 Thread Dan Muey
 The sequence is:
 
 new()
 auth()
 mail()
 to()
 data()
 datasend()
 dataend()
 quit()
 
 Josimar

Thanks Josimar!


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



Use of uninitialized value

2003-10-28 Thread B. Fongo
What may be wrong with my codes?  Perl complains of use of uninitialized
value at addition and in range (or flop).

Thanks

#

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

my ($xi, $i, @numbers, @slice);
@numbers = (1..10);
$i = 0;
$xi = 0;

open(RS, perd.dat) || die Could not open file. $!\n;
for (my $z = 0; $z = $#numbers; $z++){


foreach  (@numbers){
@slice = @numbers[$xi,  $numbers[$i] ..
$numbers[$i]+4]; # Use of uninitialized value at here?
print RS @slice\n;
$i++;
}

$xi++;

}

  close(RS);

###
Babs


Re: Use of uninitialized value

2003-10-28 Thread Steve Grazzini
On Tue, Oct 28, 2003 at 10:51:20PM +0100, B. Fongo wrote:
 What may be wrong with my codes?  Perl complains of use of uninitialized
 value at addition and in range (or flop).
 
 #!/usr/bin/perl -w
 use strict;
 
 my ($xi, $i, @numbers, @slice);
 @numbers = (1..10);
 $i = 0;
 $xi = 0;
 
 open(RS, perd.dat) || die Could not open file. $!\n;
 for (my $z = 0; $z = $#numbers; $z++){
 foreach  (@numbers){
 @slice = @numbers[$xi,  $numbers[$i] ..  $numbers[$i]+4];
  # Use of uninitialized value at here?
 print RS @slice\n;
 $i++;
  }
   $xi++;
 }

You could write it more cleanly like this:

  my $path = 'perd.dat';
  open my $rs, $path  or die open: $path: $!;

  my @numbers = 1..10;

  for my $z (0..$#numbers) {
for my $i (0..$#numbers) {
  print $rs @numbers[$z, $numbers[$i]..$numbers[$i]+4];
}
  }

Which gets rid of some of the unused variables and uses the more
perlish foreach() loop.  The problem is that you're indexing off
the end of @numbers -- I assumed that you meant to reset $i each
time through the outer loop (?) which fixes part of the problem,
but you still have the situation where $i  4.

Look at the result of this expression when $z = 0 and $i = 5.

   print $rs @numbers[$z, $numbers[$i] .. $numbers[$i] + 4];
  --  print $rs @numbers[ 0, $numbers[5]  .. $numbers[5]  + 4];
  --  print $rs @numbers[ 0, 6.. 6+ 4];
  --  print $rs @numbers[ 0, 6.. 10  ];
  --  print $rs @numbers[ 0,6, 7, 8, 9,  10  ];

So the array slice yields:

  --  print $rs   1,7, 8, 9, 10, undef;

And this generates an uninitialized value warning.

The next time through the inner loop, you end up with:

   print $rs @numbers[0, 7 .. 11]
  --  print $rs @numbers[0, 7, 8, 9, 10, 11]
  --  print $rs 1, 8, 9, 10, undef, undef;

Which generates two warnings, and so forth.

What are you really trying to do here?

-- 
Steve

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



Re: Parse and Compare Text Files

2003-10-28 Thread Kevin Pfeiffer
In article [EMAIL PROTECTED], Mike M wrote:
 I've found this script on another message board that is close, but still
 doesn't work with my data.  Any ideas on modifications?  I think my
 biggest problem is the regex in the split function, because what this does
 is match ONLY against the first column in the line, when I need it to
 match anything
 in the fourth column.  Thanks for your help, and I'll see what I can do
 about allowing playboy.com (although since I work at a public school
 district, it might not be a good idea!)   

Even worse (I had assumed this was for an employer)...

 The script follows:

[...]
 while(my $line=FILE2)
 {
 my($num);
 ($num, undef)=split /\s+/,$line, 2;
[...]

This, I believe, says split $line on white space into two pieces; place
first piece into $num and throw away the rest.

If you look at perldoc -f split and then try a couple tests, you should be
able to get what you want.

-Kevin (no expert though)

P.S. - No top-posting please.

-- 
Kevin Pfeiffer


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



Re: initializing a closure variable

2003-10-28 Thread Kevin Pfeiffer
In article [EMAIL PROTECTED], Rob Dixon wrote:

 Kevin Pfeiffer wrote:

 I would have thought that this would initialize my $indent variable to 2
 (like setting an initial state for an object), but if I call indent() I
 get nothing back. :-(


 {  # static local variable
my $indent = 2;

sub indent {
   my $increment = shift;
   $indent += $increment if $increment;
   return $indent;
}
 }
 
 By the way, that's not a closure! It's just a subroutine
 with a non-volatile local variable.

Hmmm, does the subroutine need to to only exist as a reference to an
anonymous subroutine to be a closure? I'm going by what I read in Learning
Perl Objects, but I may be misinterpreting what I _thought_ I read.

-- 
Kevin Pfeiffer


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



Newbe needs help

2003-10-28 Thread sadman
Hi all can anyone help with a direct command line syntax for the following
im trying to add text to the end of the last line in a text file like so
aaa
bbb
ccc
Wishing to add ddd on the end of this list.
I have tried the following but it doesnt have quite the desired effect 
any help would be good.

perl -pi -e s/'$'/'ddd'/g script1

This gives me this

aaaddd
dddbbbddd
dddcccddd
dd
ddd


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


RE: Newbe needs help

2003-10-28 Thread Tim Johnson

I would recommend getting a strong grasp of Perl before you start trying to
make one-liners for problems like this, since you can end up making a simple
problem much more complicated.  What's wrong with this:



use strict;
use warnings;
open(OUTFILE,script1) || die Couldn't open script1 for writing!\n;
print OUTFILE ddd\n;
close OUTFILE;



-Original Message-
From: sadman [mailto:[EMAIL PROTECTED] 
Sent: Tuesday, October 28, 2003 2:56 PM
To: [EMAIL PROTECTED]
Subject: Newbe needs help


Hi all can anyone help with a direct command line syntax for the following
im trying to add text to the end of the last line in a text file like so

aaa
bbb
ccc


Wishing to add ddd on the end of this list.
 I have tried the following but it doesnt have quite the desired effect 
any help would be good.

perl -pi -e s/'$'/'ddd'/g script1

This gives me this


aaaddd
dddbbbddd
dddcccddd
dd
ddd



-- 
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: Issue

2003-10-28 Thread Gary Stainburn
On Tuesday 28 Oct 2003 5:42 pm, [EMAIL PROTECTED] wrote:
 Gary,

I think your closer to what I was thinking of.
It makes more sense. Currently, This is what I
Have so far not with your suggestions as of yet.

[snip]

 #
 # Get the host name of system
 #
 my @lines = $telnet-cmd('uname -n');
 my $csv = Text::CSV-new;
 if ( $csv-parse(@lines) ){
my @field = $csv-fields;
for $host (@field){
print OUT_FH $host,,, $ipaddr;
print Found Host...\n;
}
 }

Hi Philip,

I'm not sure why you're using Text::CSV in this context, but other than that, 
wouldn't the above be better placed in a subroutine, e.g.

sub get_response(
  my @lines = $telnet-cmd($_[0]);
  my $csv = Text::CSV-new;
  if ( $csv-parse(@lines) ){
 return $csv-fields;
  }
  return undef;
}

then you could simply do (using my answer from before)

my $OS=(get_response('uname -n'))[0];
die OS not found unless ($OS  defined $whichos{$OS});

my $hostname=(get_response($commands{$OS}{'hostname'}))[0];
print OUTPUT_FH ,$hostname;
etc..

If course, if you made the subroutine only return a single value, it would be 
cleaner to call.

[snip]

 So far this is only testing the solaris commands on the network
 I have access to. I appreciate any other comments you may have.


 -Original Message-
 From: Gary Stainburn [mailto:[EMAIL PROTECTED]
 Sent: Tuesday, October 28, 2003 8:36 AM
 To: [EMAIL PROTECTED]; [EMAIL PROTECTED]
 Subject: Re: Issue
 y

 On Monday 27 Oct 2003 7:32 pm, [EMAIL PROTECTED] wrote:
  Hi,
 
I'm trying to accomplish some task using perl. So let
me describe what I have.
 
I have several systems of the following:
 
Unix:
  Sun - Solaris
  HP - HPUX
 
Windows:
  Dell - Windows 2k
 
   Each of these OS's have specific commands that are specific
   not only to the OS but to the hardware as well. Wouldn't it be
   better if I created a header file that contains these commands
   and assigned them to a common variable?
 
   Example:
  $memory = 'prtconf | grep Memory | awk '{print $3}'

 [snip]

 Hi Philip,

 I'd try something like (asuming $detail is part of the header returned from
 the Net::telnet connect)

 my %whichos=('Solarix'='sol','Aix'='aix','microsoft'='W2K');
 my %commands=('sol'={'memory'='prtconf | grep Memory | awk '{print $3}',
   'diskfree'='..'}
   'aix'={'memory'='...',
   'diskfree'='..'}
   'W2k'={'memory'='',
   'diskfree'='..'});

 my $OS='';
 foreach my $regex (keys %whichos) {
   $OS=$whichos{$regex} if ($details=~/$regex/i);
 }
 die cannot find OS unless  ( $OS  defined {$commands{$OS});

 then simply use %commands{$OS}{memory} to get the command you want

  Phillip Bruce
  ISC Consultant, System Architect
  Location: Dublin, CA
  * Cell: 408-476-8658
  * Office: 925-560-7853
  AIM: OkieUnix

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



Re: Issue

2003-10-28 Thread Gary Stainburn
On Tuesday 28 Oct 2003 7:20 pm, you wrote:
 Gary,

While your structure make sense. I'm a little lost here.

Do you mind given me the basic on the my %whichos

I don't think I've ever come across this before and need some
Explaination on that.

Thanks
 Phillip

[snip]

 my %whichos=('Solarix'='sol','Aix'='aix','microsoft'='W2K');
 my %commands=('sol'={'memory'='prtconf | grep Memory | awk '{print $3}',
   'diskfree'='..'}
   'aix'={'memory'='...',
   'diskfree'='..'}
   'W2k'={'memory'='',
   'diskfree'='..'});

 my $OS='';
 foreach my $regex (keys %whichos) {
   $OS=$whichos{$regex} if ($details=~/$regex/i);
 }

What I'm doing here, is using a list of regex's (actually, in this case 
they're simply substrings), that I will compare with a given variable within 
a loop.  Once I find a match, I use that regex to access a hash which 
contains the key to the hash I really want to access.

In this way, I can compare the header returned from the Net::telnet to find 
the OS I want, and then use that to access the hash within the hash of 
commands.

You won't actually need this because you're calling 'uname -s' to select it.


 die cannot find OS unless  ( $OS  defined {$commands{$OS});

 then simply use %commands{$OS}{memory} to get the command you want

  Phillip Bruce
  ISC Consultant, System Architect
  Location: Dublin, CA
  * Cell: 408-476-8658
  * Office: 925-560-7853
  AIM: OkieUnix

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



RE: dealing with dates

2003-10-28 Thread Steve Main
Thanks for the response.

I have been using Date::Pcalc but I guess what I have been unable to
find is an example of how to get the localtime from the system in GMT
format, with the offset already applied.  As I understand as the local
time falls back an hour or springs ahead the offset will change and I
would like to find a way for my program to automagiclly deal with it.
If Pcalc can do this then I haven't been able to figure it out.

thanks

-Original Message-
From: Harter, Douglas [mailto:[EMAIL PROTECTED] 
Sent: Tuesday, October 28, 2003 11:58 AM
To: Steve Main; [EMAIL PROTECTED]
Subject: RE: dealing with dates

Do a search on www.cpan.org for Date::Pcalc. This is a whole series of
Perl functions dealing with date calculations. (And I didn't even write
them.)



 -Original Message-
 From: Steve Main [mailto:[EMAIL PROTECTED]
 Sent: Tuesday, October 28, 2003 1:15 PM
 To: [EMAIL PROTECTED]
 Subject: dealing with dates
 
 
 
 
 Hello list,
 
 I am having a problem coming up with a solution to compare 
 and find the
 difference between two dates.
 
 One of the dates is a GMT date while the other is PST(or PDT) so my
 first
 Problem is converting the local date to GMT which is fine 
 unless I want
 to automagically detect the hour back or ahead.  So I guess my
 question is does anyone have a slick way to convert a date to 
 GMT and a
 way to get the number of days between the two dates?
 
 Thanks
 
 Steve
 
 
 -- 
 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: Use of uninitialized value

2003-10-28 Thread Charles K. Clarkson
B. Fongo [EMAIL PROTECTED] wrote:
: 
: What may be wrong with my code?  Perl complains of
: use of uninitialized value at addition and in range
: (or flop).

: #
: 
: #!/usr/bin/perl -w
: use strict;
: 
: my ($xi, $i, @numbers, @slice);
: @numbers = (1..10);

This array has 10 items in it. @number[ 0 .. 9 ]

: $i = 0;
: $xi = 0;
: 
: open(RS, perd.dat) || die Could not open file. $!\n;
: for (my $z = 0; $z = $#numbers; $z++){
:   
:   
:   foreach  (@numbers){

Comment the next two lines out and add:

printf
%3s: [EMAIL PROTECTED] = [EMAIL PROTECTED] \$number[ %s ], .
\$number[ %2s ] .. \$number[ %2s ] + 4 ]\n,
++$iter, $xi, $i, $i, $#numbers;

:   @slice = @numbers[$xi,  $numbers[$i] ..
:   $numbers[$i]+4];
:   print RS @slice\n;
:   $i++;
:   }
:   
:   $xi++;
:   
: }
:   
:   close(RS);

This is some of what I got. Notice that by
the seventh iteration you are using indexes
for @numbers that have no value. $number[6]
when incremented by 4 gives an index of 10.


  1: @slice = @numbers[ $number[ 0 ],$number[  0 ] .. $number[  0 ] + 4 ]
  2: @slice = @numbers[ $number[ 0 ],$number[  1 ] .. $number[  1 ] + 4 ]
  3: @slice = @numbers[ $number[ 0 ],$number[  2 ] .. $number[  2 ] + 4 ]
  4: @slice = @numbers[ $number[ 0 ],$number[  3 ] .. $number[  3 ] + 4 ]
  5: @slice = @numbers[ $number[ 0 ],$number[  4 ] .. $number[  4 ] + 4 ]
  6: @slice = @numbers[ $number[ 0 ],$number[  5 ] .. $number[  5 ] + 4 ]
  7: @slice = @numbers[ $number[ 0 ],$number[  6 ] .. $number[  6 ] + 4 ]
--
  8: @slice = @numbers[ $number[ 0 ],$number[  7 ] .. $number[  7 ] + 4 ]
--
  9: @slice = @numbers[ $number[ 0 ],$number[  8 ] .. $number[  8 ] + 4 ]
--
 10: @slice = @numbers[ $number[ 0 ],$number[  9 ] .. $number[  9 ] + 4 ]
--
 11: @slice = @numbers[ $number[ 1 ],$number[ 10 ] .. $number[ 10 ] + 4 ]
--
 12: @slice = @numbers[ $number[ 1 ],$number[ 11 ] .. $number[ 11 ] + 4 ]
--
[arrows added]


HTH,

Charles K. Clarkson
-- 
Head Bottle Washer,
Clarkson Energy Homes, Inc.
Mobile Home Specialists
254 968-8328
















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



RE: Issue

2003-10-28 Thread Bruce_Phillip
Gary,

   That was my reasons for my question originally, I've already
   Modified the new version of the script to for loop the routine
   So it could go thru the commands when the OS has been determined.
   I really do appreciate that feedback. 

   My original reasoning for using Text::CSV cause it
   Could parse the @lines statement into fields cause I
   Was getting other characters that needed to be separated
   after the telnet call. I probably could have used the
   chomp routine to deal with that instead.

Phillip

-Original Message-
From: Gary Stainburn [mailto:[EMAIL PROTECTED] 
Sent: Tuesday, October 28, 2003 3:04 PM
To: [EMAIL PROTECTED]
Cc: [EMAIL PROTECTED]
Subject: Re: Issue

On Tuesday 28 Oct 2003 5:42 pm, [EMAIL PROTECTED] wrote:
 Gary,

I think your closer to what I was thinking of.
It makes more sense. Currently, This is what I
Have so far not with your suggestions as of yet.

[snip]

 #
 # Get the host name of system
 #
 my @lines = $telnet-cmd('uname -n');
 my $csv = Text::CSV-new;
 if ( $csv-parse(@lines) ){
my @field = $csv-fields;
for $host (@field){
print OUT_FH $host,,, $ipaddr;
print Found Host...\n;
}
 }

Hi Philip,

I'm not sure why you're using Text::CSV in this context, but other than
that, 
wouldn't the above be better placed in a subroutine, e.g.

sub get_response(
  my @lines = $telnet-cmd($_[0]);
  my $csv = Text::CSV-new;
  if ( $csv-parse(@lines) ){
 return $csv-fields;
  }
  return undef;
}

then you could simply do (using my answer from before)

my $OS=(get_response('uname -n'))[0];
die OS not found unless ($OS  defined $whichos{$OS});

my $hostname=(get_response($commands{$OS}{'hostname'}))[0];
print OUTPUT_FH ,$hostname;
etc..

If course, if you made the subroutine only return a single value, it would
be 
cleaner to call.

[snip]

 So far this is only testing the solaris commands on the network
 I have access to. I appreciate any other comments you may have.


 -Original Message-
 From: Gary Stainburn [mailto:[EMAIL PROTECTED]
 Sent: Tuesday, October 28, 2003 8:36 AM
 To: [EMAIL PROTECTED]; [EMAIL PROTECTED]
 Subject: Re: Issue
 y

 On Monday 27 Oct 2003 7:32 pm, [EMAIL PROTECTED] wrote:
  Hi,
 
I'm trying to accomplish some task using perl. So let
me describe what I have.
 
I have several systems of the following:
 
Unix:
  Sun - Solaris
  HP - HPUX
 
Windows:
  Dell - Windows 2k
 
   Each of these OS's have specific commands that are specific
   not only to the OS but to the hardware as well. Wouldn't it be
   better if I created a header file that contains these commands
   and assigned them to a common variable?
 
   Example:
  $memory = 'prtconf | grep Memory | awk '{print $3}'

 [snip]

 Hi Philip,

 I'd try something like (asuming $detail is part of the header returned
from
 the Net::telnet connect)

 my %whichos=('Solarix'='sol','Aix'='aix','microsoft'='W2K');
 my %commands=('sol'={'memory'='prtconf | grep Memory | awk '{print $3}',
   'diskfree'='..'}
   'aix'={'memory'='...',
   'diskfree'='..'}
   'W2k'={'memory'='',
   'diskfree'='..'});

 my $OS='';
 foreach my $regex (keys %whichos) {
   $OS=$whichos{$regex} if ($details=~/$regex/i);
 }
 die cannot find OS unless  ( $OS  defined {$commands{$OS});

 then simply use %commands{$OS}{memory} to get the command you want

  Phillip Bruce
  ISC Consultant, System Architect
  Location: Dublin, CA
  * Cell: 408-476-8658
  * Office: 925-560-7853
  AIM: OkieUnix

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



How to store arrays in hashes or objects?

2003-10-28 Thread Richard Heintze
I had emailed this query out previously but since I
never saw my own email in the digest, I'm assuming
that it never made it to the [EMAIL PROTECTED] list.
Please forgive me if it did and I did not see it (my
SPAM filter might have eaten it).


Question #1
---
I have an array stored in an object and I trying to
compute the length of the array. This seemed to work
initially:

my $nColumns = [EMAIL PROTECTED]{component_titles}}}+1;

Something changed, I don't know what, and perl started
dying on the above statement with no error message or
explanation. I had to resort to this technique:

my @ComponentTitles = @{$me-{component_titles}};
my $nColumns = $#ComponentTitles+1 ; 

This seems to work, but I don't like it because it
uses a supefluous deep copy. Can someone tell me how
to do it in one statement without a superfluous deep
copy?

Question #2
---

Incidently, I believe I'm storing an array here
instead of a reference to an array.

I don't really do anything to create to create this
array -- I just start storing elements like this:

  $me-{component_titles}[0] = xyz;

Is there a better way to populate this array? Perhaps
with a declaration or something?

Question #3
---

I tried to create a second array and store it by
reference like this:

my $a = [];
$me-{a} = \$a;
$a-[0] = 1;
$a-[1] = 23;
etc...

But when I tried to retrieve the array, there was
nothing there:

print $me-{a}-[0];

I cured the problem by storing elements directly, but
I did not want to make a new copy of the array (I
wanted to store a reference to the original array).

  $ii = 0;
  $me-{a}-[$ii++] = $_ foreach (@{$a});


Why does not this work:
 $me-{a} = \$a;

  Thanks,
 Siegfried

__
Do you Yahoo!?
Exclusive Video Premiere - Britney Spears
http://launch.yahoo.com/promos/britneyspears/

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



Re: How to store arrays in hashes or objects?

2003-10-28 Thread Jeff 'japhy' Pinyan
On Oct 28, Richard Heintze said:

I have an array stored in an object and I trying to
compute the length of the array. This seemed to work
initially:

The LENGTH of an array is @array or @{ $ref_to_array }.  The LAST INDEX of
an array is $#array or $#{ $ref_to_array }.

my $nColumns = [EMAIL PROTECTED]{component_titles}}}+1;

You want my $nColumns = $#{ $me-{component_titles} }+1, or even better,
just my $nColumns = @{ $me-{component_titles} }.

I don't really do anything to create to create this
array -- I just start storing elements like this:

  $me-{component_titles}[0] = xyz;

Is there a better way to populate this array? Perhaps
with a declaration or something?

That's ok.  You can start by saying

  $me-{component_titles} = [];

but that's not necessary.  If you treat an undefined value as an array
reference, it becomes an array reference.  This process is called
autovivification (automatically coming to life).

my $a = [];
$me-{a} = \$a;
$a-[0] = 1;
$a-[1] = 23;

print $me-{a}-[0];

This is because $a is a reference to an array ALREADY.  Storing \$a in
$me-{a} makes $me-{a} a reference to a reference to an array.  Just
store $a, not \$a.

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


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



DBI

2003-10-28 Thread Andrew Gaffney
Is there anything wrong with this code?

my $sth = $dbh-prepare($query);
$sth-execute;
my $ref = $sth-fetchrow_hashref;
while($ref) {
  $totalhrs += $ref-{quantity};
  my $tmpdate = $ref-{id};
  $tmpdate =~ s/(\d{4})(\d{2})(\d{2})\d+/$2-$3-$1/;
  print trtd$tmpdate/tdtd$ref-{item}/tdtd$ref-{quantity}/td;
  $ref = $sth-fetchrow_hashref;
  if($ref-{id} eq $lastinvid) {
print td$ref-{fname} $ref-{lname}/td/tr\n;
$ref = $sth-fetchrow_hashref;
  } else {
print tdN/A/td/tr\n;
  }
  $lastinvid = $ref-{id};
}
I get this error over and over again in my Apache log:

DBD::mysql::st fetchrow_hashref failed: fetch() without execute() at 
/home/httpd/cgi-bin/report-myflights.pl line 38.
[Tue Oct 28 22:13:06 2003] [error] 17457: ModPerl::PerlRun: DBD::mysql::st 
fetchrow_hashref failed: fetch() without execute() at 
/home/httpd/cgi-bin/report-myflights.pl line 38.

It will cycle through the loop like 10 times and then die. I get output and an Apache 
error message all in one page. BTW, line 38 is the first '$ref = $sth-fetchrow_hashref' 
in the while loop.

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


Re: DBI

2003-10-28 Thread Andrew Gaffney
Andrew Gaffney wrote:
Is there anything wrong with this code?

my $sth = $dbh-prepare($query);
$sth-execute;
my $ref = $sth-fetchrow_hashref;
while($ref) {
  $totalhrs += $ref-{quantity};
  my $tmpdate = $ref-{id};
  $tmpdate =~ s/(\d{4})(\d{2})(\d{2})\d+/$2-$3-$1/;
  print 
trtd$tmpdate/tdtd$ref-{item}/tdtd$ref-{quantity}/td;
  $ref = $sth-fetchrow_hashref;
  if($ref-{id} eq $lastinvid) {
print td$ref-{fname} $ref-{lname}/td/tr\n;
$ref = $sth-fetchrow_hashref;
  } else {
print tdN/A/td/tr\n;
  }
  $lastinvid = $ref-{id};
}

I get this error over and over again in my Apache log:

DBD::mysql::st fetchrow_hashref failed: fetch() without execute() at 
/home/httpd/cgi-bin/report-myflights.pl line 38.
[Tue Oct 28 22:13:06 2003] [error] 17457: ModPerl::PerlRun: 
DBD::mysql::st fetchrow_hashref failed: fetch() without execute() at 
/home/httpd/cgi-bin/report-myflights.pl line 38.

It will cycle through the loop like 10 times and then die. I get output 
and an Apache error message all in one page. BTW, line 38 is the first 
'$ref = $sth-fetchrow_hashref' in the while loop.
Nevermind, it was my own fault. It was running out of input. I changed that line to:

if(!($ref = $sth-fetchrow_hashref)) {
  last;
}
--
Andrew Gaffney
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


RE: DBI

2003-10-28 Thread Tim Johnson

Another way to do it is:

while($ref = $sth-fetchrow_hashref){
   do something...
}

-Original Message-
From: Andrew Gaffney [mailto:[EMAIL PROTECTED] 
Sent: Tuesday, October 28, 2003 10:00 PM
To: [EMAIL PROTECTED]
Subject: Re: DBI


Andrew Gaffney wrote:
 Is there anything wrong with this code?
 
 my $sth = $dbh-prepare($query);
 $sth-execute;
 my $ref = $sth-fetchrow_hashref;
 while($ref) {
   $totalhrs += $ref-{quantity};
   my $tmpdate = $ref-{id};
   $tmpdate =~ s/(\d{4})(\d{2})(\d{2})\d+/$2-$3-$1/;
   print
 trtd$tmpdate/tdtd$ref-{item}/tdtd$ref-{quantity}/td;
   $ref = $sth-fetchrow_hashref;
   if($ref-{id} eq $lastinvid) {
 print td$ref-{fname} $ref-{lname}/td/tr\n;
 $ref = $sth-fetchrow_hashref;
   } else {
 print tdN/A/td/tr\n;
   }
   $lastinvid = $ref-{id};
 }
 
 I get this error over and over again in my Apache log:
 
 DBD::mysql::st fetchrow_hashref failed: fetch() without execute() at
 /home/httpd/cgi-bin/report-myflights.pl line 38.
 [Tue Oct 28 22:13:06 2003] [error] 17457: ModPerl::PerlRun: 
 DBD::mysql::st fetchrow_hashref failed: fetch() without execute() at 
 /home/httpd/cgi-bin/report-myflights.pl line 38.
 
 It will cycle through the loop like 10 times and then die. I get 
 output
 and an Apache error message all in one page. BTW, line 38 is the first 
 '$ref = $sth-fetchrow_hashref' in the while loop.

Nevermind, it was my own fault. It was running out of input. I changed that
line to:

if(!($ref = $sth-fetchrow_hashref)) {
   last;
}

-- 
Andrew Gaffney


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