Re: Strange error: PerlRun

2005-09-29 Thread Jeff Peng
too few info u have given.
It seems that u have problem at the interface of cgi script to web server.

2005/9/28, Graeme McLaren [EMAIL PROTECTED]:
 Afternoon all, I have a strange error:

 [Tue Sep 27 14:43:41 2005] [error] PerlRun: `failed at stage 1: Input/output
 error
 at /usr/local/lib/perl5/5.8.0/CGI/Carp.pm line 301.


 I have had a google around and I've not found anything.

 Does anyone know what this means or what problem this could point to?



 Cheers in advance,

 Graeme :)



 --
 To unsubscribe, e-mail: [EMAIL PROTECTED]
 For additional commands, e-mail: [EMAIL PROTECTED]
 http://learn.perl.org/ http://learn.perl.org/first-response





--
  Jeff Peng
  [EMAIL PROTECTED]

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Current directory?

2005-09-29 Thread gustav
Hi there!

I want to get the current environment variable (current directory), and I
type like this:

$currentpath = %ENV;

and I get something like 37/64
instead of maybe usr/username/test

How do I get current directory?

/G




-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: Current directory?

2005-09-29 Thread John W. Krahn
[EMAIL PROTECTED] wrote:
 Hi there!

Hello,

 I want to get the current environment variable (current directory), and I
 type like this:
 
 $currentpath = %ENV;
 
 and I get something like 37/64
 instead of maybe usr/username/test
 
 How do I get current directory?

perldoc Cwd


John
-- 
use Perl;
program
fulfillment

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: Current directory?

2005-09-29 Thread Jeff Peng
#!/usr/bin/perl
use strict;
use Cwd;

print getcwd,\n; #get the current path
print $ENV{PATH};  #get the path from environment variable

2005/9/29, [EMAIL PROTECTED] [EMAIL PROTECTED]:
 Hi there!

 I want to get the current environment variable (current directory), and I
 type like this:

 $currentpath = %ENV;

 and I get something like 37/64
 instead of maybe usr/username/test

 How do I get current directory?

 /G




 --
 To unsubscribe, e-mail: [EMAIL PROTECTED]
 For additional commands, e-mail: [EMAIL PROTECTED]
 http://learn.perl.org/ http://learn.perl.org/first-response





--
  Jeff Peng
  [EMAIL PROTECTED]

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: Current directory?

2005-09-29 Thread Gustav Wiberg

Hi there!

Thanx! I'll try that! :-)

/G

- Original Message - 
From: Jeff Peng [EMAIL PROTECTED]

To: [EMAIL PROTECTED]
Cc: beginners@perl.org
Sent: Thursday, September 29, 2005 10:27 AM
Subject: Re: Current directory?


#!/usr/bin/perl
use strict;
use Cwd;

print getcwd,\n; #get the current path
print $ENV{PATH};  #get the path from environment variable

2005/9/29, [EMAIL PROTECTED] [EMAIL PROTECTED]:

Hi there!

I want to get the current environment variable (current directory), and I
type like this:

$currentpath = %ENV;

and I get something like 37/64
instead of maybe usr/username/test

How do I get current directory?

/G




--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response






--
 Jeff Peng
 [EMAIL PROTECTED]

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




--
No virus found in this incoming message.
Checked by AVG Anti-Virus.
Version: 7.0.344 / Virus Database: 267.11.8/114 - Release Date: 2005-09-28



--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: DBI fetch

2005-09-29 Thread Tom Allison

Peter Scott wrote:
On Sat, 27 Aug 2005 14:07:09 +0300, Octavian Rasnita wrote: 


What do you think, if the most important is the speed, which method is
recommended to get the results of a DBI query?

fetchrow_arrayref
or
fetchrow_array

(I guess that fetchrow_hashref has the lowest speed).



That wasn't one of your choices.

Don't guess, measure.  perldoc Benchmark.



Peters right.  Measure it.  And I would love to know your findings.  But 
you probably need to include the database (pgsql, mysql, oracle...) 
because of the different backends.


Be careful that your first SQL doesn't become cached giving you 
artificially fast returns on subsequent queries.  In Oracle I typically 
can run a SQL statement in say 3 seconds and run it again right away and 
get 0.2 seconds.  But you'll see that on the first two runs.


One thing that Perl has a lot of (and doesn't get enough coverage) are 
the tools for development.  Benchmark, Test::More, Devel::Size, 
Devel::Cover, Data::Dumper -- these are all wonderful tools at your 
disposal and well worth spending some serious time learning how to use.


As an anectdote, my brother has fallen in favor with Python while I'm a 
Perl fan.  Tools like this are either unavailable or unknown to him (I 
honestly don't know which).  In either case it's apparent that he has a 
lot of work to do in validating and testing code that I don't have to 
experience.


--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: Date in perl

2005-09-29 Thread Tom Allison

Gomez, Juan wrote:

Hi all
 
 
I have a problem need to work with date
 
I have a input like these :   20050829 and I need to change it to 
something like this : Aug 29 2005
 
but it still eludes me how to do that
 
can anyone help me please?
 
 
 
 
 
thanks
 
 
Armando


I was going to say use regex but then I saw this nice example of 
unpack which should be faster.


So I tested it:


#!/usr/bin/perl
#

use strict;
use warnings;
use Benchmark ':hireswallclock';

my $string = 20050829;

timethese(100, {
'regex' = sub { my @array = $string=~/(\d\d\d\d)(\d\d)(\d\d)/;},
'unpack'= sub { my @array = unpack(A4A2A2,$string); },
});


And ended up with this:

[EMAIL PROTECTED]:~$ benchmark.pl
Benchmark: timing 100 iterations of regex, unpack...
 regex: 2.75194 wallclock secs ( 2.75 usr +  0.00 sys =  2.75 CPU) 
@ 363636.36/s (n=100)
unpack: 2.15273 wallclock secs ( 2.15 usr +  0.00 sys =  2.15 CPU) 
@ 465116.28/s (n=100)


I think the POSIX modules would be considerably slower but I did not 
test them.


--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: Current directory?

2005-09-29 Thread Chris Devers
On Thu, 29 Sep 2005 [EMAIL PROTECTED] wrote:

 I want to get the current environment variable (current directory), and I
 type like this:
 
 $currentpath = %ENV;

Why do you expect this to do anything useful?

You're assigning the contents of a hash into a single scalar.

That will almost never do anything useful.

As others noted, if you want a specific element from a hash, you have to 
name it explicitly --

$currentpath = $ENV{PWD};

-- or, as another person noted, use the Cwd module to do this in a more 
guaranteed to be portable way. 

But in any case, assigning a (full) hash to a scalar will never work :-)



-- 
Chris Devers

6f9A/

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




RE: Date in perl

2005-09-29 Thread Bakken, Luke
Tom Allison wrote:
 Gomez, Juan wrote:
 I have a problem need to work with date
 
 I have a input like these :   20050829 and I need to change it to
 something like this : Aug 29 2005
 
 but it still eludes me how to do that
 
 can anyone help me please?
 

 I was going to say use regex but then I saw this nice example of
 unpack which should be faster.
 
 So I tested it:
 And ended up with this:
 
 [EMAIL PROTECTED]:~$ benchmark.pl
 Benchmark: timing 100 iterations of regex, unpack...
   regex: 2.75194 wallclock secs ( 2.75 usr +  0.00 sys =  2.75
 CPU) @ 363636.36/s (n=100)
  unpack: 2.15273 wallclock secs ( 2.15 usr +  0.00 sys =  2.15
 CPU) @ 465116.28/s (n=100)
 
 I think the POSIX modules would be considerably slower but I did not
 test them.

If absolute speed is essential Juan should load up an array with a month
number - month name index and use substr to extract the month, day and
year values out of the string, i.e. months[0] = 'Jan', months[1] =
'Feb'

However, if his date string may change I'd use strftime() with substr().

use strict;
use warnings;
use POSIX qw/strftime/;
use Benchmark ':hireswallclock';

my $string = '20050829';
timethese(100, {
 'regex' = sub { my @array = $string=~/(\d\d\d\d)(\d\d)(\d\d)/;},
 'unpack'= sub { my @array = unpack('A4A2A2', $string); },
 'substr'= sub { my @array = (substr($string, 0, 4),
substr($string, 4, 2), substr($string, 6, 2)); },
});

print strftime('%b %d %Y', 0, 0, 0, substr($string, 6, 2),
substr($string, 4, 2) - 1, substr($string, 0, 4) - 1900);

Outputs:
Benchmark: timing 100 iterations of regex, substr, unpack...
 regex: 12.1695 wallclock secs (11.59 usr +  0.00 sys = 11.59 CPU) @
86303.62/s (n=100)
substr: 5.70029 wallclock secs ( 5.54 usr +  0.00 sys =  5.54 CPU) @
180603.21/s (n=100)
unpack: 10.2787 wallclock secs (10.13 usr +  0.00 sys = 10.13 CPU) @
98765.43/s (n=100)
Aug 29 2005

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: Date in perl

2005-09-29 Thread Jay Savage
On 8/27/05, Gomez, Juan [EMAIL PROTECTED] wrote:

 Hi all


 I have a problem need to work with date

 I have a input like these :   20050829 and I need to change it to something
 like this : Aug 29 2005

 but it still eludes me how to do that

 can anyone help me please?





 thanks


 Armando


Take a look at the Date::Manip module:

#!/usr/bin/perl

use warnings;
use strict;
use Date::Manip;

my $date = UnixDate(ParseDate(20050829), %b %e %Y);
print $date\n;

See perldoc Date::Manip for the details. Roll you own solutions are
faster for specific conversions, but if you're oging to be doing a lot
of date conversions, Date::Manip is your friend.

HTH,

-- jay
--
This email and attachment(s): [  ] blogable; [ x ] ask first; [  ]
private and confidential

daggerquill [at] gmail [dot] com
http://www.tuaw.com  http://www.dpguru.com  http://www.engatiki.org

values of β will give rise to dom!


RE: Date in perl

2005-09-29 Thread Wagner, David --- Senior Programmer Analyst --- WGO
Jay Savage wrote:
 On 8/27/05, Gomez, Juan [EMAIL PROTECTED] wrote:
 
 Hi all
 
 
 I have a problem need to work with date
 
 I have a input like these :   20050829 and I need to change it to
 something like this : Aug 29 2005 
 
 but it still eludes me how to do that
 
 can anyone help me please?
 
 
 
 
 
 thanks
 
 
 Armando
 
 
 Take a look at the Date::Manip module:
Understood, but quite a bit of routine for getting the date out in the 
format that Armando wants.  If he had alot of date manipultion, okay, but this 
the unapck and a simple array of month names would be much easy and alot less 
overhead.

Wags ;)
 
 #!/usr/bin/perl
 
 use warnings;
 use strict;
 use Date::Manip;
 
 my $date = UnixDate(ParseDate(20050829), %b %e %Y);
 print $date\n;
 
 See perldoc Date::Manip for the details. Roll you own solutions are
 faster for specific conversions, but if you're oging to be doing a lot
 of date conversions, Date::Manip is your friend.
 
 HTH,
 
 -- jay
 --
 This email and attachment(s): [  ] blogable; [ x ] ask first; [  ]
 private and confidential
 
 daggerquill [at] gmail [dot] com
 http://www.tuaw.com  http://www.dpguru.com  http://www.engatiki.org
 
 values of ? will give rise to dom!



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


--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




generating a wordlist from an array of arrays

2005-09-29 Thread mark berger
hey list. i stuck with gererating a wordlist from a changing
multidimensional array. each entry in the array contains a list with the
possible values.

fe:

@wordlayout = ((a, b),  # possible values for 1st char
   (c), # possible values for 2nd char
   (d, e, f));  # possible values for 3rd char

the following wordlist should be generated:

acd
ace
acf
bcd
bce
bcf

the only thing i came up with so far, is to generate some for loops
based on the array structure (how many chars, with how many posible
values) on fly and pass this to eval. pretty ugly (at least the way i
thought it out).

any hints on how to solve this? probably using recursion but i got no
idea about it right now. and sorry for my bad english, hope i can make
my problem understandable.

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




RE: generating a wordlist from an array of arrays

2005-09-29 Thread Hall, Scott
Mark,

I like to use glob for such tasks.  

perldoc -f glob 
perldoc File::Glob
bash-2.05b$ perl -le 'print for glob ({a,b}{c}{d,e,f})'
acd
ace
acf
bcd
bce
bcf

Regards,
Scott

PS: I apologize for the top post.

-Original Message-
From: mark berger [mailto:[EMAIL PROTECTED] 
Sent: Thursday, September 29, 2005 1:27 PM
To: beginners@perl.org
Subject: generating a wordlist from an array of arrays

hey list. i stuck with gererating a wordlist from a changing
multidimensional array. each entry in the array contains a list with the
possible values.

fe:

@wordlayout = ((a, b),  # possible values for 1st char
   (c), # possible values for 2nd char
   (d, e, f));  # possible values for 3rd char

the following wordlist should be generated:

acd
ace
acf
bcd
bce
bcf

the only thing i came up with so far, is to generate some for loops
based on the array structure (how many chars, with how many posible
values) on fly and pass this to eval. pretty ugly (at least the way i
thought it out).

any hints on how to solve this? probably using recursion but i got no
idea about it right now. and sorry for my bad english, hope i can make
my problem understandable.

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response



--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




compiling Storable in order to use Proc::ProcessTable

2005-09-29 Thread DBSMITH
As I am attempting to compile this module I am getting many errors on an
HPUX 11.11 64 bit machine.
Any help please ?

(See attached file: log)
thank you,


Derek B. Smith
OhioHealth IT
UNIX / TSM / EDM Teams


log
Description: Binary data
-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response


question on returning value

2005-09-29 Thread Helen Chen

Hi,

I am calling a perl script within matlab, and am trying to return the name of 
the file, which the perl script created to matlab. Is there a simple way to 
do it? 


Thanks
Helen


--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: compiling Storable in order to use Proc::ProcessTable

2005-09-29 Thread JupiterHost.Net



[EMAIL PROTECTED] wrote:

As I am attempting to compile this module I am getting many errors on an


this module as in Storable or Proc::ProcessTable ??

perl -MCPAN -e 'install Storable;' # your perl doesn't already have 
Storable???


perl -MCPAN -e 'install Proc::ProcessTable;'

Are you installing from CPAM, PPM, Source ???

What did your server admin find when he looked into those logs?

What errors have you been unable to understand or rectify (Speaking for 
myself, I can't take the time to sift through a huge error log, 
especially if you don't...)


Try to throw us a bone Derek :)

How many times have you posted and someone recommends ways to help 
people help you by posting smarter questions.


--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: a little help...

2005-09-29 Thread FamiLink Admin

David,
Thank you for your help!  I am trying to get this to work.  Can you tell me 
what my $MyIpAddrInfo = \%MIAI; does?  I am getting


HASH(0x8133528)

for $MyIpAddrInfo  if I print it out after the:

$MyIpAddrInfo-{$ip}++;


Ryan Lamberton


- Original Message - 
From: Wagner, David --- Senior Programmer Analyst --- WGO 
[EMAIL PROTECTED]

To: FamiLink Admin [EMAIL PROTECTED]
Cc: beginners@perl.org
Sent: Wednesday, September 28, 2005 5:53 PM
Subject: RE: a little help...


FamiLink Admin wrote:

I am only concerned about the IP.  The rest is just to verify the
data for now.  What code would I use to key the $IP in to hash for
counting?.  Most of the IP's are not static but are from broadband
and don't change too often.  An example log is:

-
[2005-09-28 10:05:03 -7:00] 127.0.0.1 71.32.59.249 216.163.137.3 -
http://www.playboy.com/ blocked 0 PO
-
 the IP I want to count is 71.32.59.249 (for this log) and the
category is PO


I would do something like:
my %MIAI = ();
my $MyIpAddrInfo = \%MIAI;
Now as you go through the scan loop, you would take the if which is doing 
the check on the $flag and the do something like $MyIpAddInfo-{$ip}++;

Now you complete your scan and then run throuh your loop like:

foreach $MyIpAddr (sort keys %{MyIpAddrInfo}) {
next if ( $MyIpAddrInfo-{MyIpAddr} = $blocklimit ); # if less than or 
equal get next key

# write your suspend and you could put together your email at the same time
}

A start.

Wags ;)


Ryan Lamberton


- Original Message -
From: Wagner, David --- Senior Programmer Analyst --- WGO
[EMAIL PROTECTED]
To: FamiLink Admin [EMAIL PROTECTED]
Cc: beginners@perl.org
Sent: Wednesday, September 28, 2005 5:18 PM
Subject: RE: a little help...


FamiLink Admin wrote:

Jeff ,
Thanks for all your help!  This is what I have now (below and this
time the whole thing):   I think I have included all that you talked
about plus others:

The sub scanlog does write the information to the files but it does
not return anything back to the main program and I also get the
error:

Use of uninitialized value in split at ./test.pl line 9.

Also, is there a better way of counting the number of times each IP
address gets blocked with category PO?   Each time I get to the
blocklimit it writes to the file but I really just want the max
number of blocks over the limit. It will write the same IP each time
it gets over the blocklimit though.



If you are only concerned about $ip and if they went over that limit
and not desiring the detail of said offense, then you could use the
$ip as a key into a hash. Then you could count all the occurances. At
the conclusion of that processing then you could loop through the
hash and any count greater than your max, then you could write to the
suspend file.  For email, then could again use the hash to put
together a list of $ip's that are over your limit.

I have not followed the topic, but unless you do something with the
$ip, I would assume that the log is just that a log. You would have
interspersed $ip and so I am unsure how you would be able to say $ip
is at fault. I see nothing in your code which isolates to the $ip.
Again, are these static ip addr or when someone logs out, they are
ready for use by someone else.  If it is released then you have to
figure out when this occurs to get an accurate rcd. If static, then
not a problem.

Wags ;)




--
#!/usr/bin/perl -w require Mail::Send;
$|=1;   # no buffering
use constant IP_LIST_FILE = /etc/squid/iplist.txt;
use constant SUSPEND_FILE = /etc/squid/SuspendIpList.txt;
use constant LOG_FILE = /opt/n2h2/logs/filter_log;
my $sysop = [EMAIL PROTECTED];
my $flag = PO;
my $hour = (split, localtime)[2];
my $blocklimit = 5;
my $matches = 0;
my $matched = 0;
{
($matched,$ip,$hour,$time,$category,$url) =
Scanlog($flag,$hour,$blocklimit,$matches,);
if($matched  $blocklimit){
  $msg = new Mail::Send Subject='SuspendIpList',
  To=$sysop; $fh = $msg-open;
  print $fh Someone has tried to access $matches banned
  sites today\n; print $fh Their IP address ($ip) has been
added to /etc/squid/SuspendIpList.txt\n;
  print $fh To unblock them, remove their entry from the
file and run squid -k reconfigure\n;
  print $fh $matches, $ip, $hour, $time, $category, $url\n;
  $fh-close; # complete the message and send it
   $matched = 0; }
else{
open my $output2, , SUSPEND_FILE or die Can't write
 @{[SUSPEND_FILE]}: $!; print $output2 10.0.0.252/32\n;
close $output2;
   }
}
sub Scanlog {
my ($flag,$hour,$blocklimit,$matches,)[EMAIL PROTECTED];
open my $slog, -|, tail -n 25000  @{[LOG_FILE]} or die
Unable to open $log:$!\n; open my $output, ,
IP_LIST_FILE or die Can't write @{[IP_LIST_FILE]}: $!;
open my $output2, , SUSPEND_FILE or die Can't write
 

Re: generating a wordlist from an array of arrays

2005-09-29 Thread Jeff 'japhy' Pinyan

On Sep 29, mark berger said:


hey list. i stuck with gererating a wordlist from a changing
multidimensional array. each entry in the array contains a list with the
possible values.


You want a cartesian cross product.  And there's a module out there that 
does just that:  Set::CrossProduct.


  http://search.cpan.org/~bdfoy/Set-CrossProduct-1.6/CrossProduct.pm

Sample use:

  use Set::CrossProduct;

  my $iterator = Set::CrossProduct-new(['a','b'],['c'],['d','e','f']);

  my @wordlayout = $iterator-combinations;

@wordlayout will be an array of array references (like ['a','c','f']).  To 
turn them into strings, you could do:


  my @wordlayout = map join(, @$_), $iterator-combinations;


any hints on how to solve this? probably using recursion but i got no
idea about it right now. and sorry for my bad english, hope i can make
my problem understandable.


It would be a fun exercise to do this on your own, and yes, recursion is 
the most obvious way to do it.


--
Jeff japhy Pinyan%  How can we ever be the sold short or
RPI Acacia Brother #734%  the cheated, we who for every service
http://www.perlmonks.org/  %  have long ago been overpaid?
http://princeton.pm.org/   %-- Meister Eckhart

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




RE: a little help...

2005-09-29 Thread Wagner, David --- Senior Programmer Analyst --- WGO
FamiLink Admin wrote:
 David,
 Thank you for your help!  I am trying to get this to work.  Can you
 tell me what my $MyIpAddrInfo = \%MIAI; does?  I am getting
This is making $MyIpAddInfo a refeence to %MIAI so to access the data 
you use the - as the connector vs $MIAI{}.

 
 HASH(0x8133528)
 
 for $MyIpAddrInfo  if I print it out after the:
Since you have only given me this, it should be and I looked at whait i 
sent you:

foreach $MyIpAddr (sort keys %{MyIpAddrInfo}) {
next if ( $MyIpAddrInfo-{MyIpAddr} = $blocklimit ); # if less than or 
equal get next key

the best way to see what you have is using Data::Dumper. 
Add a use Data::Dumper at top of script.
I then would add at a high level:
$Data::Dumper::Sortkeys = 1;# sort the keys when printing.

Then you can do something like:

print Dumper(\%{$MyIpAddrInfo});# in thise case will go to std out.  if 
a lot of data, then open a disk file and write to that.
Also you can before the print place this line:
$Data::Dumper::Varname = 'MyIpAddrInfo';# this is name will appear at 
the beginning of the output
print Dumper(\%{$MyIpAddrInfo});# in thise case will go to std out.  
# if a lot of data, then open a 
disk file and write to
Wags ;)
 
 $MyIpAddrInfo-{$ip}++;
 
 
 Ryan Lamberton
 
 
 - Original Message -
 From: Wagner, David --- Senior Programmer Analyst --- WGO
 [EMAIL PROTECTED]
 To: FamiLink Admin [EMAIL PROTECTED]
 Cc: beginners@perl.org
 Sent: Wednesday, September 28, 2005 5:53 PM
 Subject: RE: a little help...
 
 
 FamiLink Admin wrote:
 I am only concerned about the IP.  The rest is just to verify the
 data for now.  What code would I use to key the $IP in to hash for
 counting?.  Most of the IP's are not static but are from broadband
 and don't change too often.  An example log is:
 
 -
 [2005-09-28 10:05:03 -7:00] 127.0.0.1 71.32.59.249 216.163.137.3 -
 http://www.playboy.com/ blocked 0 PO
 -
  the IP I want to count is 71.32.59.249 (for this log) and the
 category is PO 
 
 I would do something like:
 my %MIAI = ();
 my $MyIpAddrInfo = \%MIAI;
 Now as you go through the scan loop, you would take the if which is
 doing the check on the $flag and the do something like
 $MyIpAddInfo-{$ip}++; Now you complete your scan and then run throuh
 your loop like: 
 
 foreach $MyIpAddr (sort keys %{MyIpAddrInfo}) {
 next if ( $MyIpAddrInfo-{MyIpAddr} = $blocklimit ); # if less than
 or equal get next key
 # write your suspend and you could put together your email at the
 same time }
 
 A start.
 
 Wags ;)
 
 Ryan Lamberton
 
 
 - Original Message -
 From: Wagner, David --- Senior Programmer Analyst --- WGO
 [EMAIL PROTECTED]
 To: FamiLink Admin [EMAIL PROTECTED]
 Cc: beginners@perl.org
 Sent: Wednesday, September 28, 2005 5:18 PM
 Subject: RE: a little help...
 
 
 FamiLink Admin wrote:
 Jeff ,
 Thanks for all your help!  This is what I have now (below and this
 time the whole thing):   I think I have included all that you
 talked about plus others: 
 
 The sub scanlog does write the information to the files but it does
 not return anything back to the main program and I also get the
 error: 
 
 Use of uninitialized value in split at ./test.pl line 9.
 
 Also, is there a better way of counting the number of times each IP
 address gets blocked with category PO?   Each time I get to the
 blocklimit it writes to the file but I really just want the max
 number of blocks over the limit. It will write the same IP each time
 it gets over the blocklimit though.
 
 
 If you are only concerned about $ip and if they went over that limit
 and not desiring the detail of said offense, then you could use the
 $ip as a key into a hash. Then you could count all the occurances. At
 the conclusion of that processing then you could loop through the
 hash and any count greater than your max, then you could write to the
 suspend file.  For email, then could again use the hash to put
 together a list of $ip's that are over your limit.
 
 I have not followed the topic, but unless you do something with the
 $ip, I would assume that the log is just that a log. You would have
 interspersed $ip and so I am unsure how you would be able to say $ip
 is at fault. I see nothing in your code which isolates to the $ip.
 Again, are these static ip addr or when someone logs out, they are
 ready for use by someone else.  If it is released then you have to
 figure out when this occurs to get an accurate rcd. If static, then
 not a problem. 
 
 Wags ;)
 
 
 
 --
 #!/usr/bin/perl -w require Mail::Send;
 $|=1;   # no buffering
 use constant IP_LIST_FILE = /etc/squid/iplist.txt;
 use constant SUSPEND_FILE = /etc/squid/SuspendIpList.txt;
 use constant LOG_FILE = /opt/n2h2/logs/filter_log;
 my $sysop = [EMAIL PROTECTED];
 my $flag = PO;
 my $hour = (split, localtime)[2];
 my 

RE: a little help...

2005-09-29 Thread Timothy Johnson

my $MyIpAddrInfo = \%MIAI; makes $MyIpAddrInfo a reference to the
%MIAI hash.  That is why you can't print it directly.

If you want to treat $MyIpAddrInfo like the hash it refers to, you have
to dereference it by prefacing it with the '%' (see example below).  The
brackets are usually optional, but some people like me just use them all
the time to avoid certain problems with more complicated data
structures.

my @keys = sort keys %{$MyIpAddrInfo};

You can also indirectly access the members of the hash by using the -
operator, so:

   $MyIpAddrInfo-{ip}

is the same as

   ${$MyIpAddrInfo}{ip}

is the same as

   $MIAI{ip}



-Original Message-
From: FamiLink Admin [mailto:[EMAIL PROTECTED] 
Sent: Saturday, October 01, 2005 3:04 PM
To: Wagner, David --- Senior Programmer Analyst --- WGO
Cc: beginners@perl.org
Subject: Re: a little help...

David,
Thank you for your help!  I am trying to get this to work.  Can you tell
me 
what my $MyIpAddrInfo = \%MIAI; does?  I am getting

HASH(0x8133528)

for $MyIpAddrInfo  if I print it out after the:

$MyIpAddrInfo-{$ip}++;


Ryan Lamberton

snip


--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: generating a wordlist from an array of arrays

2005-09-29 Thread Gerard Robin
On Thu, Sep 29, 2005 at 07:26:51PM +0200 mark berger wrote:
 hey list. i stuck with gererating a wordlist from a changing
 multidimensional array. each entry in the array contains a list with the
 possible values.
 
 fe:
 
 @wordlayout = ((a, b),# possible values for 1st char
(c),   # possible values for 2nd char
(d, e, f));# possible values for 3rd char
 
 the following wordlist should be generated:
 
 acd
 ace
 acf
 bcd
 bce
 bcf

use references for multidimensional arrays:

#!/usr/bin/perl

use warnings;

@w1 = ([a, b], [c], [d, e, f]);

$str =;

foreach $k (@{$w1[0]}) {

  foreach $l (@{$w1[2]}) {

$str = [EMAIL PROTECTED] ;
  }
}

@w2 = split  , $str;

foreach (@w2) {

print $_\n;
}

it's another solution  ...

hth

-- 
Gérard 


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: a little help...

2005-09-29 Thread FamiLink Admin

That works!  Now I see data!

$VAR1 = {
 '70.117.26.250' = '1'
   };
$VAR1 = {
 '70.117.26.250' = '1',
 '71.32.59.249' = '1'
   };
$VAR1 = {
 '70.117.26.250' = '1',
 '71.32.59.249' = '2'
   };
$VAR1 = {
 '70.117.26.250' = '1',
 '71.32.59.249' = '3'
   };


The foreach loop does not seem to work and I get this error:

Name main::MyIpAddrInfo used only once: possible typo at ./test2.pl line 
48.


-
#!/usr/bin/perl -w
require Mail::Send;
use Data::Dumper;
use constant IP_LIST1_FILE = /etc/squid/iplist1.txt;
use constant IP_LIST_FILE = /etc/squid/iplist.txt;
use constant SUSPEND_FILE = /etc/squid/SuspendIpList.txt;
use constant LOG_FILE = /opt/n2h2/logs/filter_log;
{
my $sysop = [EMAIL PROTECTED];
my $flag = PO;
my $hour = (localtime)[2];
my $matches = 0;
   my ($matched,$ip2) = Scanlog($flag,$hour,$matches);
   if($matched  1){
 $msg = new Mail::Send Subject='SuspendIpList', To=$sysop;
 $fh = $msg-open;
 print $fh Someone has tried to access $matched banned sites 
today\n;
 print $fh Their IP address ($ip2) has been added to 
/etc/squid/SuspendIpList.txt\n;
 print $fh To unblock them, remove their entry from the file and 
run squid -k reconfigure\n;

 print $fh $matched, $ip2\n;
 $fh-close; # complete the message and send it
 $matched = 0;
  }
   else{
   open my $output2, , SUSPEND_FILE or die Can't write 
@{[SUSPEND_FILE]}: $!;

print $output2 10.0.0.252/32\n;
   close $output2;
  }
}
sub Scanlog {
   my ($flag,$hour,$matches)[EMAIL PROTECTED];
   my $blocklimit = 1;
   $matched = 0;
   open my $slog, -|, tail -n 25000  @{[LOG_FILE]} or die Unable 
to open  @{[LOG_FILE]}: $!;
   open my $output, , IP_LIST_FILE or die Can't write 
@{[IP_LIST_FILE]}: $!;
   open my $output1, , IP_LIST1_FILE or die Can't write 
@{[IP_LIST1_FILE]}: $!;
   open my $output2, , SUSPEND_FILE or die Can't write 
@{[SUSPEND_FILE]}: $!;

   my %MIAI = ();
   my $MyIpAddrInfo = \%MIAI;
   while (my $line = $slog){ # assigns each line in turn to $line
  #use an array slice to select the fields we want
  my ($time, $ip, $url, $category) = (split  , $line)[1,4,7,10];
  my ($hr) = split /:/, $time;
if($flag eq $category and $hr eq $hour){
   $MyIpAddrInfo-{$ip}++;
   print $output Dumper(\%{$MyIpAddrInfo});
}
foreach $MyIpAddr (sort keys %{MyIpAddrInfo}) {
   next if ( $MyIpAddrInfo-{MyIpAddr} = $blocklimit ); # if 
less than or equal get next key

   print $output1 Dumper(\%{$MyIpAddrInfo});
   print $output2 $ip/32\n;
   $matched = $matches;
   $matches = 0;
   $ip2 = $ip;
}
   }
   close $output;
   close $output2;
   return $matched,$ip2;
}




Ryan Lamberton


- Original Message - 
From: Wagner, David --- Senior Programmer Analyst --- WGO 
[EMAIL PROTECTED]

To: FamiLink Admin [EMAIL PROTECTED]
Cc: beginners@perl.org
Sent: Thursday, September 29, 2005 3:15 PM
Subject: RE: a little help...


FamiLink Admin wrote:

David,
Thank you for your help!  I am trying to get this to work.  Can you
tell me what my $MyIpAddrInfo = \%MIAI; does?  I am getting
This is making $MyIpAddInfo a refeence to %MIAI so to access the data you 
use the - as the connector vs $MIAI{}.




HASH(0x8133528)

for $MyIpAddrInfo  if I print it out after the:
Since you have only given me this, it should be and I looked at whait i sent 
you:


foreach $MyIpAddr (sort keys %{MyIpAddrInfo}) {
next if ( $MyIpAddrInfo-{MyIpAddr} = $blocklimit ); # if less than or 
equal get next key


the best way to see what you have is using Data::Dumper.
Add a use Data::Dumper at top of script.
I then would add at a high level:
$Data::Dumper::Sortkeys = 1; # sort the keys when printing.

Then you can do something like:

print Dumper(\%{$MyIpAddrInfo}); # in thise case will go to std out.  if a 
lot of data, then open a disk file and write to that.

Also you can before the print place this line:
$Data::Dumper::Varname = 'MyIpAddrInfo'; # this is name will appear at the 
beginning of the output

print Dumper(\%{$MyIpAddrInfo}); # in thise case will go to std out.
# if a lot of data, then open a disk file and write to
Wags ;)


$MyIpAddrInfo-{$ip}++;


Ryan Lamberton


- Original Message -
From: Wagner, David --- Senior Programmer Analyst --- WGO
[EMAIL PROTECTED]
To: FamiLink Admin [EMAIL PROTECTED]
Cc: beginners@perl.org
Sent: Wednesday, September 28, 2005 5:53 PM
Subject: RE: a little help...


FamiLink Admin wrote:

I am only concerned about the IP.  The rest is just to verify the
data for now.  What code would I use to key the $IP in to 

RE: a little help...

2005-09-29 Thread Wagner, David --- Senior Programmer Analyst --- WGO
FamiLink Admin wrote:
 That works!  Now I see data!
 
 $VAR1 = {
   '70.117.26.250' = '1'
 };
 $VAR1 = {
   '70.117.26.250' = '1',
   '71.32.59.249' = '1'
 };
 $VAR1 = {
   '70.117.26.250' = '1',
   '71.32.59.249' = '2'
 };
 $VAR1 = {
   '70.117.26.250' = '1',
   '71.32.59.249' = '3'
 };
 
 
 The foreach loop does not seem to work and I get this error:
You are not using strict, so it is working and this is just informative.
What you are missing is that you collect all the data first which meets your 
criteria. At the end of that processing, then you go through the foreach 
checking. You have to be on the outside of the whlle loop:

while (my $line = $slog){ # assigns each line in turn to $line
   #use an array slice to select the fields we want
   my ($time, $ip, $url, $category) = (split  , $line)[1,4,7,10];
   my ($hr) = split /:/, $time;
 if($flag eq $category and $hr eq $hour){
$MyIpAddrInfo-{$ip}++;
 }
}
   foreach $MyIpAddr (sort keys %{MyIpAddrInfo}) {
  next if ( $MyIpAddrInfo-{MyIpAddr} = $blocklimit ); # if less than 
or equal get next key
  print $output2 $ip/32\n;
   }
  print $output1 Dumper(\%{$MyIpAddrInfo});
  close $output;
Something along this line as a starter.

You should get use to using strict and warnings.  Makes life much easier if you 
get started that way.

Wags ;)   

 
 Name main::MyIpAddrInfo used only once: possible typo at ./test2.pl
 line 
 48.
 
 -
 #!/usr/bin/perl -w
 require Mail::Send;
 use Data::Dumper;
 use constant IP_LIST1_FILE = /etc/squid/iplist1.txt;
 use constant IP_LIST_FILE = /etc/squid/iplist.txt;
 use constant SUSPEND_FILE = /etc/squid/SuspendIpList.txt;
 use constant LOG_FILE = /opt/n2h2/logs/filter_log;
 {
 my $sysop = [EMAIL PROTECTED];
 my $flag = PO;
 my $hour = (localtime)[2];
 my $matches = 0;
 my ($matched,$ip2) = Scanlog($flag,$hour,$matches);
 if($matched  1){
   $msg = new Mail::Send Subject='SuspendIpList',
   To=$sysop; $fh = $msg-open;
   print $fh Someone has tried to access $matched banned sites
 today\n;
   print $fh Their IP address ($ip2) has been added to
 /etc/squid/SuspendIpList.txt\n;
   print $fh To unblock them, remove their entry from the
 file and run squid -k reconfigure\n;
   print $fh $matched, $ip2\n;
   $fh-close; # complete the message and send it
   $matched = 0;
}
 else{
 open my $output2, , SUSPEND_FILE or die Can't write
 @{[SUSPEND_FILE]}: $!;
  print $output2 10.0.0.252/32\n;
 close $output2;
}
 }
 sub Scanlog {
 my ($flag,$hour,$matches)[EMAIL PROTECTED];
 my $blocklimit = 1;
 $matched = 0;
 open my $slog, -|, tail -n 25000  @{[LOG_FILE]} or die
 Unable to open  @{[LOG_FILE]}: $!;
 open my $output, , IP_LIST_FILE or die Can't write
 @{[IP_LIST_FILE]}: $!;
 open my $output1, , IP_LIST1_FILE or die Can't write
 @{[IP_LIST1_FILE]}: $!;
 open my $output2, , SUSPEND_FILE or die Can't write
 @{[SUSPEND_FILE]}: $!;
 my %MIAI = ();
 my $MyIpAddrInfo = \%MIAI;
 while (my $line = $slog){ # assigns each line in turn
to $line #use an array slice to select the fields we want
my ($time, $ip, $url, $category) = (split  ,
$line)[1,4,7,10]; my ($hr) = split /:/, $time;
  if($flag eq $category and $hr eq $hour){
 $MyIpAddrInfo-{$ip}++;
 print $output Dumper(\%{$MyIpAddrInfo});
  }
  foreach $MyIpAddr (sort keys %{MyIpAddrInfo}) {
 next if ( $MyIpAddrInfo-{MyIpAddr} = $blocklimit );
 # if less than or equal get next key
 print $output1 Dumper(\%{$MyIpAddrInfo});
 print $output2 $ip/32\n;
 $matched = $matches;
 $matches = 0;
 $ip2 = $ip;
  }
 }
 close $output;
 close $output2;
 return $matched,$ip2;
 }
 
 
 
 
 Ryan Lamberton
 
 
 - Original Message -
 From: Wagner, David --- Senior Programmer Analyst --- WGO
 [EMAIL PROTECTED]
 To: FamiLink Admin [EMAIL PROTECTED]
 Cc: beginners@perl.org
 Sent: Thursday, September 29, 2005 3:15 PM
 Subject: RE: a little help...
 
 
 FamiLink Admin wrote:
 David,
 Thank you for your help!  I am trying to get this to work.  Can you
 tell me what my $MyIpAddrInfo = \%MIAI; does?  I am getting
 This is making $MyIpAddInfo a refeence to %MIAI so to access the data
 you use the - as the connector vs $MIAI{}.
 
 
 HASH(0x8133528)
 
 for $MyIpAddrInfo  if I print it out after the:
 Since you have only