Re: How to concatenate nested arrays of strings

2004-12-27 Thread John W. Krahn
Siegfried Heintze wrote:
I'm writing perl cgi and I like to buffer my output in an array of strings.
I just decided it would be very useful to be able to have nested arrays.
Below is a little function that does what a want. However,
(1) Is there a more compact way of performing this nested concatenation?
(2) Hasn't someone else already written a function like this that is
part of the standard repertoire? 

(3) Assuming I have to use my own function below: My code only
concatenates the elements first argument. How can I concatenate all the
elements of all the function arguments?
(4) Is it possible to have nested lists? How would I modify my code to
handle those?
use strict;
use warnings;
sub concat {
  my $sResult = shift;
  return join("", map {  ref($_) eq "ARRAY"? concat($_) :"$_ " }
@{$sResult});
}
print concat (["hello ", "there", ["a", "nested", "array"], "world!"]);
Is this what you want?
$ perl -le'
sub concat { return join " ", map ref eq "ARRAY" ? concat( @$_ ) : $_, @_ }
print concat( [ "hello ", "there", [ "a", "nested", "array" ], "world!" ] );
'
hello  there a nested array world!

John
--
use Perl;
program
fulfillment
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 



to check directory permission and owner

2004-12-27 Thread Chandrakant Reddy
Hi 
  How do I check  whether user's home directory exist or not, & if
exists then whether it is owned by his uid

The perl script will have this information :  
username:x:20205:1:my name :/home/username:/bin/bash

regards
CVR

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




Re: Can someone translate a small .PY to Perl?

2004-12-27 Thread Andrew Gaffney
Randal L. Schwartz wrote:
"Andrew" == Andrew Gaffney <[EMAIL PROTECTED]> writes:

Andrew> while `/bin/true`;
Uh, what?
Execute /bin/true,
take its output
if its output is non-null, continue.
Last I checked, /bin/true outputs nothing. :)
Maybe you wanted:
while true;
do; ...; done
Or more commonly:
while :; do
...
done
because the ":" command is true.
It works for me. That's the way I'd seen it done when I was learning bash. I 
believe the while checks the return value, not the output of the command.

--
Andrew Gaffney
Network Administrator
Skyline Aeronautics, LLC.
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 



Re: Can someone translate a small .PY to Perl?

2004-12-27 Thread Randal L. Schwartz
> "Andrew" == Andrew Gaffney <[EMAIL PROTECTED]> writes:

Andrew> while `/bin/true`;

Uh, what?

Execute /bin/true,
take its output
if its output is non-null, continue.

Last I checked, /bin/true outputs nothing. :)

Maybe you wanted:

while true;
do; ...; done

Or more commonly:

while :; do
...
done

because the ":" command is true.

-- 
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
 http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!

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




How to concatenate nested arrays of strings

2004-12-27 Thread Siegfried Heintze
I'm writing perl cgi and I like to buffer my output in an array of strings.
I just decided it would be very useful to be able to have nested arrays.

 

Below is a little function that does what a want. However,

(1) Is there a more compact way of performing this nested concatenation?

(2) Hasn't someone else already written a function like this that is
part of the standard repertoire? 

(3) Assuming I have to use my own function below: My code only
concatenates the elements first argument. How can I concatenate all the
elements of all the function arguments?

(4) Is it possible to have nested lists? How would I modify my code to
handle those?

 

Thanks,

Siegfried

 

use strict;

use warnings;

sub concat {

  my $sResult = shift;

  return join("", map {  ref($_) eq "ARRAY"? concat($_) :"$_ " }
@{$sResult});

}

print concat (["hello ", "there", ["a", "nested", "array"], "world!"]);



Re: Can someone translate a small .PY to Perl?

