Re: What is the best way to set options in a constructor

2003-10-24 Thread R. Joseph Newton
Steve Grazzini wrote:

> On Thu, Oct 23, 2003 at 06:48:29AM -0700, R. Joseph Newton wrote:
> > "Randal L. Schwartz" wrote:
> > > > "Dan" == Dan Anderson <[EMAIL PROTECTED]> writes:
> > >
> > > Dan>   my $class = ref($proto) || $proto;
> > >
> > > Don't do this!
> >
> > I'm still a little mystified as to what you find offensive there.
>
> [snip]
>
> > I'll grant that I have sometimes felt silly having that construct in a root
> > class, but so far it has not done any actual damage.
>
> There are two things going on --
>
> First, the constructor is taking the classname from the first argument,
> like this:
>
> sub new {
>   my $class = shift;
>   my $self = { initial => 'data' };
>   bless $self, $class;
> }
>
> There's nothing wrong with that, and in fact it's *necessary* if a derived
> class wants to inherit the new() method from Foo.  So don't feel silly about
> using "my $class = shift" in a root class!  That's where you really need to
> be using it.
>
> But the constructor is also prepared to take an object as the first argument
> instead of just the classname-as-a-string.  This is explained in perltoot:
>
> While we're at it, let's make our constructor a bit more flexible.
> Rather than being uniquely a class method, we'll set it up so that it
> can be called as either a class method or an object method.  That way
> you can say:
>
> $me  = Person->new();
> $him = $me->new();

Okay, I just found out where I got confused.  I've never read perltoot, but I
skipped over a couple paragraphs, actually a code sample and a paragraph, in
reading perlobj:

If you care about inheritance (and you should; see the section on
"Modules: Creation, Use, and Abuse" in the perlmodlib manpage), then you
want to use the two-arg form of bless so that your constructors may be
inherited:
[glossed over this:
sub new {
my $class = shift;
my $self = {};
bless $self, $class;
$self->initialize();
return $self;
}

Or if you expect people to call not just "CLASS->new()" but also
"$obj->new()", then use something like this. The initialize() method
used will be of whatever $class we blessed the object into:
...and connected the text above to the code sample below]

sub new {
my $this = shift;
my $class = ref($this) || $this;
my $self = {};
bless $self, $class;
$self->initialize();
return $self;
}


I must say that it makes much more sense reading this way.  The construct is now
much less mysterious, too.

Thanks,

Joseph


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



Passing and returning values from another script?

2003-10-24 Thread Mark Weisman









I would like to encrypt textbox provided passwords. I have
a script that I found on the web, and it asks that I call the script and
provide the word afterwards (i.e. ./scriptname.pl password). The script then
provides me the encrypted password to the screen. I am wondering how I can pass
that password to the script, and get the output value back into my other
script? Can someone help?

 



Sincerely in Christ,

Mark-Nathaniel
Weisman

President / Owner

Outland Domain Group

Anchorage, Alaska



 






<>

Re: What is the best way to set options in a constructor

2003-10-24 Thread R. Joseph Newton
Wiggins d Anconia wrote:

>
> my $new_obj = ref($obj)->new;

Ouch!  Unfortunately, I can well imagine someone trying to use that, too.

> I do have to differ with the opinion about new, if you really are just
> constructing an object then to me it still makes sense as a name, but in
> the case of DBI you are constructing an object *and* performing an
> action, so the 'connect' name makes sense. To me it would also make
> sense if there was (and maybe there is):
>
> my $dbi = new DBI;
> my $dbh = $dbi->connect;
>
> Because in this case you are *just* constructing an object, and then
> *just* connecting...  But this assumes you throw out the history of the
> corruption of the name 'new' both as a cloning method and as "let's do
> more than just create an object, lets also connect to a server, read a
> file, etc." which somehow I don't think Randal will let us ;-) (and he
> probably is right not to)

I agree [I think ;-)]  For creating a new object, the only way I would use it,
new makes sense.

Even for cloning, it can be used without the kind of confusion that Randal
refers to:
package MyObject;

