RE: Problems getting a simple form to work.

2003-04-04 Thread Mike Butler
Hi Li, Rob and Mark.

Thanks for your help. My site is being hosted by Hypermart, so I don't have
access to /var/log/httpd. My new simpleform.cgi now looks like this:

#!/usr/local/bin/perl -wT
use CGI;
use strict;

$username = param('username');

print Content-type: text/plain\n\n;
print You entered: $username\n;

The permissions look like this:

Permissions for cgi-bin: rwxr-xr-x
Permissions for simpleform.cgi rwxr-xr-x
Permissions for simpleform.htm: rwxr-xr-x

I have changed form method=post action=../cgi-bin/simpleform.pl to
form method=post action=http://www.mikyo.com/cgi-bin/simpleform.cgi;.

I am still getting the 500 error.

Thanks,

  - Mike

-Original Message-
From: Li Ngok Lam [mailto:[EMAIL PROTECTED]
Sent: Friday, April 04, 2003 1:16 PM
To: Mike Butler; [EMAIL PROTECTED]
Subject: Re: Problems getting a simple form to work.


[..]

 Can anyone tell me what I'm doing wrong? Also, is there a way to turn on
 error.log?

Actually, error.log is always turned on... If you are not running the server
on
yours own, ask the server admin where is the error.log located.

[..]

 Permissions for cgi-bin: rwxr-xr-x
 Permissions for simpleform.htm: rwxr-xr-x

What about your script ?  simpleform.pl

[..]

 #!/usr/local/bin/perl

use CGI; # You missed this

 $username = param('username');

You can't ask a value from param without use CGI in this case.


 print Content-type: text/plain\n\n;
 print You entered: $username\n;


One more point, when you are going to write a script for real running,
always use strict You will know how pain it is to remember all the
var names that you've declared along the whole script. And most likely
have to rewrite the whole thing again when touching to maintenence or
debugging...


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



Re: Problems getting a simple form to work.

2003-04-04 Thread javamaster
Mike Butler wrote:

Hi Li, Rob and Mark.

Thanks for your help. My site is being hosted by Hypermart, so I don't have
access to /var/log/httpd. My new simpleform.cgi now looks like this:
#!/usr/local/bin/perl -wT
use CGI;
use strict;
$username = param('username');

should be

my $username = param('username');

When you are using strict all variables must be declared with the my.

print Content-type: text/plain\n\n;
print You entered: $username\n;
The permissions look like this:

Permissions for cgi-bin: rwxr-xr-x
Permissions for simpleform.cgi rwxr-xr-x
Permissions for simpleform.htm: rwxr-xr-x
Out of curiosity why is the simpleform.htm chmod 755 instead of 644?

I have changed form method=post action=../cgi-bin/simpleform.pl to
form method=post action=http://www.mikyo.com/cgi-bin/simpleform.cgi;.
I am still getting the 500 error.

Thanks,

 - Mike
 



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


RE: Problems getting a simple form to work.

2003-04-04 Thread Etienne Rivard
Hi,

 You have access to your error log in Hypermart through the site tools.  Simply click 
on Site Statistics then on CGI Error Log and you'll find the most recent errors.

Etienne Rivard


 Mike Butler[EMAIL PROTECTED] 04/04/03 01:57pm 
Hi Li, Rob and Mark.

Thanks for your help. My site is being hosted by Hypermart, so I don't have
access to /var/log/httpd. My new simpleform.cgi now looks like this:

#!/usr/local/bin/perl -wT
use CGI;
use strict;

$username = param('username');

print Content-type: text/plain\n\n;
print You entered: $username\n;

The permissions look like this:

Permissions for cgi-bin: rwxr-xr-x
Permissions for simpleform.cgi rwxr-xr-x
Permissions for simpleform.htm: rwxr-xr-x

I have changed form method=post action=../cgi-bin/simpleform.pl to
form method=post action=http://www.mikyo.com/cgi-bin/simpleform.cgi;.

I am still getting the 500 error.

Thanks,

  - Mike

-Original Message-
From: Li Ngok Lam [mailto:[EMAIL PROTECTED] 
Sent: Friday, April 04, 2003 1:16 PM
To: Mike Butler; [EMAIL PROTECTED] 
Subject: Re: Problems getting a simple form to work.


[..]

 Can anyone tell me what I'm doing wrong? Also, is there a way to turn on
 error.log?

Actually, error.log is always turned on... If you are not running the server
on
yours own, ask the server admin where is the error.log located.

[..]

 Permissions for cgi-bin: rwxr-xr-x
 Permissions for simpleform.htm: rwxr-xr-x

What about your script ?  simpleform.pl

[..]

 #!/usr/local/bin/perl

use CGI; # You missed this

 $username = param('username');

You can't ask a value from param without use CGI in this case.


 print Content-type: text/plain\n\n;
 print You entered: $username\n;


One more point, when you are going to write a script for real running,
always use strict You will know how pain it is to remember all the
var names that you've declared along the whole script. And most likely
have to rewrite the whole thing again when touching to maintenence or
debugging...


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



Any one who knows Formmail by Matts Scripts

2003-04-04 Thread Luinrandir Hernsen
Hallo
I need to have my form mail to 2 or 3 addresses.
Anyone familiar enough with this popular program to advise???
Thanks
Lou

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



RE: Problems getting a simple form to work.

2003-04-04 Thread Mike Butler
Thanks, Andrew. I added CGI::Carp qw(fatalsToBrowser); to the script. That's
a big help. The error message that I get now is:
Software error:
Undefined subroutine main::param called at simpleform.cgi line 6.

Line 6 is my $username = param('username');

Any idea why param is undefined?

Thanks,

  - Mike


-Original Message-
From: Hughes, Andrew [mailto:[EMAIL PROTECTED]
Sent: Friday, April 04, 2003 3:09 PM
To: [EMAIL PROTECTED]
Subject: RE: Problems getting a simple form to work.


I would also add

use CGI::Carp qw(fatalsToBrowser);

along with

use CGI;
use strict;

This way your errors will get displayed in your browser.

Also, check with your hosting company to make sure that your path to perl is
correct (ex. is it #!/usr/local/bin/perl -wT vs. #!/usr/bin/perl -wT)

Andrew

-Original Message-
From: Li Ngok Lam [mailto:[EMAIL PROTECTED]
Sent: Friday, April 04, 2003 2:37 PM
To: Mike Butler; [EMAIL PROTECTED]
Subject: Re: Problems getting a simple form to work.


[..]
 #!/usr/local/bin/perl -wT
 use CGI;
 use strict;

 $username = param('username');

should be :
my $username = param('username');

because you've using strict;


 print Content-type: text/plain\n\n;
For what I know, I would write as Content-type: text/html\n\n;

 print You entered: $username\n;

 The permissions look like this:

 Permissions for cgi-bin: rwxr-xr-x
 Permissions for simpleform.cgi rwxr-xr-x
 Permissions for simpleform.htm: rwxr-xr-x

 I have changed form method=post action=../cgi-bin/simpleform.pl to
 form method=post action=http://www.mikyo.com/cgi-bin/simpleform.cgi;.


2 suggestion here :

1. use CGI::Carp 'fatalsToBrowser'; # the die message will goto your
browser.
2. Try simpler script, so you will know if your form is going to a right
place :

#!/usr/bin/perl
print Content-type: text/html\n\n;
print Hello world;





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

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


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



RE: Problems getting a simple form to work.

2003-04-04 Thread Mark Young


Undefined subroutine main::param called at simpleform.cgi line 6.


Is the error I get for your script when I execute it from
http://www.mikyo.com/cgi-bin/simpleform.cgi

If you want to try what I did, do the following:
1. type in http://www.mikyo.com/cgi-bin/simpleform.cgi to your web
browser
2. You will get the error above.

Are you sure the CGI module is installed on Hypermart's servers?

You can send them an email to see.

CGI module is not a standard part of my web hoster either, so you might
want to find a hosting site that will install it for you.  There are
ways you can install CPAN modules yourself on the Hypermart server, but
I think you need to rebuild the module with some details about where
you'll be installing it.  This is covered in 12.7 and 12.17 in Perl
Cookbook.

Mark




I tried to go to Hypermart to look at their CGI implementation, that is,
where they say to get access to your CGI programs, but I couldn't until
I signed up.  They have a free option, but oddly they require a credit
card even for the zero-dollar option.

So, I would look at their CGI FAQ (

 -Original Message-
 From: Mike Butler [mailto:[EMAIL PROTECTED]
 Sent: Friday, April 04, 2003 12:58 PM
 To: Li Ngok Lam; [EMAIL PROTECTED]
 Subject: RE: Problems getting a simple form to work.
 
 Hi Li, Rob and Mark.
 
 Thanks for your help. My site is being hosted by Hypermart, so I
don't
 have
 access to /var/log/httpd. My new simpleform.cgi now looks like this:
 
 #!/usr/local/bin/perl -wT
 use CGI;
 use strict;
 
 $username = param('username');
 
 print Content-type: text/plain\n\n;
 print You entered: $username\n;
 
 The permissions look like this:
 
 Permissions for cgi-bin: rwxr-xr-x
 Permissions for simpleform.cgi rwxr-xr-x
 Permissions for simpleform.htm: rwxr-xr-x
 
 I have changed form method=post action=../cgi-bin/simpleform.pl
to
 form method=post action=http://www.mikyo.com/cgi-
 bin/simpleform.cgi.
 
 I am still getting the 500 error.
 
 Thanks,
 
   - Mike
 
 -Original Message-
 From: Li Ngok Lam [mailto:[EMAIL PROTECTED]
 Sent: Friday, April 04, 2003 1:16 PM
 To: Mike Butler; [EMAIL PROTECTED]
 Subject: Re: Problems getting a simple form to work.
 
 
 [..]
 
  Can anyone tell me what I'm doing wrong? Also, is there a way to
turn
 on
  error.log?
 
 Actually, error.log is always turned on... If you are not running the
 server
 on
 yours own, ask the server admin where is the error.log located.
 
 [..]
 
  Permissions for cgi-bin: rwxr-xr-x
  Permissions for simpleform.htm: rwxr-xr-x
 
 What about your script ?  simpleform.pl
 
 [..]
 
  #!/usr/local/bin/perl
 
 use CGI; # You missed this
 
  $username = param('username');
 
 You can't ask a value from param without use CGI in this case.
 
 
  print Content-type: text/plain\n\n;
  print You entered: $username\n;
 
 
 One more point, when you are going to write a script for real
running,
 always use strict You will know how pain it is to remember all
the
 var names that you've declared along the whole script. And most
likely
 have to rewrite the whole thing again when touching to maintenence or
 debugging...
 
 
 --
 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: Problems getting a simple form to work.

2003-04-04 Thread Rob Benton
Give this a shot and see if it errors:

use CGI;
my $query = new CGI;
my %params = $query-Vars;

my $username = $params{'username'};



On Fri, 2003-04-04 at 15:29, Mike Butler wrote:
 Thanks, Andrew. I added CGI::Carp qw(fatalsToBrowser); to the script. That's
 a big help. The error message that I get now is:
 Software error:
 Undefined subroutine main::param called at simpleform.cgi line 6.
 
 Line 6 is my $username = param('username');
 
 Any idea why param is undefined?
 
 Thanks,
 
   - Mike
 
 
 -Original Message-
 From: Hughes, Andrew [mailto:[EMAIL PROTECTED]
 Sent: Friday, April 04, 2003 3:09 PM
 To: [EMAIL PROTECTED]
 Subject: RE: Problems getting a simple form to work.
 
 
 I would also add
 
 use CGI::Carp qw(fatalsToBrowser);
 
 along with
 
 use CGI;
 use strict;
 
 This way your errors will get displayed in your browser.
 
 Also, check with your hosting company to make sure that your path to perl is
 correct (ex. is it #!/usr/local/bin/perl -wT vs. #!/usr/bin/perl -wT)
 
 Andrew
 
 -Original Message-
 From: Li Ngok Lam [mailto:[EMAIL PROTECTED]
 Sent: Friday, April 04, 2003 2:37 PM
 To: Mike Butler; [EMAIL PROTECTED]
 Subject: Re: Problems getting a simple form to work.
 
 
 [..]
  #!/usr/local/bin/perl -wT
  use CGI;
  use strict;
 
  $username = param('username');
 
 should be :
 my $username = param('username');
 
 because you've using strict;
 
 
  print Content-type: text/plain\n\n;
 For what I know, I would write as Content-type: text/html\n\n;
 
  print You entered: $username\n;
 
  The permissions look like this:
 
  Permissions for cgi-bin: rwxr-xr-x
  Permissions for simpleform.cgi rwxr-xr-x
  Permissions for simpleform.htm: rwxr-xr-x
 
  I have changed form method=post action=../cgi-bin/simpleform.pl to
  form method=post action=http://www.mikyo.com/cgi-bin/simpleform.cgi;.
 
 
 2 suggestion here :
 
 1. use CGI::Carp 'fatalsToBrowser'; # the die message will goto your
 browser.
 2. Try simpler script, so you will know if your form is going to a right
 place :
 
 #!/usr/bin/perl
 print Content-type: text/html\n\n;
 print Hello world;
 
 
 
 
 
 --
 To unsubscribe, e-mail: [EMAIL PROTECTED]
 For additional commands, e-mail: [EMAIL PROTECTED]
 
 --
 To unsubscribe, e-mail: [EMAIL PROTECTED]
 For additional commands, e-mail: [EMAIL PROTECTED]
 
 
 -- 
 To unsubscribe, e-mail: [EMAIL PROTECTED]
 For additional commands, e-mail: [EMAIL PROTECTED]
 
 


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



Re: Any one who knows Formmail by Matts Scripts

2003-04-04 Thread Abel Lucano
On Fri, 4 Apr 2003, Luinrandir Hernsen wrote:

 Hallo
 I need to have my form mail to 2 or 3 addresses.
 Anyone familiar enough with this popular program to advise???
 Thanks
 Lou


Lou, forget it; matt's formmail script has a lot of security flaws
discussed in this list and others.

Try  http://nms-cgi.sourceforge.net/   as an alternative good choice

regards,


Abel Lucano
DECODE SA
[EMAIL PROTECTED]






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



RE: Problems getting a simple form to work.

2003-04-04 Thread Mike Butler
Thanks, Andrew. That did it. It's working now. :) :) :)

Thanks everyone for all your help.

  - Mike

-Original Message-
From: Rob Benton [mailto:[EMAIL PROTECTED]
Sent: Friday, April 04, 2003 4:38 PM
To: Mike Butler
Cc: Hughes, Andrew; [EMAIL PROTECTED]
Subject: RE: Problems getting a simple form to work.


Give this a shot and see if it errors:

use CGI;
my $query = new CGI;
my %params = $query-Vars;

my $username = $params{'username'};



On Fri, 2003-04-04 at 15:29, Mike Butler wrote:
 Thanks, Andrew. I added CGI::Carp qw(fatalsToBrowser); to the script.
That's
 a big help. The error message that I get now is:
 Software error:
 Undefined subroutine main::param called at simpleform.cgi line 6.

 Line 6 is my $username = param('username');

 Any idea why param is undefined?

 Thanks,

   - Mike


 -Original Message-
 From: Hughes, Andrew [mailto:[EMAIL PROTECTED]
 Sent: Friday, April 04, 2003 3:09 PM
 To: [EMAIL PROTECTED]
 Subject: RE: Problems getting a simple form to work.


 I would also add

 use CGI::Carp qw(fatalsToBrowser);

 along with

 use CGI;
 use strict;

 This way your errors will get displayed in your browser.

 Also, check with your hosting company to make sure that your path to perl
is
 correct (ex. is it #!/usr/local/bin/perl -wT vs. #!/usr/bin/perl -wT)

 Andrew

 -Original Message-
 From: Li Ngok Lam [mailto:[EMAIL PROTECTED]
 Sent: Friday, April 04, 2003 2:37 PM
 To: Mike Butler; [EMAIL PROTECTED]
 Subject: Re: Problems getting a simple form to work.


 [..]
  #!/usr/local/bin/perl -wT
  use CGI;
  use strict;
 
  $username = param('username');

 should be :
 my $username = param('username');

 because you've using strict;

 
  print Content-type: text/plain\n\n;
 For what I know, I would write as Content-type: text/html\n\n;

  print You entered: $username\n;
 
  The permissions look like this:
 
  Permissions for cgi-bin: rwxr-xr-x
  Permissions for simpleform.cgi rwxr-xr-x
  Permissions for simpleform.htm: rwxr-xr-x
 
  I have changed form method=post action=../cgi-bin/simpleform.pl to
  form method=post
action=http://www.mikyo.com/cgi-bin/simpleform.cgi;.
 

 2 suggestion here :

 1. use CGI::Carp 'fatalsToBrowser'; # the die message will goto your
 browser.
 2. Try simpler script, so you will know if your form is going to a right
 place :

 #!/usr/bin/perl
 print Content-type: text/html\n\n;
 print Hello world;





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

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


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




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



RE: Problems getting a simple form to work.

2003-04-04 Thread Hughes, Andrew
I think you meant, Thanks, Rob.

Andrew

-Original Message-
From: Mike Butler [mailto:[EMAIL PROTECTED]
Sent: Friday, April 04, 2003 4:45 PM
To: Rob Benton
Cc: Hughes, Andrew; [EMAIL PROTECTED]
Subject: RE: Problems getting a simple form to work.


Thanks, Andrew. That did it. It's working now. :) :) :)

Thanks everyone for all your help.

  - Mike

-Original Message-
From: Rob Benton [mailto:[EMAIL PROTECTED]
Sent: Friday, April 04, 2003 4:38 PM
To: Mike Butler
Cc: Hughes, Andrew; [EMAIL PROTECTED]
Subject: RE: Problems getting a simple form to work.


Give this a shot and see if it errors:

use CGI;
my $query = new CGI;
my %params = $query-Vars;

my $username = $params{'username'};



On Fri, 2003-04-04 at 15:29, Mike Butler wrote:
 Thanks, Andrew. I added CGI::Carp qw(fatalsToBrowser); to the script.
That's
 a big help. The error message that I get now is:
 Software error:
 Undefined subroutine main::param called at simpleform.cgi line 6.

 Line 6 is my $username = param('username');

 Any idea why param is undefined?

 Thanks,

   - Mike


 -Original Message-
 From: Hughes, Andrew [mailto:[EMAIL PROTECTED]
 Sent: Friday, April 04, 2003 3:09 PM
 To: [EMAIL PROTECTED]
 Subject: RE: Problems getting a simple form to work.


 I would also add

 use CGI::Carp qw(fatalsToBrowser);

 along with

 use CGI;
 use strict;

 This way your errors will get displayed in your browser.

 Also, check with your hosting company to make sure that your path to perl
is
 correct (ex. is it #!/usr/local/bin/perl -wT vs. #!/usr/bin/perl -wT)

 Andrew

 -Original Message-
 From: Li Ngok Lam [mailto:[EMAIL PROTECTED]
 Sent: Friday, April 04, 2003 2:37 PM
 To: Mike Butler; [EMAIL PROTECTED]
 Subject: Re: Problems getting a simple form to work.


 [..]
  #!/usr/local/bin/perl -wT
  use CGI;
  use strict;
 
  $username = param('username');

 should be :
 my $username = param('username');

 because you've using strict;

 
  print Content-type: text/plain\n\n;
 For what I know, I would write as Content-type: text/html\n\n;

  print You entered: $username\n;
 
  The permissions look like this:
 
  Permissions for cgi-bin: rwxr-xr-x
  Permissions for simpleform.cgi rwxr-xr-x
  Permissions for simpleform.htm: rwxr-xr-x
 
  I have changed form method=post action=../cgi-bin/simpleform.pl to
  form method=post
action=http://www.mikyo.com/cgi-bin/simpleform.cgi;.
 

 2 suggestion here :

 1. use CGI::Carp 'fatalsToBrowser'; # the die message will goto your
 browser.
 2. Try simpler script, so you will know if your form is going to a right
 place :

 #!/usr/bin/perl
 print Content-type: text/html\n\n;
 print Hello world;





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

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


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



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



RE: Problems getting a simple form to work.

2003-04-04 Thread fliptop
On Fri, 4 Apr 2003 at 16:29, Mike Butler opined:

MB:Thanks, Andrew. I added CGI::Carp qw(fatalsToBrowser); to the script. That's
MB:a big help. The error message that I get now is:
MB:Software error:
MB:Undefined subroutine main::param called at simpleform.cgi line 6.
MB:
MB:Line 6 is my $username = param('username');
MB:
MB:Any idea why param is undefined?

you should reread the docs for CGI:

 use CGI;
 $q = new CGI;
 print $q-header;
 print $q-param('username');

 etc.

OR

 use CGI qw/:standard/;
 print header;
 print param('username');

 etc.

when you import the standard functions into your namespace, you don't need 
to create the CGI object.  you *can't* do this:

 use CGI;
 print header;
 print param('username');

which i think is what you were originally trying to do.

perldoc CGI

or, if you don't have access to a shell try

http://search.cpan.org/author/LDS/CGI.pm-2.91/CGI.pm



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



Re: How conver decimal num. to bin. mum.

2003-04-04 Thread Steve Grazzini
Radovan Petrikí [EMAIL PROTECTED] wrote:
 
 how I conver decimal number to binary number in perl? 
 

You could use pack/unpack()

$ perl -le 'print unpack B*, pack n, 3'
0011

Or (s)printf 

$ perl -le 'printf %b\n, 3'
11

-- 
Steve

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



RE: How to measure Array or Hash's byte size ?

2003-04-04 Thread BUFFERNE,VINCENT (HP-France,ex1)
What's about:

my @foo = ( '1', '2' ,'3' );
my $size = $#foo + 1;
print table size $size\n;

Ouput:
table size 3

Vincent

-Original Message-
From: Li Ngok Lam [mailto:[EMAIL PROTECTED]
Sent: Thursday, April 03, 2003 5:14 PM
To: [EMAIL PROTECTED]
Subject: How to measure Array or Hash's byte size ?


My method  sounds stupid, but still works :

my @array = ('123', 'abc', 'def',  1..9);
my $len_of_array =  0 ;
foreach my $elem(@array)
{$len_of_array += length($elem) }
print $len_of_array ; # I got '18'

my %hash = (1=2, 2=3, 3=4);
foreach my $key(keys(%hash))
{$len_of_hash += length($key) + length($hash{$key}) }
print $len_of_hash ; # I got '6'

I suppose there should be another better and faster way to done this, 
any suggestion ?

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



Use strict (beginner question)

2003-04-04 Thread Steve . E . Pittman

All,

I added the use strict; statement to my script for the first time and
received the following compilation errors:
Global symbol $LoginName requires explicit package name at todaysFiles.pl
line 43.
Global symbol $TMPNow requires explicit package name at todaysFiles.pl
line 45.
Global symbol @filenames requires explicit package name at todaysFiles.pl
line 48.
Global symbol $filenames requires explicit package name at todaysFiles.pl
line 49.

This program works fine without the use strict statement?.please advise!!

Also, can someone offer an explanation of how = differs from = =??

Thanks In advance!


Steve Pittman
Medstar Health


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



Re: Use strict (beginner question)

2003-04-04 Thread Morten Liebach
On 2003-04-03 14:05:19 -0500, [EMAIL PROTECTED] wrote:
 
 All,
 
 I added the use strict; statement to my script for the first time and
 received the following compilation errors:
 Global symbol $LoginName requires explicit package name at todaysFiles.pl
 line 43.
 Global symbol $TMPNow requires explicit package name at todaysFiles.pl
 line 45.
 Global symbol @filenames requires explicit package name at todaysFiles.pl
 line 48.
 Global symbol $filenames requires explicit package name at todaysFiles.pl
 line 49.
 
 This program works fine without the use strict statement?.please advise!!
 
Use something like:

my $LoginName;
my $TMPNow;

Etc.

 Also, can someone offer an explanation of how = differs from = =??

I suppose you meant == instead of = =.

= is an assignment.  == is a comparison.
 
I can recommend Learning Perl or one of the other nice beginners books,
you wouldn't get into these things then.  And use strict and warnings
always, from the beginning of all new scripts, it helps a lot.

Have a nice day
 Morten

-- 
OpenPGP: 0xF1360CA9 - 8CF5 32EE A5EC 36B2 4E3F  ACDF 6D86 BEB3 F136 0CA9
 Morten Liebach [EMAIL PROTECTED] - http://m.mongers.org/

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



Problem with ^ oprator

2003-04-04 Thread Rado Petrik
Hi, 

I have two number 

$a=6;  #binary - 0110
$b=10; # 1010

I need work this operation  a OR b 
0110  - 6 
OR  1010  - 10
-
1110  - 14  this is true;

buy when I use this operator ^ in perl 

$a^$b  then output is 12

0110  - 6 
OR  1010  - 10
-
1100  - 12 false; 
 
Why ? How I make true output? 
Thanks. 
 
 







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



Re: Problem with ^ oprator

2003-04-04 Thread Jenda Krynicky
From: Rado Petrik [EMAIL PROTECTED]
 I have two number 
 
 $a=6;  #binary - 0110
 $b=10; # 1010
 
 I need work this operation  a OR b 
 0110  - 6 
 OR  1010  - 10
 -
 1110  - 14  this is true;
 
 buy when I use this operator ^ in perl 
 
 $a^$b  then output is 12
 
 0110  - 6 
 OR  1010  - 10
 -
 1100  - 12 false; 
 
 Why ?

^ is XOR. That is exclisive OR ... the resul with have 1 only on 
those places where either one or the other argument had 1, but not 
both.

0 XOR 0 = 0
0 XOR 1 = 1
1 XOR 0 = 1
1 XOR 1 = 0

What you want is

$a | $b

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


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



Re: HASH PRINTING

2003-04-04 Thread [EMAIL PROTECTED]
I started to write it but didn't reach to finish it.
Any way, the main idea is
unless (ref = scalar) {
  if (ref = hash) {
enter another layer
  }
  elsif (ref = array) {
print @Array
  }
}
print $HASH{$KEY}

HTH,
Yargo!


Original Message:
-
From: R. Joseph Newton [EMAIL PROTECTED]
Date: Thu, 03 Apr 2003 18:04:43 -0800
To: [EMAIL PROTECTED], [EMAIL PROTECTED]
Subject: Re: HASH PRINTING


Eric Walker wrote:

 I have a HASH with a mixture of single, double and triple layers.
 exampl hash of hash of array's etc
 I try to dump and see values of the entire db but I get pointers and
 memory addresses.  Below is my code  Please help.

 foreach my $item (keys %hData){
 print ($item: $hData{$item}\n);
 }

 Thanks
 Eric

Stay tuned on this list.  I am creating this some plumbing facilites for
such structures on another thread.

Joseph


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



mail2web - Check your email from the web at
http://mail2web.com/ .



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



Re: How to measure Array or Hash's byte size ?

2003-04-04 Thread Li Ngok Lam



 What's about:

 my @foo = ( '1', '2' ,'3' );
 my $size = $#foo + 1;

you can simplify this by : $size = scalar @foo;

 print table size $size\n;

 Ouput:
 table size 3

TIA, but this is not what I want... because each element is assumpted not in
same length... ie.. I am not going to get the table size...


 Vincent

 -Original Message-
 From: Li Ngok Lam [mailto:[EMAIL PROTECTED]
 Sent: Thursday, April 03, 2003 5:14 PM
 To: [EMAIL PROTECTED]
 Subject: How to measure Array or Hash's byte size ?


 My method  sounds stupid, but still works :

 my @array = ('123', 'abc', 'def',  1..9);
 my $len_of_array =  0 ;
 foreach my $elem(@array)
 {$len_of_array += length($elem) }
 print $len_of_array ; # I got '18'

 my %hash = (1=2, 2=3, 3=4);
 foreach my $key(keys(%hash))
 {$len_of_hash += length($key) + length($hash{$key}) }
 print $len_of_hash ; # I got '6'

 I suppose there should be another better and faster way to done this,
 any suggestion ?

 --
 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 strict (beginner question)

2003-04-04 Thread wiggins


On Thu, 3 Apr 2003 14:05:19 -0500, [EMAIL PROTECTED] wrote:

 
 All,
 
 I added the use strict; statement to my script for the first time and
 received the following compilation errors:
 Global symbol $LoginName requires explicit package name at todaysFiles.pl
 line 43.
 Global symbol $TMPNow requires explicit package name at todaysFiles.pl
 line 45.
 Global symbol @filenames requires explicit package name at todaysFiles.pl
 line 48.
 Global symbol $filenames requires explicit package name at todaysFiles.pl
 line 49.
 
 This program works fine without the use strict statement?.please advise!!
 

You have some obligatory reading to do :-)... You should read:

http://perl.plover.com/FAQs/Namespaces.html
perldoc strict
perldoc -f my
perldoc -f our

Essentially you need to declare the namespace/scope of the variables you are using. 
Before they were automagically placed in the 'main::' namespace.  This seems overly 
tedious at first, once you learn the practice you will forever appreciate it.

 Also, can someone offer an explanation of how = differs from = =??
 

'=' is for assignment, '==' is for comparison...

so you 'assign' a variable with the first:

my $variable = 'value';

you compare number values with the second:

if ($variable == 4) {
}

http://danconia.org


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



Re: Problem with ^ oprator

2003-04-04 Thread Brett W. McCoy
On 4 Apr 2003, Rado Petrik wrote:

 I have two number

 $a=6;  #binary - 0110
 $b=10; # 1010

 I need work this operation  a OR b
 0110  - 6
 OR  1010  - 10
 -
 1110  - 14  this is true;

 buy when I use this operator ^ in perl

 $a^$b  then output is 12

 0110  - 6
 OR  1010  - 10
 -
 1100  - 12 false;

^ is XOR, not OR.  You want to use | for bitwise OR.

$ perl -e 'print 6 | 10'
14

-- Brett


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



RE: php mySQL question

2003-04-04 Thread Dan Muey
 Hi,

Howdy

 
 I have a php form that takes in data for a mysql query.  The 
 script that 
 processes the form takes the variables from the form and 
 submits them to 
 the db.
 
 What if the field after LIKE needs to be imprecise?  The variable 
 somehow needs to be converted to a regular expression like /'%expr%'/ 
  so the query will match the expression anywhere in the line. 
  I can't 
 put $var inside the regex delimiters, so not sure what else to try.

Hmm two things you could try ::

1) delete the php and write it inperl so his list can help
2) ask your question to a php list

:)

 
 Any ideas?
 Thanks,
 Robbie

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



RE: Php perl?

2003-04-04 Thread Dan Muey

 Dan Muey [EMAIL PROTECTED] wrote:
  
  If you want it to run like mod_php use mod_perl. Someone said that
  not using mod_perl increases dramatically the startup. 
 Yeah by like 
  zillionth of a second.
 
 Hi Dan,
 
 And remember that the startup can also include loading modules, connecting to an 
 RDMS, parsing XSL stylesheets, etc...

Right but what I meant was all things else being the same .
IE a perl script that connects to a database and adds 100,000 records 
will be slower than php script that print Hello, World and vice versa.

So what I meant was take a script of each that does the exact same thing.
The non mod_perl perl script will not have dramatically increased startup.
It may have, I believe I said, a zillionth of a second difference. 

The point was that mod_php isn't a zillion times faster than a non mod_perl script.

That's what bugs the crap out of me about PHP people. They're so dramatic about how 
wonderful PHP is when it does the same stuff, and usually less, than lots of other
scripting languages, not just perl.


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



Re: Use strict (beginner question)

2003-04-04 Thread R. Joseph Newton
[EMAIL PROTECTED] wrote:

 All,

 I added the use strict; statement to my script for the first time and
 received the following compilation errors:
 Global symbol $LoginName requires explicit package name at todaysFiles.pl
 line 43.

This error means that $LoginName was declared without a statement indicating what 
package it is meant to be part of.  It is not a hard question to answer.  Simply make 
sure that before you use a variable in your code, you tell the interpreter that it is 
being introduced:
my $login_name;
or
my $login_name = pittmans;

It can get a little more complicated.  If you care about your data, you will probably 
want to declare your variables only within subs or other blocks, so that it is more 
difficult to accidentally corrupt their values.

 This program works fine without the use strict statement?.please advise!!

use strict;
and deal with the errors the interpreter issues.  If it gives you an error message, 
that is because you are doing something that will make errors more likely.  Choosing 
not to use strict is a directive to the compiler give me enough rope to ang myself  
The compiler will respect that directive.

 Also, can someone offer an explanation of how = differs from = =??

= assignment
== numeric comparison

If you use the assignment operator in a context calling for numeric comparision, the 
operation will return true unless you are assigning 0, the empty string '', or undef 
to the variable.  If you have warnings enabled, the interpreter will catch most such 
cases and warn you about them.

Joseph


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



Re: Php perl?

2003-04-04 Thread Gary Stainburn
On Friday 04 Apr 2003 3:59 pm, Dan Muey wrote:
  Dan Muey [EMAIL PROTECTED] wrote:
   If you want it to run like mod_php use mod_perl. Someone said that
   not using mod_perl increases dramatically the startup.
 
  Yeah by like
 
   zillionth of a second.
 
  Hi Dan,
 
  And remember that the startup can also include loading modules,
  connecting to an RDMS, parsing XSL stylesheets, etc...

 Right but what I meant was all things else being the same .
 IE a perl script that connects to a database and adds 100,000 records
 will be slower than php script that print Hello, World and vice versa.

 So what I meant was take a script of each that does the exact same thing.
 The non mod_perl perl script will not have dramatically increased
 startup. It may have, I believe I said, a zillionth of a second
 difference.

 The point was that mod_php isn't a zillion times faster than a non mod_perl
 script.

 That's what bugs the crap out of me about PHP people. They're so dramatic
 about how wonderful PHP is when it does the same stuff, and usually less,
 than lots of other scripting languages, not just perl.

Just to put things into perspective here

1) I made the comment about the start-up speed.
2) Although I use PHP frequently my feet are FIRMLY in the Perl camp
3) Unix Fork/Load/Exec cycle *IS* slow because of the amount of work involved. 
The MS equiv will be just as slow
4) The F/L/E cycle has to be done *every* time the CGI is requested.

The PHP interpreter is already loaded and therefore *WILL* have a quicker 
startup. I don't have figures to back it up, but I would imagine Perl scripts 
exec much quicker that PHP asuming both scripts perform the same function.

(From memory) Using mod_perl will only require scripts to be loaded and 
compiled once per lifetime of the apache daemon so will be much quicker 
overall and provide less load on the server than either traditional CGI's.

-- 
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: SIGINT and SIGQUIT with system()

2003-04-04 Thread Bob Showalter
R. Joseph Newton wrote:
 [EMAIL PROTECTED] wrote:
 
  if (!$pid) { player(); }
  while (!-e stop) { sleep(10); }
  kill('QUIT', $pid);
 
 ...
 
  Am I missing something here? Any idea how I could do this
  differently? 
  
 
 Yes.  Braces.  They may not be required here--are you using
 strict?--but they would certainly make more clear to any
 human reading this code what your intent is.  A control
 statement is meant to control a block of code.  The block
 could be empty, have an empty statement, have a single line,
 or have a series of stements affecting the flow of tens of
 thousnads of lines of code.  No matter how obvious it seems,
 marking your execution blocks is worth the effort.

What braces are missing?

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



Re: How to measure Array or Hash's byte size ?

2003-04-04 Thread Rob Dixon
Li Ngok Lam wrote:
  What's about:
 
  my @foo = ( '1', '2' ,'3' );
  my $size = $#foo + 1;

 you can simplify this by : $size = scalar @foo;

You can simplify even this by : $size = @foo

:)

Rob




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



Re: SIGINT and SIGQUIT with system()

2003-04-04 Thread Rob Dixon
[EMAIL PROTECTED] wrote:
 Hi there

 I'm stuck with system(). According to some posts, system() is passing SIGINT
 and SIGQUIT to it's child, yet this doesn't seem to work. I've boiled the
 code down to the following lines. (Please note that 'alsaplayer' is a console
 soundfile player that honors SIGINT and SIGQUIT by immediately quitting.)

 sub controler
 {
 my $pid = fork;
 if (!$pid) { player(); }
 while (!-e stop) { sleep(10); }
 kill('QUIT', $pid);
 }

Both your parent and child processes are executing the 'while'
and 'kill' statements.

 sub player
 {
 system(alsaplayer -q song.mp3);
 sleep;
 }

 The controler forks off the player child which system()-implicitly forks
 again and runs alsaplayer in the child. So the sound's playing. I 'touch
 stop' and the controler signals SIGQUIT to the player child. This works as
 I can see when I catch SIGQUIT there. Still, the SIGQUIT is not forwarded
 to the child running alsaplayer the way it is supposed to do - at least according
 to my literature.

 Am I missing something here? Any idea how I could do this differently?

Here's a rewrite of what you had:

sub controller
{
my $pid = fork;
player() unless $pid;
sleep(10) UNTIL -e stop;
kill 'QUIT', $pid;
}

sub player
{
system(alsaplayer -q song.mp3);
sleep;
}

The subroutine 'player' looks OK, but how about this for 'controller'

sub controller
{
my $pid = fork;
die Unable to fork unless defined $pid;

if ( $pid == 0 ) {
player();
} else {
sleep(10) until -e stop;
kill 'QUIT', $pid;
}
}

HTH,

Rob




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



Re: HASH PRINTING

2003-04-04 Thread Eric Walker
[EMAIL PROTECTED] wrote:

 I started to write it but didn't reach to finish it.
 Any way, the main idea is
 unless (ref = scalar) {
   if (ref = hash) {
 enter another layer
   }
   elsif (ref = array) {
 print @Array
   }
 }
 print $HASH{$KEY}

 HTH,
 Yargo!

 Original Message:
 -
 From: R. Joseph Newton [EMAIL PROTECTED]
 Date: Thu, 03 Apr 2003 18:04:43 -0800
 To: [EMAIL PROTECTED], [EMAIL PROTECTED]
 Subject: Re: HASH PRINTING

 Eric Walker wrote:

  I have a HASH with a mixture of single, double and triple layers.
  exampl hash of hash of array's etc
  I try to dump and see values of the entire db but I get pointers and
  memory addresses.  Below is my code  Please help.
 
  foreach my $item (keys %hData){
  print ($item: $hData{$item}\n);
  }
 
  Thanks
  Eric

 Stay tuned on this list.  I am creating this some plumbing facilites for
 such structures on another thread.

 Joseph

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

 
 mail2web - Check your email from the web at
 http://mail2web.com/ .

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

Sorry for the ignorance but I think I am able to pull the first layer of
the hash but the values that are also hashes or arrays I get memory
pointers out .

For example:

TEMP: 2.0
TEMP5: ARRAY(0xdb660)
TEMP6: HASH(0xa2058)

Any suggestions on how to access the array and or hash at that point?

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

Is there any Polling mechanism in perl ?

2003-04-04 Thread Madhu Reddy
Hi,
  Is there any polling mechanism in perl ?
Following is my problem..
my program has to wait (poll) on particular
folder...
If any file arrived on that folder, my main program
has to invoke another program...

In Unix, we have poll() system call for waiting on 
particular event ?

is there any similar thing in perl to wait on
particular event ?
if event occurs trigger some job..

following is my algorithm...
i want to implement in better way...

here file arrived means, completely transfered...
Files will be FTPed to C:\temp on my local system...
once that FTP is completed, i want to know...
But i don't want to know in the middle of FTP.
I want to know after FTP done...
I think here we need unix lsof command?
Does anybody have any idea ? about that?


while(1) {
 if (file arrived on C:\temp\) {
 mail me the file name. 
  }

}




__
Do you Yahoo!?
Yahoo! Tax Center - File online, calculators, forms, and more
http://tax.yahoo.com

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



Re: Installing Curses.pm on Red Hat 8.0

2003-04-04 Thread Bruno Negrao
Hi everybody, I found myself the solution. To install Curses 1.06 with my
perl-5.8.0-55, i need a patch for the Curses package.
First, I  made a search on www.rmpfind.net  for the string 'perl-Curses' and
I found various rpm and src.rpm packages of it, mostly for mandrake. So, I
downloaded the perl-Curses-1.06-5mdk.src.rpm package, and installed it.
I tried the 'rpmbuild -ba perl-Curses-specfile' but it didn't work, so, I
went to the /usr/src/redhat/SOURCES where I found the patch:
Curses-1.06-fix-Perl_sv_isa.patch.bz2. I uncompressed it with bunzip2 and
applied it against my own
Curses-1.06.tar.gz package that I downloaded from CPAN.
Curses compiled and installed fine.

Bruno Negrao

- Original Message -
From: Bruno Negrao
To: [EMAIL PROTECTED]
Sent: Thursday, April 03, 2003 6:40 PM
Subject: Installing Curses.pm on Red Hat 8.0


Hi,
I tried to install the Curses.pm module (from CPAN) on my redhat linux 8.0
but I didn't
compile.
Does someone did it successfully? Any trick?

Thank you,
-
 -- Bruno Negrão -- Suporte
 -- Plugway Acesso Internet Ltda.
 -- (31)34812311
 -- bnegrao at plugway dot com dot br



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



RE: How to measure Array or Hash's byte size ?

2003-04-04 Thread Shawn
That's not what he was asking.

On Thu, 2003-04-03 at 10:07, BUFFERNE,VINCENT (HP-France,ex1) wrote:
 What's about:
 
 my @foo = ( '1', '2' ,'3' );
 my $size = $#foo + 1;
 print table size $size\n;
 
 Ouput:
 table size 3
 
 Vincent
 
 -Original Message-
 From: Li Ngok Lam [mailto:[EMAIL PROTECTED]
 Sent: Thursday, April 03, 2003 5:14 PM
 To: [EMAIL PROTECTED]
 Subject: How to measure Array or Hash's byte size ?
 
 
 My method  sounds stupid, but still works :
 
 my @array = ('123', 'abc', 'def',  1..9);
 my $len_of_array =  0 ;
 foreach my $elem(@array)
 {$len_of_array += length($elem) }
 print $len_of_array ; # I got '18'
 
 my %hash = (1=2, 2=3, 3=4);
 foreach my $key(keys(%hash))
 {$len_of_hash += length($key) + length($hash{$key}) }
 print $len_of_hash ; # I got '6'
 
 I suppose there should be another better and faster way to done this, 
 any suggestion ?

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



Re: looking for help with Net::IRC

2003-04-04 Thread Oliver Schaedlich
Hello Dan,

Thursday, April 3, 2003, 11:04:36 PM, you wrote:
 Net::IRC isn't the best way in the world of creating an IRC bot. I just use
 IO::Socket, and establish  maintain the connection to IRC myself within my
 own source. Personally that's the better option.

thanks for your advice. Since I didn't get one step ahead with
Net::IRC I switched to IO::Socket. Some simple routines already work
though I still do not know how to detect the modes of a channel or its
users. RFC 2810-2812 either do not provide such an option or I just
cannot find it. :)

Best regards,
oliver.



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



regex $1 not updating?

2003-04-04 Thread Jim
I've never encountered this before but I have to be doing something wrong.

snippet of code:

]$ perl -e '
 $var = Company Online (Company Systems) NETBLK-COM-5BLK 
(NET-24-256-0-0-1);
 $var =~ /.*? \(.*\) (.*?) \(.*?\)/;
 print $1,\n;
 
 $var = NetBlock: NETBLK-10H-6BLK;
 $var =~ /s\(.*?\) (.*?) \(.*?\)/;
 print $1,\n;
 '
NETBLK-COM-5BLK
NETBLK-COM-5BLK


Why isn't $1 getting updated with the next implicit match?  It should fail 
but its returning the first $1 match.  I can't unset $1 because it is a 
read-only variable.  This doesn't even work if I change the second $var to 
$var2 because of course $1 is the same the way through.

VERY frustrating.

-- 

- Jim

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



Re: regex $1 not updating?

2003-04-04 Thread John W. Krahn
Jim wrote:
 
 I've never encountered this before but I have to be doing something wrong.

Yes, you are.  This is the documented behaviour of the numeric variables
and is why we always tell beginners to use them only if the regular
expression matched.


 snippet of code:
 
 ]$ perl -e '
  $var = Company Online (Company Systems) NETBLK-COM-5BLK
 (NET-24-256-0-0-1);
  $var =~ /.*? \(.*\) (.*?) \(.*?\)/;
  print $1,\n;

print $1\n if $var =~ /.*? \(.*\) (.*?) \(.*?\)/;


  $var = NetBlock: NETBLK-10H-6BLK;
  $var =~ /s\(.*?\) (.*?) \(.*?\)/;
  print $1,\n;

print $1\n if $var =~ /s\(.*?\) (.*?) \(.*?\)/;


  '
 NETBLK-COM-5BLK
 NETBLK-COM-5BLK
 
 Why isn't $1 getting updated with the next implicit match?  It should fail
 but its returning the first $1 match.  I can't unset $1 because it is a
 read-only variable.  This doesn't even work if I change the second $var to
 $var2 because of course $1 is the same the way through.

$1, $2, $3, etc. are only set on a successful match otherwise they
retain the value from the previous successful match.


John
-- 
use Perl;
program
fulfillment

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



Re: [mail_lists] Re: looking for help with Net::IRC

2003-04-04 Thread Jim
On Friday 04 April 2003 11:59, you wrote:

Yes.  I agree.  IO::Socket is better.  Anyone tried the POE components?

   31 POE::Component::IRC  2.70   FIMM  
   32 POE::Component::IRC::Object  0.02   MSERGEANT 
   33 POE::Component::IRC::Onjoin  1.12   AFOXSON   
   34 POE::Component::IRC::Onjoin::EventProcessor  1.70   AFOXSON   


| Hello Dan,
|
| Thursday, April 3, 2003, 11:04:36 PM, you wrote:
|  Net::IRC isn't the best way in the world of creating an IRC bot. I just
|  use IO::Socket, and establish  maintain the connection to IRC myself
|  within my own source. Personally that's the better option.
|
| thanks for your advice. Since I didn't get one step ahead with
| Net::IRC I switched to IO::Socket. Some simple routines already work
| though I still do not know how to detect the modes of a channel or its
| users. RFC 2810-2812 either do not provide such an option or I just
| cannot find it. :)
|
| Best regards,
| oliver.

-- 

- Jim

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



sending an email to a email address after a perl operation

2003-04-04 Thread mel awaisi
Hi,

I have a script named renamer.pl that takes images from a directory and 
renames images and stores image meta information in a mysql. i also have a 
script that sends an email notification when excecuted to a desired email 
address.

is there away that i could combine the 2 scripts together, so when the meta 
information are inserted into MySQL, an email is sent to me.

Cheers

Mel

---emailtest.pl

#!/usr/local/bin/perl

use Net::SMTP;

print Content-type: text/plain, \n\n;

my $DEBUG = 1;

if($DEBUG)
{
$| = 1;
open(STDERR, STDOUT);
}
# Set this variable to your smtp server name
my $ServerName = smtp.dundee.ac.uk;
# Create a new SMTP object
$smtp = Net::SMTP-new($ServerName, Debug = 1);
# If you can't connect, don't proceed with the rest of the script
die Couldn't connect to server unless $smtp;
# Initiate the mail transaction
# Your real email address
my $MailFrom = [EMAIL PROTECTED];
# Recipient's real email address
my $MailTo = [EMAIL PROTECTED];
$smtp-mail( $MailFrom );
$smtp-to( $MailTo );
# Start the mail
$smtp-data();
# Send the header
# This address will appear in the message
$smtp-datasend(To: [EMAIL PROTECTED]);
# So will this one
$smtp-datasend(From: [EMAIL PROTECTED]);
$smtp-datasend(Subject: image_alert\n);
$smtp-datasend(\n);
# Send the body.
$smtp-datasend(This is to notify you of a new image being sent to the 
server!\n\n);

# Send the termination string
$smtp-dataend();
# Close the connection
$smtp-quit();


renamerr.pl
#!/usr/bin/perl
use strict;
use warnings;
use DBI;
use Date::Manip;
=head1 NAME # renamer - renames files received by ftp, moving them to a new
directory
=head1 SYNOPSIS

nohup ./renamer image /home/httpd/htdocs /home/me/images jpg renamer.process

=head1 DESCRIPTION

#The above instructs renamer to look for files called image.jpg in
/home/httpd/htdocs.
#It checks once per minute for such a file to appear. If it sees a
#readable file called /home/httpd/htdocs.jpg it moves it
to/home/httpd/htdocs/image.200302251530.jpg
#where the number is a
#time stamp with year (four digits), month, day of the month, hour (in24
mode), and minute.
#Read the bugs section closely.
=head1 BUGS

#The original and new directories must be on the same file system.The
#program probably does not work on windows systems.
#The daemon behavior is weak.Not much testing has been done, so the script
may have other problems.
=cut

my $usage = EOUSAGE;
usage: $0 initial_name original_dir new_dir suffix lockfile
example: $0 pic /home/httpd/htdocs /home/me/images jpg
/home/me/renamer.process
EOUSAGE
my $check_file = shift or die $usage;
my $original_dir = shift or die $usage;
my $new_dir = shift or die $usage;
my $suffix = shift or die $usage;
my $lockfile = shift or die $usage;
##
# If you put it into the cron, comment out between the START and END BLOCK,
# and uncomment the section below it so you don't get multiple
# copies running. Also, comment out the
# lockfile bits above.
#START BLOCK
exit if (fork());
while (-e $lockfile) {
process($check_file) if (-r $original_dir/$check_file.$suffix);
sleep 30;
}
#END BLOCK
##
#
# process($check_file) if (-r $original_dir/$check_file.$suffix);
#
##
sub process {
my $file = shift;
my @st = (stat($original_dir/$file.$suffix));
my ($Second, $Minute, $Hour, $Day, $Month, $Year, $WeekDay, $DayOfYear,
$IsDST) = localtime($st[10]);
$Year += 1900;
$Month++;
my $stamp = sprintf %4d_%02d_%02d_%02d_%02d_%02d, $Year, $Month, $Day,
$Hour, $Minute, $Second;
print renaming $original_dir/$file.$suffix to
$new_dir/$stamp.$suffix\n;
rename $original_dir/$file.$suffix, $new_dir/$stamp.$suffix or warn
couldn't rename file: $! $file to $new_dir/$file.$stamp.$suffix\n;
print adding $new_dir/$stamp.$suffix to database\n;
my $single_string = $new_dir . '/' . $stamp . '.' . $suffix;
infoinsert ($single_string);
}





#
# Connect to Database Named cctvimages on the localhost with the root user
# $dbh=DBI-connect(DBI:mysql;$database, $user, $password);
# and insert info about the file given as the argument $_[0];

#


sub infoinsert
{
my ($file) = @_;
dieFailed to get the info\n\$file is: $file if not defined $file;
my $dbh = DBI-connect(DBI:mysql:dbname=cctvimages;host=localhost,root,
, {'RaiseError' = 1});
my $size;
my $mtime;
my $secs;
($size, $secs) = (stat ($file))[7,9];
$mtime = ParseDateString(epoch $secs);
# even after conversion ':' is used to seperate hh and mn and ss
$mtime =~ s/://g;
# the above swaps out the ':' for nothing
$file =~ s/\/home\/me\/images\///;
# the above strips path
printsize is $size\nmodified is $mtime\nfilename is $file\n;
my $rows_affected = $dbh-do(INSERT INTO imageinfo VALUES(null, '$file',
'$size', '$mtime'))
or die Do Fails: 

Re: regex $1 not updating?

2003-04-04 Thread Bob Showalter
Jim wrote:
 I've never encountered this before but I have to be doing something
 wrong.

 snippet of code:

 ]$ perl -e '
  $var = Company Online (Company Systems) NETBLK-COM-5BLK
  (NET-24-256-0-0-1); $var =~ /.*? \(.*\) (.*?) \(.*?\)/;
  print $1,\n;
 
  $var = NetBlock: NETBLK-10H-6BLK;
  $var =~ /s\(.*?\) (.*?) \(.*?\)/;
  print $1,\n;
  '
 NETBLK-COM-5BLK
 NETBLK-COM-5BLK


 Why isn't $1 getting updated with the next implicit match?  It should
 fail but its returning the first $1 match.  I can't unset $1 because
 it is a read-only variable.  This doesn't even work if I change the
 second $var to $var2 because of course $1 is the same the way through.

 VERY frustrating.

This is the way the $1, $2, etc. variables work. They are only set if there
is a successful match. Otherwise, they simply retain whatever previous value
they had.

You either need to test that the match worked:

   if (/(\w+)/) {
  # $1 is now set
  print $1;
   }

Or, evaluate the match in list context:

   my ($word) = /(\w+)/;  # $word will be undef if no match





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



RE: sending an email to a email address after a perl operation

2003-04-04 Thread Dan Muey
 Hi,

Howdy again, still working on this huh?

 
 I have a script named renamer.pl that takes images from a 
 directory and 
 renames images and stores image meta information in a mysql. 
 i also have a 
 script that sends an email notification when excecuted to a 
 desired email 
 address.
 
 is there away that i could combine the 2 scripts together, so 
 when the meta 
 information are inserted into MySQL, an email is sent to me.

Sure.

#!/usr/bin/perl

...code that inserts into mysql ...

...code that sends mail ...


Ta Da! One script

DMuey

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



Re: [mail_lists] Re: regex $1 not updating?

2003-04-04 Thread Jim
On Friday 04 April 2003 14:34, John W. Krahn wrote:
| Jim wrote:
|  I've never encountered this before but I have to be doing something
|  wrong.
|
| Yes, you are.  This is the documented behaviour of the numeric variables
| and is why we always tell beginners to use them only if the regular
| expression matched.

Ok.  I didn't put tests in my example code.  However, I do have tests in my 
actual code which is what led me to this whole fiasco.  In this code I am 
finding that the first test ($back) pasts...and rightly so.  It should.  
However, in the following regex ($line) it should fail sometimes...but it 
doesn't.  It doesn't because when $back returns $1 as a valid return from the 
regex then $1 remains a valid rval for the condition for $line.  I need to 
get around that! 

Here is my code:

 76 for $back ( @data )
 77 {
 78 $go_on = 1;
 79 
 80 # start infinite loop
 81 
 82 while ( $go_on )
 83 {
 84 
 85 # if we see that there is a net_blk
 86 
 87 $back =~ /.*\(.*\) (.*?) .*/;
 88 
 89 if ( $1 )
 90 {
 91 
 92 # add it to the array
 93 
 94 push(@ret,$1);
 95 
 96 # walk it
 97 push(@done,$1);
 98 my @more = get_whois($1);
 99 
100 # repeat process
101 for my $line ( @more )
102 {
103 $line =~ /.* \(.*\) (.*?) .*/;
104 
105 if ( $1 )
106 {
107 print Pushing net_blk: $1\n;
108 push(@ret,$1);
109 }
110 else
111 {
112 print Go on to next iteration.\n;
113 $go_on = 0;
114 }
115 
116 print Pushing $1 to [EMAIL PROTECTED] stack\n;
117 last if ( grep($1,@done) );
118 }
119 }
120 else
121 {
122 $go_on = 0;
123 }
124 }
125 }


|
|  snippet of code:
| 
|  ]$ perl -e '
| 
|   $var = Company Online (Company Systems) NETBLK-COM-5BLK
| 
|  (NET-24-256-0-0-1);
| 
|   $var =~ /.*? \(.*\) (.*?) \(.*?\)/;
|   print $1,\n;
|
| print $1\n if $var =~ /.*? \(.*\) (.*?) \(.*?\)/;
|
|   $var = NetBlock: NETBLK-10H-6BLK;
|   $var =~ /s\(.*?\) (.*?) \(.*?\)/;
|   print $1,\n;
|
| print $1\n if $var =~ /s\(.*?\) (.*?) \(.*?\)/;
|
|   '
| 
|  NETBLK-COM-5BLK
|  NETBLK-COM-5BLK
| 
|  Why isn't $1 getting updated with the next implicit match?  It should
|  fail but its returning the first $1 match.  I can't unset $1 because it
|  is a read-only variable.  This doesn't even work if I change the second
|  $var to $var2 because of course $1 is the same the way through.
|
| $1, $2, $3, etc. are only set on a successful match otherwise they
| retain the value from the previous successful match.
|
|
| John

-- 

- Jim

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



RE: regex $1 not updating?

2003-04-04 Thread Timothy Johnson


This feature is by design.  :)

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



RE: [mail_lists] Re: regex $1 not updating?

2003-04-04 Thread Mark Anderson
Go back and re-read John's message.  Then look at your conditionals.  They
are different.  His work, yours don't.

Yours:

 87 $back =~ /.*\(.*\) (.*?) .*/;
 88
 89 if ( $1 )

103 $line =~ /.* \(.*\) (.*?) .*/;
104
105 if ( $1 )

His:

| print $1\n if $var =~ /.*? \(.*\) (.*?) \(.*?\)/;

| print $1\n if $var =~ /s\(.*?\) (.*?) \(.*?\)/;

You aren't checking to see if the REGULAR EXPRESSION SUCCEEDED.  If the
regular expression FAILS, then $1 retains the old value, it isn't reset.

/\/\ark


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



RE: sending an email to a email address after a perl operation

2003-04-04 Thread Dan Muey

 Hi Dan

Hey, reply to the list not just me.

 
 yeh still here, back from a small break. just want to finish it!!.
 
 i tried this and this is what i got:
 
 Global symbol $smtp requires explicit package name at 

Make 
$smtp = ...

my $smtp = ...

There was a thread earlier today about namespaces. Check out the archive it was quite 
informative.

 rename.pl line 140. Global symbol $smtp requires explicit 
 package name at rename.pl line 143. Global symbol $smtp 
 requires explicit package name at rename.pl line 151. Global 
 symbol $smtp requires explicit package name at rename.pl 
 line 152. Global symbol $smtp requires explicit package 
 name at rename.pl line 155. Global symbol $smtp requires 
 explicit package name at rename.pl line 159. Global symbol 

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



Re: [mail_lists] Re: regex $1 not updating?

2003-04-04 Thread Jim
On Friday 04 April 2003 14:54, Bob Showalter wrote:

Wow!  I've coding in Perl for almost three years now and I didn't this.

Anyhoo, Bob's advice was the what I used and it works now.  I just moved the 
regex evals into the if condition statements vs the way I was doing it.

Thanks for the assistance guys.

- Jim

| Jim wrote:
|  I've never encountered this before but I have to be doing something
|  wrong.
| 
|  snippet of code:
| 
|  ]$ perl -e '
| 
|   $var = Company Online (Company Systems) NETBLK-COM-5BLK
|   (NET-24-256-0-0-1); $var =~ /.*? \(.*\) (.*?) \(.*?\)/;
|   print $1,\n;
|  
|   $var = NetBlock: NETBLK-10H-6BLK;
|   $var =~ /s\(.*?\) (.*?) \(.*?\)/;
|   print $1,\n;
|   '
| 
|  NETBLK-COM-5BLK
|  NETBLK-COM-5BLK
| 
| 
|  Why isn't $1 getting updated with the next implicit match?  It should
|  fail but its returning the first $1 match.  I can't unset $1 because
|  it is a read-only variable.  This doesn't even work if I change the
|  second $var to $var2 because of course $1 is the same the way through.
| 
|  VERY frustrating.
|
| This is the way the $1, $2, etc. variables work. They are only set if there
| is a successful match. Otherwise, they simply retain whatever previous
| value they had.
|
| You either need to test that the match worked:
|
|if (/(\w+)/) {
|   # $1 is now set
|   print $1;
|}
|
| Or, evaluate the match in list context:
|
|my ($word) = /(\w+)/;  # $word will be undef if no match

-- 

- Jim

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



RE: sending an email to a email address after a perl operation

2003-04-04 Thread mel awaisi
thanks Dan,

sorry for forgetting to send to list.

the email script works alone, as it is, so maybe it is something else.

Regards,

Mel





From: Dan Muey [EMAIL PROTECTED]
To: mel awaisi [EMAIL PROTECTED]
CC: [EMAIL PROTECTED]
Subject: RE: sending an email to a email address after a perl operation
Date: Fri, 4 Apr 2003 17:10:10 -0600
 Hi Dan

Hey, reply to the list not just me.


 yeh still here, back from a small break. just want to finish it!!.

 i tried this and this is what i got:

 Global symbol $smtp requires explicit package name at
Make
$smtp = ...
my $smtp = ...

There was a thread earlier today about namespaces. Check out the archive it 
was quite informative.

 rename.pl line 140. Global symbol $smtp requires explicit
 package name at rename.pl line 143. Global symbol $smtp
 requires explicit package name at rename.pl line 151. Global
 symbol $smtp requires explicit package name at rename.pl
 line 152. Global symbol $smtp requires explicit package
 name at rename.pl line 155. Global symbol $smtp requires
 explicit package name at rename.pl line 159. Global symbol
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


_
Surf together with new Shared Browsing 
http://join.msn.com/?page=features/browsepgmarket=en-gbXAPID=74DI=1059

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


Re: [mail_lists] Re: regex $1 not updating?

2003-04-04 Thread Rob Dixon
Hi Jim.

I think yu've got a bit lost in your nexted loops. I've tried to understand what
your code does and is meant to do and have written my interpretation
below. There are a few things that I can't fathom though.

Jim wrote:
 On Friday 04 April 2003 14:34, John W. Krahn wrote:
  Jim wrote:
   I've never encountered this before but I have to be doing something
   wrong.
 
  Yes, you are.  This is the documented behaviour of the numeric variables
  and is why we always tell beginners to use them only if the regular
  expression matched.

 Ok.  I didn't put tests in my example code.  However, I do have tests in my
 actual code which is what led me to this whole fiasco.  In this code I am
 finding that the first test ($back) pasts...and rightly so.  It should.
 However, in the following regex ($line) it should fail sometimes...but it
 doesn't.  It doesn't because when $back returns $1 as a valid return from the
 regex then $1 remains a valid rval for the condition for $line.  I need to
 get around that!

 Here is my code:

  76 for $back ( @data )
  77 {
  78 $go_on = 1;
  79
  80 # start infinite loop
  81
  82 while ( $go_on )
  83 {
  84
  85 # if we see that there is a net_blk
  86
  87 $back =~ /.*\(.*\) (.*?) .*/;
  88
  89 if ( $1 )
  90 {
  91
  92 # add it to the array
  93
  94 push(@ret,$1);
  95
  96 # walk it
  97 push(@done,$1);
  98 my @more = get_whois($1);
  99
 100 # repeat process
 101 for my $line ( @more )
 102 {
 103 $line =~ /.* \(.*\) (.*?) .*/;
 104
 105 if ( $1 )
 106 {
 107 print Pushing net_blk: $1\n;
 108 push(@ret,$1);
 109 }
 110 else
 111 {
 112 print Go on to next iteration.\n;
 113 $go_on = 0;
 114 }
 115
 116 print Pushing $1 to [EMAIL PROTECTED] stack\n;
 117 last if ( grep($1,@done) );
 118 }
 119 }
 120 else
 121 {
 122 $go_on = 0;
 123 }
 124 }
 125 }

Take a look at this, which has something like your semantics:

foreach my $back ( @data ) {

next unless ( $back =~ /\)\s+(.+)\s+\(/ ) {

push @ret, $1;
push @done, $1;

my @more = get_whois($1);

foreach my $line ( @more ) {

if ( $line =~ /\)\s+(.+)\s+\(/ ) {
print Pushing net_blk: $1\n;
push @ret, $1;
}
}

print Pushing $1 to [EMAIL PROTECTED] stack\n;
last if ( grep($1,@done) );
}

The stack pushes are done in the equivalent place, but I think
they're not quite right; in particular the push to @ret is happening
teice. I could make neither head nor tail of your grep() call: all
I know is that it's wrong!

I hope this is a better starting point for you.

HTH,

Rob




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



Re: Is there any Polling mechanism in perl ?

2003-04-04 Thread Wiggins d'Anconia
Madhu Reddy wrote:
Hi,
  Is there any polling mechanism in perl ?
Following is my problem..
my program has to wait (poll) on particular
folder...
If any file arrived on that folder, my main program
has to invoke another program...
In Unix, we have poll() system call for waiting on 
particular event ?

is there any similar thing in perl to wait on
particular event ?
if event occurs trigger some job..
following is my algorithm...
i want to implement in better way...
here file arrived means, completely transfered...
Files will be FTPed to C:\temp on my local system...
once that FTP is completed, i want to know...
But i don't want to know in the middle of FTP.
I want to know after FTP done...
I think here we need unix lsof command?
Does anybody have any idea ? about that?

while(1) {
 if (file arrived on C:\temp\) {
 mail me the file name. 
  }

}
You may run into limitations on the Win32 platform, but there are 
several places to start, check out:

http://search.cpan.org/author/JPRIT/Event-0.87/lib/Event.pod

Or for a higher level approach, check out POE:

http://poe.perl.org

There is a pre-built component for this very thing, 
POE::Component::Dirwatch which is not terribly robust, but it sounds 
adequate for your purposes.  I used it for several months before hacking 
a more specifically tailored version for our app that handles errors 
better and more specific file uses. POE has a relatively steep learning 
curve at the beginning but once over the hump it is incredibly powerful.

In both cases be sure to check out the Win32 compatibility I have no 
knowledge on this front

http://danconia.org

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


Re: HASH PRINTING

2003-04-04 Thread Wiggins d'Anconia


Eric Walker wrote:

Sorry for the ignorance but I think I am able to pull the first layer of
the hash but the values that are also hashes or arrays I get memory
pointers out .
For example:

TEMP: 2.0
TEMP5: ARRAY(0xdb660)
TEMP6: HASH(0xa2058)
Any suggestions on how to access the array and or hash at that point?

Welcome to the world of references... now for some bedtime reading...

perldoc -f ref
perldoc UNIVERSAL::isa
perldoc perldsc
perldoc perlreftut
perldoc perlref
After you have digested some of the above (don't worry you won't get it 
all the first time through) give it another shot and then ask more 
questions

http://danconia.org

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


maching end of a line with $

2003-04-04 Thread Jose Malacara
Can someone help me out here, please.

I have an if statement that is looping over a list of IP addresses:

192.168.1.1
192.168.1.2
192.168.1.3 ...192.168.1.10

$value=192.168.1.1

if ($line =~ /($value)/) ...

I only want to match the value exactly (192.168.1.1). My problem is that I am matching 
all addresses containing that string (192.168.1.10, 192.168.1.11, 192.168.1.100, 
etc...)

I know the trailing '$' anchors the match to the end of the line only, but I cannot 
seem to get it to work as I think my syntax is incorrect.

Any help would be appreciated.

Thanks,
Jose

Re: maching end of a line with $

2003-04-04 Thread Wiggins d'Anconia
Jose Malacara wrote:
Can someone help me out here, please.

I have an if statement that is looping over a list of IP addresses:

192.168.1.1
192.168.1.2
192.168.1.3 ...192.168.1.10
$value=192.168.1.1

if ($line =~ /($value)/) ...

I only want to match the value exactly (192.168.1.1). My problem is that I am matching all addresses containing that string (192.168.1.10, 192.168.1.11, 192.168.1.100, etc...)

In the case of an exact match why not just use string equality test? 
(don't forget to 'chomp' the line if you are getting it from a filehandle)

if ($line eq $value) 

I know the trailing '$' anchors the match to the end of the line only, but I cannot seem to get it to work as I think my syntax is incorrect.

What trailing '$' you don't have one in the code you posted above...if 
you insist on the regex, it would go something like:

if ($line =~ /^($value)$/) 

Which says match $value (and set it to $1) starting at the beginning of 
the string '^' and going until the end of the string '$'.

http://danconia.org

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


Re: maching end of a line with $

2003-04-04 Thread John W. Krahn
Jose Malacara wrote:
 
 Can someone help me out here, please.
 
 I have an if statement that is looping over a list of IP addresses:
 
 192.168.1.1
 192.168.1.2
 192.168.1.3 ...192.168.1.10
 
 $value=192.168.1.1
 ^   ^ ^
 ^   ^ ^
 if ($line =~ /($value)/) ...

The periods in a regular expression match any character.  You need to
escape them to match literal periods.

if ( $line =~ /(\Q$value\E)/ ) ...


 I only want to match the value exactly (192.168.1.1).

If you want to match exactly then you should use the 'eq' operator.

chomp $line;
if ( $line eq $value ) ...


 My problem is that I
 am matching all addresses containing that string (192.168.1.10, 192.168.1.11,
 192.168.1.100, etc...)
 
 I know the trailing '$' anchors the match to the end of the line only, but
 I cannot seem to get it to work as I think my syntax is incorrect.

Show us what you tried.


John
-- 
use Perl;
program
fulfillment

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



need help - simple HASHES question

2003-04-04 Thread Ciprian Morar
1. What is the difference between Line #1 and Line #2?
2. Why is the Line #2 declaration incorrect?
use strict;

my %option;
$option {'q'} = new CGI;
#Line 1-
$option{'Mon'} = 'Monday';
#Line 2 -
$option-{'Tue'} = 'Tuesday';
print $option{'q'} - header(),
$option{'q'} - start_html();
print $option{'q'} - end_html;

#thanks---

_
Get Hotmail on your mobile phone http://www.msn.co.uk/mobile
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


Re: need help - simple HASHES question

2003-04-04 Thread John W. Krahn
Ciprian Morar wrote:
 
 1. What is the difference between Line #1 and Line #2?
 2. Why is the Line #2 declaration incorrect?
 
 use strict;
 
 my %option;
 $option {'q'} = new CGI;
 
 #Line 1-
 $option{'Mon'} = 'Monday';
 
 #Line 2 -
 $option-{'Tue'} = 'Tuesday';
 
 print $option{'q'} - header(),
 $option{'q'} - start_html();
 
 print $option{'q'} - end_html;

1. On line 1 you are assigning a value to a key of the %option hash.  On
line 2 you are assigning a value to a key of the anonymous hash
referenced through the $option scalar.

2. You have not declared the scalar $option before using it.

perldoc perlreftut
perldoc perlref
perldoc perldata
perldoc perldsc


John
-- 
use Perl;
program
fulfillment

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



Re: matching patterns - - - EXPLANATION

2003-04-04 Thread R. Joseph Newton
R. Joseph Newton wrote:

Sorry Diego,

Turns out that there was a logic error in the code I posted that gave a false positive 
on the match.

 #!perl -w

 use strict;
 use warnings;

 my $pat1 = qr /Hi.*?\sBye/;
 #  my $pat2 = qr /(Hi|[Hh]ello).*?\sBye--I'll sure miss you\!/;  #  Error

This does not work.  Becuase the space escape is not a ltieral space the smaller regex 
being matched against it wwill actually reject the match.  This is corrected by 
changing the escape here to a literal space:

my $pat2 = qr /(Hi|[Hh]ello).*?\sBye--I'll sure miss you\!/;

 print $pat1 is the \smaller\ pattern\n;
 print $pat2 is the \larger\ pattern\n;
 print \n;

 if ($pat2 =~ $pat1) {
  print $pat2 contains $pat1\n;
 } else {
 #  print $pat2 matches $pat1\n; #  False match generator
 }
 print \n;

Corrected as:

if ($pat2 =~ $pat1) {
 print $pat2 matches $pat1\n;
} else {
 print $pat2 does not match $pat1\n;
}
print \n;

With the corrections noted, the code does provide the same output as the original, 
differing only in the content of the second regex.  I think the following should give 
a pretty accurate picture of whether one compiled regex is a true subpattern of the 
other, although it would take more work to identify subpatterns which originate within 
the larger regex, rather than at the same origin:

 my $test = $pat1;
 chop $test;  # kill  the closing paren of the canonical regex
 if ($test eq substr($pat2, 0, length($test))) {
   print $pat1 is a true sub-pattern of $pat2\n;
 } else {
   print $pat1 could not be identified by this test as a true initial sub-pattern of 
 $pat2\n;
 }
 print \n;

 my $string1 = Hello, Bye--I'll sure miss you!;

 if ($string1 =~ $pat1) {
   print $string1 matches $pat1\n;
 } else {
   print $string1 does not match $pat1\n;
 }

 if ($string1 =~ $pat2) {
   print $string1 matches $pat2\n;
 } else {
   print $string1 does not match $pat2\n;
 }

 Hi There,podner E:\d_drive\perlStuffpat_holds.pl
 (?-xism:Hi.*?\sBye) is the smaller pattern
 (?-xism:(Hi|[Hh]ello).*?\sBye--I'll sure miss you!) is the larger pattern

 (?-xism:(Hi|[Hh]ello).*?\sBye--I'll sure miss you!) matches (?-xism:Hi.*?\sBye)

 (?-xism:Hi.*?\sBye) is not a true sub-pattern of (?-xism:(Hi|[Hh]ello).*?\sBye--
 I'll sure miss you!)

 Hello, Bye--I'll sure miss you! does not match (?-xism:Hi.*?\sBye)
 Hello, Bye--I'll sure miss you! matches (?-xism:(Hi|[Hh]ello).*?\sBye--I'll sure
  miss you!)

 Hi There,podner E:\d_drive\perlStuff

 Joseph

 --
 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: dumb array/hash question

2003-04-04 Thread R. Joseph Newton
jdavis wrote:

Hi Please post to the list.  I did a lot of work on my reply to this, and didn't even 
notice till now that it had not reached the list.

Pasted below:
 On Tue, 2003-04-01 at 13:07, R. Joseph Newton wrote:
  jdavis wrote:
 I have a hash. To use this hash with a module I need it in this form...
   
@data = (
[12am,1am,2am,3am,4am,5am,6am, 7am, 8am],  ### key
[   251,   102,  55,   36,   113,  200,32,99,   4],   ###val
);
I confused.. How could I get a hash to the above structure
   
 
   I have a hash that i needed to put into a 2d array.
   I wound up doing this...
  
   foreach $key (keys(%temp)){
   push(@graph_key,$key);
   push(@graph_value,$temp{$key});
   }
  
   $data[0] = [EMAIL PROTECTED];
   $data[1] = [EMAIL PROTECTED];
 
  Nice!  Very nice!
 
   Though Im not quite sure why i need to escape the @?
   but it works :)
 
  You don't.  In that context, outside of any string, you are taking a reference
to each array.  You will profit greatly by reading up on references.  They are one
of the keys to power programming.

 dont put a pointer to the array inside $data[0],
 but actually put the whole @array_object into $data[0] ?

 Is that whats happening?

Sort of, except the other way.  In fact, that is not possible to put a whole array
into the element..  Any element of an array can hold only a single scalar.  That is
what I mean about power programming.  Using references allows you to link to
structures that you could never possibly store as elements.  This allows you to
model objects of any degree of complexity on a single hash:

#!perl -w

use strict;
use warnings;

my $full_name = Robert Joseph Newton;
my $address_part_1 = '000 Surly Lane';
my $address_part_2 = '';
my @children = ({Name = 'Joe', Age = 19},
  {Name = 'Bonnie', Age = 17}, {Name = 'Clyde', Age = 16},
   {Name = 'Floyd', Age = 14,
Interests = ['Reading', 'Running', 'Rithmetik']});

my  $person_ref = {
  Fullname = $full_name,
  Address = {
Street = $address_part_1,
Street2 = $address_part_2
  },
  Children = [EMAIL PROTECTED]
};

foreach (keys %{$person_ref}) {
  print $_\n;
  my $referent = $person_ref-{$_};
  if (ref($referent)) {
if ($referent =~ /^ARRAY/) {
  plumb_array ($referent, 2);
} elsif ($referent =~ /^HASH/) {
  plumb_hash ($referent, 2);
}
  } else {
print   $person_ref-{$_}\n;
  }
}
print Are the attributes and values of this person.\n\n;


sub plumb_array {
  my ($array_ref, $indent) = @_;
  foreach (@{$array_ref}) {
my $element = $_;
my $ref_class = ref($element);
if ($ref_class) {
  if ($ref_class =~ /^ARRAY/) {
plumb_array($element, $indent + 2);
  } elsif ($ref_class =~ /^HASH/) {
plumb_hash($element, $indent + 2);
  }
} else {
  print ' ' x ($indent) . $element\n;
}
  }
  print \n;
}

sub plumb_hash {
  my ($hash_ref, $indent) = @_;
  foreach (keys %{$hash_ref}) {
my $element = $hash_ref-{$_};
my $ref_class = ref($element);
if ($ref_class) {
  if ($ref_class =~ /^ARRAY/) {
print ' ' x ($indent) . $_:\n;
plumb_array($element, $indent + 2);
  } elsif ($ref_class =~ /^HASH/) {
print ' ' x ($indent) . $_:\n;
plumb_hash($element, $indent + 2);
  }
} else {
  print ' ' x ($indent) . $_: $element\n;
}
  }
  print \n;
}

OUTPUT:

Howdy, podner! E:\d_drive\perlStuffperson_hash.pl
Address
  Street2:
  Street: 000 Surly Lane

Children
Age: 19
Name: Joe

Age: 17
Name: Bonnie

Age: 16
Name: Clyde

Age: 14
Interests:
  Reading
  Running
  Rithmetik

Name: Floyd


Fullname
  Robert Joseph Newton
Are the attributes and values of this person.


Howdy, podner! E:\d_drive\perlStuff

Joseph




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



Re: HASH PRINTING

2003-04-04 Thread R. Joseph Newton
Eric Walker wrote:


 Sorry for the ignorance but I think I am able to pull the first layer of
 the hash but the values that are also hashes or arrays I get memory
 pointers out .

Not exactly.  Those are references.  The difference in some ways is suble, but
the upshot is that you shold never try to do pointer aritmetic on references.

 For example:

 TEMP: 2.0
 TEMP5: ARRAY(0xdb660)
 TEMP6: HASH(0xa2058)

 Any suggestions on how to access the array and or hash at that point?

To access a hash element from a reference to the hash:
$hash_ref-{$key} or $hash_ref-{'My_literal_key_name'}

To access an array element from a reference to the array:
$array_ref-[0] or $array_ref-[$n]

See the list of perldoc references sent by Wiggins d'Anconia
.
Joseph


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



Re: use of ? operator instead of if

2003-04-04 Thread R. Joseph Newton
Jeff Westman wrote:

  At last! Thanks Bob, this /is/ how to use the conditional operator,
  while
 
  $VAL ? ( $VAL = $VAL:$expr ) : ( $VAL = $expr )
 
  /isn't/. ?: is an /operator/. It happens to have three operands
  instead of the usual two or 1, but it is meant for deriving a
  new value from three others, like a function.
 
  sub conditional {
  my ($test, $val1, $val2);
  return $val1 if $test;
  return $val2;
  }
 
  $VAL = conditional ($VAL, $VAL:$expr, $expr)
 
  Rob

 If you ask /me/ the above code is a lot harder to read to the simple one-line
 ternary as was mentioned before (expr:true?false).

Hi Jeff,

I certainly agree, and I'm sure Rob would too.  I don't hink his point was to
recommend the conditional() function for actual use, but to outline in function
form the logic implemented by the operator.

 The ternary operation is used to make your code more concise and readable,
 but in a limited context.  IE, you can nest ternary operations ... have fun
 maintaining it!

 -JW

Absolutely.  Terse operations can certainly add immediacy and punch to code when
the context is small enough to be crystal clear.  Trying to pack complicated
logic into them simply imposes an equal or greater burden of unpacking the logic
whe reviewing the code.

Joseph


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



Re: sending an email to a email address after a perl operation

2003-04-04 Thread R. Joseph Newton
mel awaisi wrote:

 There was a thread earlier today about namespaces. Check out the archive it
 was quite informative.
 
   rename.pl line 140. Global symbol $smtp requires explicit
   package name at rename.pl line 143. Global symbol $smtp
   requires explicit package name at rename.pl line 151. Global
   symbol $smtp requires explicit package name at rename.pl
   line 152. Global symbol $smtp requires explicit package
   name at rename.pl line 155. Global symbol $smtp requires
   explicit package name at rename.pl line 159. Global symbol
 

Hi Mel,

Since your two scripts were developoed separately, you might want to add
use strict;
to emailtest.pl, and work on that until it compiles cleanly.  These errors
indicate that you are not declaring your variables properly.  Once that script
compiles cleanly, you could integrate the code from renamerr.pl into it.

I would say that you are also pushing the limits of what you can sensibly do
with scripting.  If you wish to be able to develop complicated processes, you
should really learn how to write subroutines and functions.

perldoc perlsub
perldoc perlref
perldoc perlreftut

Hint: If the code in renamer was properly packaged within functions, you would
not have to cut and paste code.  You could use renamer as a module, and call
functions from it in other scripts.

Joseph


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



Re: [mail_lists] Re: regex $1 not updating?

2003-04-04 Thread John W. Krahn
R. Joseph Newton wrote:
 
 from your original post raised a red flag for me:
  $var =~ /.*? \(.*\) (.*?) \(.*?\)/;
 I saw it, and wondered Well, what is he doing with it?.  The matching function
 is intended to return a true value on success, and that value is assigned to your
 blandly-named $var, yet it is never used.

No, that value is NOT assigned to $var.  The expression is in a void
context so the result of the expression is not assigned to anything. 
You need to use the assignment operator '=' if you want to assign the
result of the expression to some variable.


 Try instead:
 if  ($var =~ /.*? \(.*\) (.*?) \(.*?\)/;) ) {
 ^
That semicolon is a syntax error.  It won't compile.



John
-- 
use Perl;
program
fulfillment

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



Re: maching end of a line with $

2003-04-04 Thread R. Joseph Newton
Jose Malacara wrote:

 Can someone help me out here, please.

 I have an if statement that is looping over a list of IP addresses:

 192.168.1.1
 192.168.1.2
 192.168.1.3 ...192.168.1.10

 $value=192.168.1.1

 if ($line =~ /($value)/) ...

Should not return true for
192.168.1.3
But should return true for:
192b16801h1
192316871k1085d
192_168-161
1921681 1
etc..{1/0}


 I only want to match the value exactly (192.168.1.1). My problem is that I am 
 matching all addresses containing that string (192.168.1.10, 192.168.1.11, 
 192.168.1.100, etc...)

 I know the trailing '$' anchors the match to the end of the line only, but I cannot 
 seem to get it to work as I think my syntax is incorrect.

 Any help would be appreciated.

 Thanks,
 Jose

Hi Jose,

Could you send more of the code, and some test results?  Although there is clearly a 
problem with using a simple quoted string in a regex, I don't see the results you cite 
as
reflecting the consequences.  As noted above, something like '192.168.1.3' should not 
match, so I think there may be some problem elsewhere in the code, also.

For now, you might want to:
perldoc -f quotemeta

Joseph


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



Re: [mail_lists] Re: regex $1 not updating?

2003-04-04 Thread R. Joseph Newton
John W. Krahn wrote:

 R. Joseph Newton wrote:
 
  from your original post raised a red flag for me:
   $var =~ /.*? \(.*\) (.*?) \(.*?\)/;
  I saw it, and wondered Well, what is he doing with it?.  The matching function
  is intended to return a true value on success, and that value is assigned to your
  blandly-named $var, yet it is never used.

 No, that value is NOT assigned to $var.  The expression is in a void
 context so the result of the expression is not assigned to anything.
 You need to use the assignment operator '=' if you want to assign the
 result of the expression to some variable.

  Try instead:
  if  ($var =~ /.*? \(.*\) (.*?) \(.*?\)/;) ) {
  ^
 That semicolon is a syntax error.  It won't compile.

Thanks John,

I noticed that on first scan, hence the red flag, and then I misread it while pasting
it in.

Joseph


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