2004-12-27 Thread Andrew Gaffney
S. David Rose wrote:
Sorry, sir.  I did not state it boldly enough, but this is to be used on a
Netware server.  There is no port for Python on Netware, but PERL is
available.  Obviously, bash scripting will not work 
It's Netware 5.0 / 5.1 for my servers.
Ah, sorry. I didn't catch that part. Also, reply to the list instead of the 
sender.
--
Andrew Gaffney
Network Administrator
Skyline Aeronautics, LLC.
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 



Re: Can someone translate a small .PY to Perl?

2004-12-27 Thread Andrew Gaffney
GMane Python wrote:
Hello Everyone.
Whil e reading the Python Cookbook as a means of learning Python, I
came across the script by Nicola Larosa.  Not knowing anything about PERL, I
was wondering if there were a translation in PERL so I could have my Netware
servers send heartbeats to the heartbeat server?
I am beginning to learn the Python language after a 10-year
programming 'vacation' from my last class in college.  Looking at this, I
think it'll end up being a rather quick translation, but although I'm
searching for translations, I'd really like to be able to just get my
Netware server to send heartbeats and not take flack from my boss for
'having to learn PERL' just to get the server to send a beat packet, so
that's why I'm asking for someone's help who knows the syntax of the
language.
Thanks!
Dave
  Title: PyHeartbeat - detecting inactive computers
  Submitter: Nicola Larosa
  # Filename: HeartbeatClient.py
  """Heartbeat client, sends out an UDP packet periodically"""
  import socket, time
  SERVER_IP = '127.0.0.1'; SERVER_PORT = 43278; BEAT_PERIOD = 5
  print ('Sending heartbeat to IP %s , port %d\n'
  'press Ctrl-C to stop\n') % (SERVER_IP, SERVER_PORT)
  while True:
  hbSocket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
  hbSocket.sendto('PyHB', (SERVER_IP, SERVER_PORT))
  if __debug__: print 'Time: %s' % time.ctime()
  time.sleep(BEAT_PERIOD)


Both Perl or Python are overkill for this. This can be done with a very simple 
bash script. It only requires netcat.

#!/bin/bash
SERVER_IP="127.0.0.1"
SERVER_PORT=43278
BEAT_PERIOD=5
while `/bin/true`;
do
  echo "pyHB" | nc -u -q 0 $SERVER_IP $SERVER_PORT
  sleep ${BEAT_PERIOD}s
done
--
Andrew Gaffney
Network Administrator
Skyline Aeronautics, LLC.
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 



Can someone translate a small .PY to Perl?

2004-12-27 Thread GMane Python
Hello Everyone.

Whil e reading the Python Cookbook as a means of learning Python, I
came across the script by Nicola Larosa.  Not knowing anything about PERL, I
was wondering if there were a translation in PERL so I could have my Netware
servers send heartbeats to the heartbeat server?
I am beginning to learn the Python language after a 10-year
programming 'vacation' from my last class in college.  Looking at this, I
think it'll end up being a rather quick translation, but although I'm
searching for translations, I'd really like to be able to just get my
Netware server to send heartbeats and not take flack from my boss for
'having to learn PERL' just to get the server to send a beat packet, so
that's why I'm asking for someone's help who knows the syntax of the
language.

Thanks!

Dave


  Title: PyHeartbeat - detecting inactive computers
  Submitter: Nicola Larosa


  # Filename: HeartbeatClient.py

  """Heartbeat client, sends out an UDP packet periodically"""

  import socket, time

  SERVER_IP = '127.0.0.1'; SERVER_PORT = 43278; BEAT_PERIOD = 5

  print ('Sending heartbeat to IP %s , port %d\n'
  'press Ctrl-C to stop\n') % (SERVER_IP, SERVER_PORT)
  while True:
  hbSocket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
  hbSocket.sendto('PyHB', (SERVER_IP, SERVER_PORT))
  if __debug__: print 'Time: %s' % time.ctime()
  time.sleep(BEAT_PERIOD)





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




Re: Variable Value into MySQL DB