use strict;
use warnings;

use Exporter;

sub new {
   my $class = shift;   # point taken

   my $self = {};
   bless $self, $class;
   if ($_[0] && $_[0]->isa($class) ) {
  my $source = $_[0];
  $self->{$_} = $source->{$_} for keys %$source;
   }else {
  $self->initialize(@_);
   }
   return $self;
}

sub initialize {
  my $self = shift;
  my %source = @_;
  $self->{$_} = $source{$_} foreach keys %source;
}
1;

Greetings! E:\d_drive\perlStuff>perl -w -MMyObject
my $obj = MyObject->new qw(first 1 second 2);
print $obj, "\n";
print "Yes\n" if $obj->isa(MyObject);
print "$_: $obj->{$_}\n" for keys %$obj;
my $obj2 = MyObject->new($obj);
print $obj2, "\n";
print "Yes\n" if $obj2->isa(MyObject);
print "$_: $obj2->{$_}\n" for keys %$obj2;
^Z
MyObject=HASH(0x15d55ec)
Yes
first: 1
second: 2
MyObject=HASH(0x1a876d4)
Yes
first: 1
second: 2



Joseph


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



CGI::Session param help

2003-10-24 Thread perl
Can someone tell me how to delete a parameter in $session->param("BOGUS")
that was set?

$session->param("BOGUS", "hello");

Does this actually removes or just set a null value?

$session->("BOGUS", undef);

I want to remove or delete it completely.

-thanks


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

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



RE: Passing and returning values from another script?

2003-10-24 Thread Marcos . Rebelo
I'm not sure but
 
open (SCRIPT, "./scriptname.pl password|");
my $output = join("", SCRIPT);
close SCRIPT
 
shall work;