2004-12-27 Thread Jonathan Paton
> Then, I´d like to record these variables values in the db...
> But I just can´t get it done!

There is something more important (IMHO) than just having
working code.  Your code appears to have no concern for
security, and could be used to compromise your server.

You SHOULD enable Taint checking, warnings (this appears
to have been forgotten) and strict.  Some advice may be
found in the docs:

perldoc perlsec

> I´m using Net::MySQL to do so...

Reading the documentation for the latest 0.08 (!!!) version that
I can find is uncomfortable.  There is no mention of the risk of
SQL code injection, and no apparent means to avoid it.

Is the DBI unsuitable for some reason?  By preparing statements
first, using the DBI, you can make code injection impossible.

Sorry to spoil your effort with a word on security.  This type of
security issue is common and well known, so you can't rely on
nobody noticing.

Jonathan Paton

-- 
#!perl
$J=' 'x25 ;for (qq< 1+10 9+14 5-10 50-9 7+13 2-18 6+13
17+6 02+1 2-10 00+4 00+8 3-13 3+12 01-5 2-10 01+1 03+4
00+4 00+8 1-21 01+1 00+5 01-7 >=~/ \S\S \S\S /gx) {m/(
\d+) (.+) /x,, vec$ J,$p +=$2 ,8,= $c+= +$1} warn $J,,

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




Re: Variable Value into MySQL DB

2004-12-27 Thread Joe Mecklin



On Mon, 27 Dec 2004 16:08:20 -0200 (BRST),
[EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
> Hi guys,
> 
> I´m having kind´a problem... Here´s the deal... I´m using CGI so that the
> user can, by a browser, type the data that must be recorded into the
> database.
> I use CGI library to do that... the user type what he wants in the fields,
> and these values are sent to some variables... Then, I´d like to record
> these variables values in the db... But I just can´t get it done!
> I´m using Net::MySQL to do so... when I test the script by writing fixed
> values in it, it works fine... but when i try to record variables values
> it doesn´t work... could you help me? Here´s my code:
> #!/usr/bin/perl
> use strict;
> use CGI qw/:standard/;
>  use Net::MySQL;
> print header,
> start_html('Cadastro de Processos'),
> h1('Cadastramento Processos'),
> start_form,
> "Numero do Processo: ",textfield('process'),br,
> "Tipo do Processo: [1-2]",textfield('type'),br,
> "Nome do advogado: ",textfield('name'),br,
> "Email do advogado: ",textfield('email'),br,
> submit,
> end_form,
> hr,
> my $process =param(process);
> my $lawyer =param(name);
> my $email =param(email);
> my $type =param(type);
> 
>   my $mysql = Net::MySQL->new(
>   database => 'tj',
>   user => 'user',
>   password => 'pass'
>   );
> 
>$mysql->query(q{
>INSERT INTO processo (process, name, email, type) VALUES ($process,
> $lawyer, $email, $type)

try enclosing each VALUES variable in double quotes, like so:

... VALUES ("$process", "$lawyer", "$email", "$type")

i believe each non-numeric value needs to be enclosed in quotes - even
as a variable - and the double quotes will allow for proper
interpolation of the variable's values.

>});
> 
> --
> 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: Variable Value into MySQL DB

2004-12-27 Thread Ron Goral


> -Original Message-
> From: [EMAIL PROTECTED]
> [mailto:[EMAIL PROTECTED]
> Sent: Monday, December 27, 2004 12:08 PM
> To: beginners@perl.org
> Subject: Variable Value into MySQL DB
>
>
> Hi guys,
>
> I´m having kind´a problem... Here´s the deal... I´m using CGI so that the
> user can, by a browser, type the data that must be recorded into the
> database.
> I use CGI library to do that... the user type what he wants in the fields,
> and these values are sent to some variables... Then, I´d like to record
> these variables values in the db... But I just can´t get it done!
> I´m using Net::MySQL to do so... when I test the script by writing fixed
> values in it, it works fine... but when i try to record variables values
> it doesn´t work... could you help me? Here´s my code:
> #!/usr/bin/perl
> use strict;
> use CGI qw/:standard/;
>  use Net::MySQL;
> print header,
> start_html('Cadastro de Processos'),
> h1('Cadastramento Processos'),
> start_form,
> "Numero do Processo: ",textfield('process'),br,
> "Tipo do Processo: [1-2]",textfield('type'),br,
> "Nome do advogado: ",textfield('name'),br,
> "Email do advogado: ",textfield('email'),br,
> submit,
> end_form,
> hr,
> my $process =param(process);
> my $lawyer =param(name);
> my $email =param(email);
> my $type =param(type);
>
>   my $mysql = Net::MySQL->new(
>   database => 'tj',
>   user => 'user',
>   password => 'pass'
>   );
>
>$mysql->query(q{
>INSERT INTO processo (process, name, email, type) VALUES ($process,
> $lawyer, $email, $type)
>});

I think you have to quote the param:

my $process =param('process');
my $lawyer =param('name');
my $email =param('email');
my $type =param('type');

HTH
Ron



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




Variable Value into MySQL DB

2004-12-27 Thread diogo . senai
Hi guys,

I´m having kind´a problem... Here´s the deal... I´m using CGI so that the
user can, by a browser, type the data that must be recorded into the
database.
I use CGI library to do that... the user type what he wants in the fields,
and these values are sent to some variables... Then, I´d like to record
these variables values in the db... But I just can´t get it done!
I´m using Net::MySQL to do so... when I test the script by writing fixed
values in it, it works fine... but when i try to record variables values
it doesn´t work... could you help me? Here´s my code:
#!/usr/bin/perl
use strict;
use CGI qw/:standard/;
 use Net::MySQL;
print header,
start_html('Cadastro de Processos'),
h1('Cadastramento Processos'),
start_form,
"Numero do Processo: ",textfield('process'),br,
"Tipo do Processo: [1-2]",textfield('type'),br,
"Nome do advogado: ",textfield('name'),br,
"Email do advogado: ",textfield('email'),br,
submit,
end_form,
hr,
my $process =param(process);
my $lawyer =param(name);
my $email =param(email);
my $type =param(type);

  my $mysql = Net::MySQL->new(
  database => 'tj',
  user => 'user',
  password => 'pass'
  );

   $mysql->query(q{
   INSERT INTO processo (process, name, email, type) VALUES ($process,
$lawyer, $email, $type)
   });



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




Examples about Net::Nessus::Client

2004-12-27 Thread Goran Bogdanovic
Hi, 

Does someone have some scripts examples of how to use Net::Nessus::Client ? 

I would like to create a web interface with CGI and this nessus client ...

Thanks,

GB
-- 
__
Check out the latest SMS services @ http://www.linuxmail.org 
This allows you to send and receive SMS through your mailbox.


Powered by Outblaze

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




Re: different type of getting an array reference

2004-12-27 Thread John W. Krahn
Octavian Rasnita wrote:
Hi all,
Hello,
Can you please tell me what's the difference between these two types of
getting the reference to @a array?
my $ref = [ @a ];
This copies the array to an anonymous array and returns a reference to that 
anonymous array.  It is equivalent to:

my $ref = do { my @temp = @a; [EMAIL PROTECTED] };

and
my $ref = [EMAIL PROTECTED];
This returns a reference to the array.

If I do:
use Data::Dumper;
print Dumper $ref;
Both ways of accesing the @a array with a reference seems to be the same,
because Data::Dumper prints the same thing for $ref.
I need to access an array reference in a module, like...
my $self = [ @a ];
or...
my $self = [EMAIL PROTECTED];
and I don't know if there will be any differences...
It depends on the scope of @a.
John
--
use Perl;
program
fulfillment
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]