-Original Message-
From: Mark Weisman [mailto:[EMAIL PROTECTED]
Sent: Friday, October 24, 2003 9:53 AM
To: [EMAIL PROTECTED]
Subject: Passing and returning values from another script?


 

I would like to encrypt textbox provided passwords. I have a script that I
found on the web, and it asks that I call the script and provide the word
afterwards (i.e. ./scriptname.pl password). The script then provides me the
encrypted password to the screen. I am wondering how I can pass that
password to the script, and get the output value back into my other script?
Can someone help?

 

Sincerely in Christ,

Mark-Nathaniel Weisman

President / Owner

Outland Domain Group

Anchorage, Alaska

 

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

comparison between two regexes?

2003-10-24 Thread David Garamond
Given two regex patterns R1 and R2, is it possible at all to 
determine/calculate:

- whether R1 is "a subset of" R2, i.e. all strings that match R1 will 
also always match R2, but not necessarily the other way around;

- whether R1 is "equivalent" or "equal" to R2, i.e. all strings that 
match R1 will also always match R2, and all strings that match R2 will 
also always match R1.

- whether R1 does not "intersect" R2, i.e. no string can match both R1 
and R2 at the same time, a string can match either R1 or R2 but never both.

--
dave


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


Re: comparison between two regexes?

2003-10-24 Thread David Garamond
I wrote:
Given two regex patterns R1 and R2, is it possible at all to 
determine/calculate:

- whether R1 is "a subset of" R2, i.e. all strings that match R1 will 
also always match R2, but not necessarily the other way around;

- whether R1 is "equivalent" or "equal" to R2, i.e. all strings that 
match R1 will also always match R2, and all strings that match R2 will 
also always match R1.

- whether R1 does not "intersect" R2, i.e. no string can match both R1 
and R2 at the same time, a string can match either R1 or R2 but never both.
Hm, after browsing a bit, I found this:

 http://www.mail-archive.com/[EMAIL PROTECTED]/msg00233.html

Come to think of it, the difficulty of the problem is comparable to 
determining whether two computer programs are equivalent to each other 
(i.e. given the same input, it will always generate the same output).

Oh well...

--
dave


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


Re: CGI::Session param help

2003-10-24 Thread Jeff 'japhy' Pinyan
On Oct 24, [EMAIL PROTECTED] said:

>Can someone tell me how to delete a parameter in $session->param("BOGUS")
>that was set?

  $session->delete("BOGUS");

Read 'perldoc CGI' for more details.

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


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



Re: comparison between two regexes?

2003-10-24 Thread Jeff 'japhy' Pinyan
On Oct 24, David Garamond said:

>- whether R1 is "a subset of" R2, i.e. all strings that match R1 will
>also always match R2, but not necessarily the other way around;
>
>- whether R1 is "equivalent" or "equal" to R2, i.e. all strings that
>match R1 will also always match R2, and all strings that match R2 will
>also always match R1.
>
>- whether R1 does not "intersect" R2, i.e. no string can match both R1
>and R2 at the same time, a string can match either R1 or R2 but never both.

I'm taking a course at RPI right now called "models of computation".  It's
basically working with NFAs and DFAs and push-down automata and Turing
machines and the like.  There is probably a way to determine if DFAs and
NFAs are a subset of each other, or equivalent, or don't intersect.  But I
don't think the same can be said for Perl's regexes.  They're not regular.

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


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



Visual Perl

2003-10-24 Thread Ned Cunningham
Hi Gurus,

I just finished up with a Perl program using Win32::Console on a Windoze NT system, 
Perl ver 5.6.1.

I was wondering why with all the power of Perl, and all the functionality it has, why 
I cant make a pretty input window?

Also, Does anyone use Visual Perl?  What does it offer if any, in these type of 
programs.

TIA


Ned Cunningham
POS Systems Development
Monro Muffler Brake
200 Holleder Parkway
Rochester, NY 14615
(585) 647-6400 ext. 310
[EMAIL PROTECTED]

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



RE: Visual Perl

2003-10-24 Thread Victor Medrano
I'm Really interesting in this software , let me know if you find
A visual perl .

Regards

-Original Message-
From: Ned Cunningham [mailto:[EMAIL PROTECTED] 
Sent: Friday, October 24, 2003 12:00 PM
To: [EMAIL PROTECTED]
Subject: Visual Perl


Hi Gurus,

I just finished up with a Perl program using Win32::Console on a Windoze
NT system, Perl ver 5.6.1.

I was wondering why with all the power of Perl, and all the
functionality it has, why I cant make a pretty input window?

Also, Does anyone use Visual Perl?  What does it offer if any, in these
type of programs.

TIA


Ned Cunningham
POS Systems Development
Monro Muffler Brake
200 Holleder Parkway
Rochester, NY 14615
(585) 647-6400 ext. 310
[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: Visual Perl

2003-10-24 Thread Bob Showalter
Ned Cunningham wrote:
> Hi Gurus,
> 
> I just finished up with a Perl program using Win32::Console
> on a Windoze NT system, Perl ver 5.6.1.
> 
> I was wondering why with all the power of Perl, and all the
> functionality it has, why I cant make a pretty input window?

What's a pretty input window?

Anyway, the Perl/Tk modules come by default with ActivePerl and let you
create nice clicky-GUI thingies. Those applications have the benefit of
being cross-platform, too.

Here's a place to start: http://www.perltk.org/articles/pm1.htm

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



RE: Visual Perl

2003-10-24 Thread NIPP, SCOTT V (SBCSI)
You are looking for the TK module for Perl.  Perl/TK allows you to
create windows and everything that goes along with them.


Scott Nipp
Phone:  (214) 858-1289
E-mail:  [EMAIL PROTECTED]
Web:  http:\\ldsa.sbcld.sbc.com



-Original Message-
From: Ned Cunningham [mailto:[EMAIL PROTECTED] 
Sent: Friday, October 24, 2003 11:00 AM
To: [EMAIL PROTECTED]
Subject: Visual Perl


Hi Gurus,

I just finished up with a Perl program using Win32::Console on a Windoze NT
system, Perl ver 5.6.1.

I was wondering why with all the power of Perl, and all the functionality it
has, why I cant make a pretty input window?

Also, Does anyone use Visual Perl?  What does it offer if any, in these type
of programs.

TIA


Ned Cunningham
POS Systems Development
Monro Muffler Brake
200 Holleder Parkway
Rochester, NY 14615
(585) 647-6400 ext. 310
[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: Visual Perl

2003-10-24 Thread Ned Cunningham
Oh cool.

Sorry to ask more help, but I must.

What module should I donwload?  Tk does not come with the standard Active Perl load.

If I make an executable with perlapp, would I need TK loaded on the target system?  

TIAA

Ned Cunningham
POS Systems Development
Monro Muffler Brake
200 Holleder Parkway
Rochester, NY 14615
(585) 647-6400 ext. 310
[EMAIL PROTECTED]

-Original Message-
From:   Bob Showalter [mailto:[EMAIL PROTECTED]
Sent:   Friday, October 24, 2003 12:10 PM
To: Ned Cunningham; [EMAIL PROTECTED]
Subject:RE: Visual Perl

Ned Cunningham wrote:
> Hi Gurus,
> 
> I just finished up with a Perl program using Win32::Console
> on a Windoze NT system, Perl ver 5.6.1.
> 
> I was wondering why with all the power of Perl, and all the
> functionality it has, why I cant make a pretty input window?

What's a pretty input window?

Anyway, the Perl/Tk modules come by default with ActivePerl and let you
create nice clicky-GUI thingies. Those applications have the benefit of
being cross-platform, too.

Here's a place to start: http://www.perltk.org/articles/pm1.htm

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



Re: Visual Perl

2003-10-24 Thread R. Joseph Newton
Ned Cunningham wrote:

> Hi Gurus,
>
> I just finished up with a Perl program using Win32::Console on a Windoze NT system, 
> Perl ver 5.6.1.
>
> I was wondering why with all the power of Perl, and all the functionality it has, 
> why I cant make a pretty input window?

You wonderment has a fallacious premise.  You can.  You just have to use the right 
module or Toolkit.  Consoles are not
meant to be pretty.  Use Tk.

ppm> install Tk

Joseph




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



Rename a file

2003-10-24 Thread Chinku Simon
Hi,

Is there any inbuilt command by which we can rename a file (in WinNT)

Regards,
Chinku

__
Do you Yahoo!?
The New Yahoo! Shopping - with improved product search
http://shopping.yahoo.com

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



RE: Rename a file

2003-10-24 Thread Tim Johnson

Yes.  There is a function called rename that will do just that.  Go to a
command prompt and type:

C:\> perldoc -f rename



-Original Message-
From: Chinku Simon [mailto:[EMAIL PROTECTED] 
Sent: Friday, October 24, 2003 9:55 AM
To: [EMAIL PROTECTED]
Subject: Rename a file


Hi,

Is there any inbuilt command by which we can rename a file (in WinNT)

Regards,
Chinku

__
Do you Yahoo!?
The New Yahoo! Shopping - with improved product search
http://shopping.yahoo.com

-- 
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: Rename a file

2003-10-24 Thread Casey West
It was Friday, October 24, 2003 when Chinku Simon took the soap box, saying:
: Hi,
: 
: Is there any inbuilt command by which we can rename a file (in WinNT)

Hi there.  I'd give the rename() function a shot.  :-)

perldoc -f rename

   rename OLDNAME,NEWNAME
   Changes the name of a file; an existing file NEWNAME will
   be clobbered. Returns true for success, false otherwise.

   Behavior of this function varies wildly depending on your
   sys- tem implementation. For example, it will usually not
   work across file system boundaries, even though the
   system mv com- mand sometimes compensates for this. Other
   restrictions include whether it works on directories,
   open files, or pre- existing files. Check perlport and
   either the rename(2) man- page or equivalent system
   documentation for details.


  Casey West

-- 
Good Idea: Visiting picturesque McLean, Virginia.
Bad Idea:  Visiting picturesque McLean Stevenson. 


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



RE: Passing and returning values from another script?

2003-10-24 Thread Mark Weisman
I'm not sure, however I put the script mods in that you suggested, and
my $output is the word "SCRIPT", I would like clarification on line 2 if
you would please?
>my $output = join("", SCRIPT);

Sincerely in Christ,
Mark-Nathaniel Weisman
President / Owner
Outland Domain Group
Anchorage, Alaska



-Original Message-
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]

Sent: Friday, October 24, 2003 12:08 AM
To: Mark Weisman; [EMAIL PROTECTED]
Subject: RE: Passing and returning values from another script?


I'm not sure but
 
open (SCRIPT, "./scriptname.pl password|");
my $output = join("", SCRIPT);
close SCRIPT
 
shall work;

-Original Message-
From: Mark Weisman [mailto:[EMAIL PROTECTED]
Sent: Friday, October 24, 2003 9:53 AM
To: [EMAIL PROTECTED]
Subject: Passing and returning values from another script?


 

I would like to encrypt textbox provided passwords. I have a script that
I found on the web, and it asks that I call the script and provide the
word afterwards (i.e. ./scriptname.pl password). The script then
provides me the encrypted password to the screen. I am wondering how I
can pass that password to the script, and get the output value back into
my other script? Can someone help?

 

Sincerely in Christ,

Mark-Nathaniel Weisman

President / Owner

Outland Domain Group

Anchorage, Alaska

 


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



Success! RE: No dice;details . RE: run in background from qx// ?

2003-10-24 Thread McMahon, Chris

Thank you Stefan, that works fine!  
The camel book is not at all clear for system/exec syntax... 
-C 

-Original Message-
From: Stefan Lidman [mailto:[EMAIL PROTECTED] 
Sent: Thursday, October 23, 2003 2:43 PM
To: [EMAIL PROTECTED]
Subject: Re: No dice;details . RE: run in background from qx//?

>Stefan...
>   The line I'm trying to execute looks like: 
>
>"/dir/dir2/program -a -a -B 5000 -c $var1 -d value $var2&"  
>
>   I'm trying to do this with 'system' and failing.  How would you
>parse this run line for 'system' to execute?  
>   -Chris

system '/dir/dir2/program -a -a -B 5000 -c ' . $var1 .  ' -d value '.
$var2 .'&';

should work

/Stefan

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



RE: Visual Perl

2003-10-24 Thread Bob Showalter
Ned Cunningham wrote:
> Tk does not come with the standard
> Active Perl load. 

Hmm, it did with mine. Anyway "ppm install Tk" should do the trick.

> 
> If I make an executable with perlapp, would I need TK loaded on the
> target system? 

Nope. PerlApp is cool!

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



Parse and Compare Text Files

2003-10-24 Thread Mike M
Hi,

I'm new to Perl and have what I hope is a simple question:  I have a Perl
script that parses a log file from our proxy server and reformats it to a
more easily readable space-delimited text file.  I also have another file
that has a categorized list of internet domains, also space-delimited.  A
snippet of both text files is below:

Proxy Log
snip
10/23/2003 4:18:32 192.168.0.100 http://www.squid-cache.org OK
10/23/2003 4:18:33 192.168.1.150 http://msn.com OK
10/23/2003 4:18:33 192.168.1.150 http://www.playboy.com DENIED
snip

Categorized Domains List
snip
msn.com news
playboy.com porn
squid-cache.com software
snip

What I would like to do is write a script that compares the URL in the proxy
log with the categorized domains list file and creates a new file that looks
something like this:

New File
snip
10/23/2003 4:18:32 192.168.0.100 http://www.squid-cache.org software OK
10/23/2003 4:18:33 192.168.1.150 http://msn.com news OK
10/23/2003 4:18:33 192.168.1.150 http://www.playboy.com porn DENIED
snip

Is this possible with Perl??  I've been trying to do this by importing the
log files into SQL and then running queries, but it's so much slower than
Perl (the proxy logs are roughly 1 million lines).  Any ideas?

Thanks in advance for your help.

Mike



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



Re: lowercase

2003-10-24 Thread Yi Chu
try this:
$stri =~ tr/A-Z/a-z/;

yi

--- Andre Chaves Mascarenhas <[EMAIL PROTECTED]> wrote:
> Hi if i have an string lets say
> $stri="Joana Prado";
> How do i transformm it into
> "joana prado" 
> (all lowercase)
> Thanks
> 


__
Do you Yahoo!?
The New Yahoo! Shopping - with improved product search
http://shopping.yahoo.com

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



Re: lowercase

2003-10-24 Thread George Schlossnagle
Or

$str = lc($str);

On Friday, October 24, 2003, at 11:23  AM, Yi Chu wrote:

try this:
$stri =~ tr/A-Z/a-z/;
yi

--- Andre Chaves Mascarenhas <[EMAIL PROTECTED]> wrote:
Hi if i have an string lets say
$stri="Joana Prado";
How do i transformm it into
"joana prado"
(all lowercase)
Thanks


__
Do you Yahoo!?
The New Yahoo! Shopping - with improved product search
http://shopping.yahoo.com
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

-- George Schlossnagle
-- Principal Consultant
-- OmniTI Computer Consulting, Inc.
-- +1.410.872.4910 x202
-- 1024D/1100A5A0 1370 F70A 9365 96C9 2F5E  56C2 B2B9 262F 1100 A5A0
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


Re: What is the best way to set options in a constructor

2003-10-24 Thread R. Joseph Newton
Sorry, this was clumsy and graceless:

"R. Joseph Newton" wrote:


> sub new {
> ...

>   }else {
>   $self->initialize(@_);
>}
>return $self;
> }
>

It works much better without the else here.  Inializing with the remainder of the
parameter list allows ad-hoc expansion of the object attributes.  So:

package MyObject;

use strict;
use warnings;

use Exporter;

sub new {
   my $class = shift;   # point taken

   my $self = {};
   bless $self, $class;
   if ($_[0] && $_[0]->isa($class) ) {
  my $source = shift;
  $self->{$_} = $source->{$_} for keys %$source;
   }

   $self->initialize(@_);
   return $self;
}

sub initialize {
  my $self = shift;
  my %source = @_;
  $self->{$_} = $source{$_} foreach keys %source;
}
1;

Greetings! E:\d_drive\perlStuff>perl -w -MMyObject
my $obj = MyObject->new qw(first 1 second 2);
print $obj, "\n";
print "Yes\n" if $obj->isa(MyObject);
print "$_: $obj->{$_}\n" for keys %$obj;
my $obj2 = MyObject->new($obj);
print $obj2, "\n";
print "Yes\n" if $obj2->isa(MyObject);
print "$_: $obj2->{$_}\n" for keys %$obj2;
my $obj3 = MyObject->new($obj, qw(third 3 fourth 4));
print $obj3, "\n";
print "Yes\n" if $obj3->isa(MyObject);
print "$_: $obj3->{$_}\n" for keys %$obj3;
^Z
MyObject=HASH(0x15d55ec)
Yes
first: 1
second: 2
MyObject=HASH(0x1a87824)
Yes
first: 1
second: 2
MyObject=HASH(0x1a45afc)
Yes
first: 1
second: 2
third: 3
fourth: 4

Greetings! E:\d_drive\perlStuff>


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



Re: Visual Perl

2003-10-24 Thread Beau E. Cox
On Friday 24 October 2003 05:47 am, Victor Medrano wrote:
> I'm Really interesting in this software , let me know if you find
> A visual perl .
>
> Regards
>
> -Original Message-
> From: Ned Cunningham [mailto:[EMAIL PROTECTED]
> Sent: Friday, October 24, 2003 12:00 PM
> To: [EMAIL PROTECTED]
> Subject: Visual Perl
>
>
> Hi Gurus,
>
> I just finished up with a Perl program using Win32::Console on a Windoze
> NT system, Perl ver 5.6.1.
>
> I was wondering why with all the power of Perl, and all the
> functionality it has, why I cant make a pretty input window?
>
> Also, Does anyone use Visual Perl?  What does it offer if any, in these
> type of programs.
>
> TIA
>
>
> Ned Cunningham

You folks should check out Perl/Tk - a complete GUI for perl
- from CPAN.

Aloha => Beau.


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



'rmm' (or 'trash') script

2003-10-24 Thread Kevin Pfeiffer
Hi all,

I just took another look at an exercise I wrote a couple months ago and
fleshed it out a bit. It is a commandline "trashcan" program which I
actually use. Instead of typing 'rm' I almost always use 'rmm' now.

It's meant to be used in a "friendly" environment, nonetheless, if anyone
sees any potentials for error (or suggestions for better work) please say
so...

http://timo.iu-bremen.de/~pfeiffer/bin/trash.d/

(I'm also not quite sure if $ENV{HOME} is valid for the Windows
environment.)

I ran into the problem of how to delete non-empty directories (which I
ignored the first time I worked on this) and remembered from my objects
book that I needed a recursive function to first clear out my directories.
Amazingly, I actually remembered how to do this (okay, it's not that
difficult, I know).

Thanks,

-Kevin


-- 
Kevin Pfeiffer


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



Re: Parse and Compare Text Files

2003-10-24 Thread Wiggins d'Anconia
Mike M wrote:
Hi,

I'm new to Perl and have what I hope is a simple question:  I have a Perl
script that parses a log file from our proxy server and reformats it to a
more easily readable space-delimited text file.  I also have another file
that has a categorized list of internet domains, also space-delimited.  A
snippet of both text files is below:
Proxy Log
snip
10/23/2003 4:18:32 192.168.0.100 http://www.squid-cache.org OK
10/23/2003 4:18:33 192.168.1.150 http://msn.com OK
10/23/2003 4:18:33 192.168.1.150 http://www.playboy.com DENIED
snip
Categorized Domains List
snip
msn.com news
playboy.com porn
squid-cache.com software
snip
What I would like to do is write a script that compares the URL in the proxy
log with the categorized domains list file and creates a new file that looks
something like this:
New File
snip
10/23/2003 4:18:32 192.168.0.100 http://www.squid-cache.org software OK
10/23/2003 4:18:33 192.168.1.150 http://msn.com news OK
10/23/2003 4:18:33 192.168.1.150 http://www.playboy.com porn DENIED
snip
Is this possible with Perl??  I've been trying to do this by importing the
log files into SQL and then running queries, but it's so much slower than
Perl (the proxy logs are roughly 1 million lines).  Any ideas?
What have you tried, where have you failed?  Just about anything is 
possible with Perl, and there are hints that will make this more 
bearable, but this isn't a one stop shopping place, so give it a try 
yourself first

You seem to have a good grasp of what is needed, break it down into 
parts and see what you come up with...

1. We need a list of domains to match against and what category they are in,
2. We need a line from the log to get the domain,
3. We need to look up into the list of domains to see if the domain is 
there,
4. If it is we need to add the category to the end of the domain,
5. We need a place to store the information back to.

So you need at the very least:

perldoc -f open
perldoc -f print
And you are probably going to want,

perldoc -f exists
perldoc -f keys
perldoc -f values
perldoc -f grep
And then probably a while loopSo some pseudo code might look like:

open file of categorized domains
store categorized domains into an easily accessible data structure
close file
open file for writing to store updated log to
open file that has log lines in it
while we read the file, do some stuff, where:
if the line has a domain name
pull the domain name
compare it to the data structure
if it is in teh data structure update the line
print the line to the new location
repeat
close the read file
close the write file
Have a beer.  By the way you should deny msn.com instead of playboy.com 
;-)

http://danconia.org

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


Re: 'rmm' (or 'trash') script

2003-10-24 Thread david
Kevin Pfeiffer wrote:

> Hi all,
> 
> I just took another look at an exercise I wrote a couple months ago and
> fleshed it out a bit. It is a commandline "trashcan" program which I
> actually use. Instead of typing 'rm' I almost always use 'rmm' now.
> 
> It's meant to be used in a "friendly" environment, nonetheless, if anyone
> sees any potentials for error (or suggestions for better work) please say
> so...
> 

i didn't read your whole script, only the first 20 lines or so and i have a 
few suggestions:

1. you have:

if ($ARGV[0] =~ /^-(.)$/) {

can your program handle files starting with a '-'? it's legal in *nix for 
file names to begin with a '-':

[panda]$ touch ./-abcd
[panda]$ ls -l ./-abcd
-rw-r--r--1 dzhuo dzhuo0 Oct 24 16:13 ./-abcd
[panda]$ rm -f ./-abcd

i understand that you can still supply files to rmm starting with '-' like:

[panda]$ rmm ./-remove-this-file
[panda]$ rmm /home/dzhuo/-remove-this-file

but i think it's still nice (maybe) to be able to just:

[panda]$ rmm -remove-this-file

2. you have:

($trash_dir) or die "Error: No trash directory defined!\n";

which means you will not allow user to name his/her trash directory '0'? for 
a general utility program like your rmm, you should relax this restriction.
btw, $trash_dir is hard coded in your script so how can it ever be false?

3. you have:

$path =~ /.*\..+$/ or die "Name of trash directory must begin with a dot 
followed by one or more letters!\n";

your regex does not match your die message.

4. you have:

unless (-e $path) {
 print "Creating trash directory: $path\n";
 mkdir $path or die "Couldn't create $path: $!\n";
}

don't do this for a general utility program where your program might be 
involved very often from different scripts. you have a race condition. do 
something similar to the following instead:

[panda]$ perl -MErrno -e 'die $! unless(mkdir('foo') || $!{EEXIST});'
[panda]$

5. see if Getopt::Std (and friends) can help you simplify your arg parsing 
code.

6. see if Fild::Find can help you simplify some of your dir scanning code.

7. it will be nice to set a limit on how big your trash dir can be. 
otherwise, it's easy for people to give putting stuff into it and forget 
about how big it has grown to.

if i have time, i will check the whole script for you.

david
-- 
$_=q,015001450154015401570040016701570162015401440041,,*,=*|=*_,split+local$";
map{~$_&1&&{$,<<=1,[EMAIL PROTECTED]||3])=>~}}0..s~.~~g-1;*_=*#,

goto=>print+eval

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



CGI:Session param dbh

2003-10-24 Thread perl
If I store a dbh in a session as in, $session->param("DB",$dbh), what
happen when the session expire due to expire setting? Will the dbh still
be in memory or cleaned up?

-thanks



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

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



Re: CGI::Session param help

2003-10-24 Thread perl
Thanks, I was reading the doc on the cpan site and it wasn't so obvious.
But the perldoc CGI::Session showed how to delete so obviously.

That's after I figured out how to use perldoc to get to Session.

Again, thanks for the patient.


> On Oct 24, [EMAIL PROTECTED] said:
>
>>Can someone tell me how to delete a parameter in $session->param("BOGUS")
>>that was set?
>
>   $session->delete("BOGUS");
>
> Read 'perldoc CGI' for more details.
>
> --
> Jeff "japhy" Pinyan  [EMAIL PROTECTED]  http://www.pobox.com/~japhy/
> RPI Acacia brother #734   http://www.perlmonks.org/   http://www.cpan.org/
>  what does y/// stand for?   why, yansliterate of course.
> [  I'm looking for programming work.  If you like my work, let me know.  ]
>
>
> --
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
>



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

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



Re: lowercase

2003-10-24 Thread perl
or you can do $stri=lc($stri);

-rkl

> try this:
> $stri =~ tr/A-Z/a-z/;
>
> yi
>
> --- Andre Chaves Mascarenhas <[EMAIL PROTECTED]> wrote:
>> Hi if i have an string lets say
>> $stri="Joana Prado";
>> How do i transformm it into
>> "joana prado"
>> (all lowercase)
>> Thanks
>>
>
>
> __
> Do you Yahoo!?
> The New Yahoo! Shopping - with improved product search
> http://shopping.yahoo.com
>
> --
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
>



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

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