[17429] in Perl-Users-Digest

home help back first fref pref prev next nref lref last post

Perl-Users Digest, Issue: 4849 Volume: 9

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Nov 8 21:06:10 2000

Date: Wed, 8 Nov 2000 18:05:13 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <973735512-v9-i4849@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Wed, 8 Nov 2000     Volume: 9 Number: 4849

Today's topics:
    Re: $password = crypt($pass, ar); <godoy@conectiva.com>
    Re: -e file tester bug <ren.maddox@tivoli.com>
    Re: -e file tester bug (Tad McClellan)
        cgi.pm cookie path bug? <fchanny@lbl.gov>
    Re: garbage collecting hashes are slow (Richard J. Rauenzahn)
    Re: Help -- msgget with key >= 0x80000000 fails (Martien Verbruggen)
    Re: HELP HOMEWORK!!! <wyzelli@yahoo.com>
    Re: help on improving code (pine2mutt-script ca 130 lin (Tad McClellan)
    Re: Help with HTML::Parser module (Daniel Chetlin)
    Re: Help with HTML::Parser module (Daniel Chetlin)
    Re: HELP nodo70@my-deja.com
        How would you delete the topmost line of a file? research@ev1.net
    Re: How would you delete the topmost line of a file? (Gwyn Judd)
    Re: How would you delete the topmost line of a file? <jeff@vpservices.com>
    Re: How would you delete the topmost line of a file? <crt@kiski.net>
    Re: I do not Understand Perl Formats <sariq@texas.net>
        I dunno if that's kinda offtopic <crud_alex@yahoo.com>
        Ideas? Anyone, please..... <tlawall@score.leaguelink.com>
    Re: Need Help with a Regular Expression <ren.maddox@tivoli.com>
        Net::Telnet & Net::Ping nodo70@my-deja.com
    Re: OOP and information hiding (Chris Fedde)
    Re: OOP and information hiding (Damian Conway)
        Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)

----------------------------------------------------------------------

Date: 08 Nov 2000 21:39:01 -0200
From: Jorge Godoy <godoy@conectiva.com>
Subject: Re: $password = crypt($pass, ar);
Message-Id: <kp1ywmrq3u.fsf@dagon.conectiva>

On Wed, 08 Nov 2000, tjla@guvfybir.qlaqaf.bet wrote:
> Yeah but then you are stuck if the user can't remember the password
> and you have to email it to them. Of course, the whole idea of
> emailing someone a password is so ridiculous from the security front
> I don't know why I'm mentioning it.

An alternative would be to create a temporary password that will
replace the old one and make it valid for, lets say, 30 minutes. The
user will use this password to login and change it to a known
password, removing the time limit (or changing it to anything else).


See you,
-- 
Godoy. <godoy@conectiva.com>

Departamento de Publicações       Conectiva S.A.
Publishing Department             Conectiva Inc.


------------------------------

Date: 08 Nov 2000 16:19:10 -0600
From: Ren Maddox <ren.maddox@tivoli.com>
Subject: Re: -e file tester bug
Message-Id: <m3k8aeksyp.fsf@dhcp11-177.support.tivoli.com>

Don Vaillancourt <donv@webimpact.com> writes:

> >>
> >>     $properties->{running}->{"running_size"}=0; # this is a mock entry
> >
> >So, $properties->{running} is a reference to a hash, yes?
> >
> >>     my $i;
> >>     my $file = $properties->{running};
> >
> >Or is it the name of a file?
> 
> This is a hash which contains name/values which I read from $file.

A few lines above, you treat $properties->{running} as a hash
reference -- you dereference it with ->{"running_size"}.  Then, you
treat it as a string.  Which is it?  (Admittedly, it technically *can*
be both if strict refs are not enabled, but that would be particularly
ugly.)

> >>     if (-e "$file")  # <-- This is where the problem occurs
> >
> >Perhaps you should print the value of $file and verify that it is what
> >you expect.
> 
> That I have done, and have verified that the filename is correct and does or
> doesn't exist in the directory structure.

Could you possible include your prints in your code, and then also
include the results?  Does the filename include the full path?  If
not, then perhaps the current directory is getting changed somewhere.
For good measure, include a line right next to the -e test that just
does lists the directory:

print `ls`;  # or print `dir` on Windows

I'm sure we can track this down eventually....

BTW, those quotes around $file are not needed (for that matter,
neither are the ones around running_size.

-- 
Ren Maddox
ren@tivoli.com


------------------------------

Date: Wed, 8 Nov 2000 18:48:29 -0500
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: -e file tester bug
Message-Id: <slrn90jpid.aa5.tadmc@magna.metronet.com>

On 8 Nov 2000 22:52:55 GMT, Clay Irving <clay@panix.com> wrote:
>On Wed, 08 Nov 2000 17:06:54 -0500, Don Vaillancourt <donv@webimpact.com> wrote:

>You also wrote a bunch of HTML garbage in this message.


Oh. That must be why I never saw the article.

I love my killfile.


-- 
    Tad McClellan                          SGML consulting
    tadmc@metronet.com                     Perl programming
    Fort Worth, Texas


------------------------------

Date: Wed, 08 Nov 2000 15:44:31 -0800
From: Frank Hanny <fchanny@lbl.gov>
Subject: cgi.pm cookie path bug?
Message-Id: <3A09E55F.C81AFA2@lbl.gov>

If this has come up before, as seems likely, forgive me, as lengthy
searches 
on dejanews did not turn it up.

From http://www.perl.com/pub/doc/manual/html/lib/CGI.html:

>3.a path If you provide a cookie path attribute, the browser will check it against your 
>script's URL before returning the cookie. For example, if you specify the path ``/cgi-bin'', 
>then the cookie will be returned to each of the scripts ``/cgi-bin/tally.pl'', 
>``/cgi-bin/order.pl'', and ``/cgi-bin/customer_service/complain.pl'', but not to the script 
>``/cgi-private/site_admin.pl''. By default, path is set to ``/'', which causes the cookie
>to be sent to any CGI script on your site. 

My experience differs. My environment: ActiveState perl 5.005, cgi.pm
version 2.46, on a 
Windows NT server running IIS. Browsers I have tried are Netscape 4.73
and IE 5.00, and both
behave the same for once.

First, the default path, if none is specified in the call to the cookie
method, is the 
current path of the perl program, not "/".

Thus, the following call from
http://mydomain.com/self_service/parking/cookie.pl

	$cookie = $q->cookie( -name => 'self_service', 
                              -value => '123',
                              -expires => '+1h' );

produces the following cookie:

"self_service=123; path=/self_service/parking/; expires=Wed, 08-Nov-2000
22:57:58 GMT"

This cookie does have the desirable attribute that it can be retrieved
using 

	$value = $q->cookie( -name => 'self_service' );

Second problem: if I do specify the path, as follows

 	$cookie = $q->cookie( -name => 'self_service', 
                              -value => '123',
                              -path => '/self_service/',
                              -expires => '+1h' );

intending to share the cookie with other applications in the
/self_service/ hierarchy, 
I can no longer retrieve the cookie with 

	$value = $q->cookie( -name => 'self_service' );

from the original application, nor can I retrieve it from any other
application in the 
/self_service/ hierarchy, (though presumably I could retrieve it from an
application 
running in /self_service/ itself?) If I specify -path => '/', the
behavior is the same.

Any suggestions? 

Thanks,

Frank Hanny


------------------------------

Date: 9 Nov 2000 00:54:32 GMT
From: nospam@hairball.cup.hp.com (Richard J. Rauenzahn)
Subject: Re: garbage collecting hashes are slow
Message-Id: <973731271.952678@hpvablab.cup.hp.com>

Fulko Hew <fulko@wecan.com> writes:
>Gwyn Judd wrote:
>> 
>> :) Oh by the way, it's considered rude to send someone an emailed reply
>> and post the same reply to usenet without mentioning that fact.
>
>My appologies.  I've never heard such a rule before.  Unless you
>mean the private mail should have mentioned that it was posted too?
>cause anyone reading the posting wouldn't care if it was privately
>mailed.

You'll notice many posters will prefix their post with...

	[a courtesy copy has been sent to the author]

	or

	[posted & emailed]

The reason behind this is that one might spend some time coming up with
a personal reply, email it off, then find that the same message was also
in the newsgroup.  Now the person you thought you were helping has to
_also_ reply in the newsgroup, and possibly has to rewrite the response
since its now in a public forum.

>I just think it convenient to receive it personally, since you were
>involved in the discussion, and to have it posted too for posterity
>so that others could benefit.

I generally prefer not to receive a copy.  Some of us get enough email
as it is!

Rich

-- 
Rich Rauenzahn ----------+xrrauenza@cup.hp.comx+ Hewlett-Packard Company
Technical Consultant     | I speak for me,     |   19055 Pruneridge Ave. 
Development Alliances Lab|            *not* HP |                MS 46TU2
ESPD / E-Serv. Partner Division +--------------+---- Cupertino, CA 95014


------------------------------

Date: Thu, 09 Nov 2000 01:37:36 GMT
From: mgjv@tradingpost.com.au (Martien Verbruggen)
Subject: Re: Help -- msgget with key >= 0x80000000 fails
Message-Id: <slrn90jvv3.7ck.mgjv@verbruggen.comdyn.com.au>

On Wed, 8 Nov 2000 14:07:31 -0000,
	Geoff Winkless <geoff-at-farmline-dot-com@127.0.0.1> wrote:
> "Martien Verbruggen" <mgjv@tradingpost.com.au> wrote in message
> news:slrn90ifbf.boe.mgjv@martien.heliotrope.home...
>> One thing you could do, in the meantime, is check the Perl code to see
>> what goes on when you call these functions, and compare them with what
>> they should do. It is possible that the Perl 5.005_03 code uses an int
>> when they should use a key_t. Perl 5.6.0 uses
>>
>>     key = (key_t)SvNVx(*++mark);
>>
>> which looks like a cast from a double to a key_t. Maybe that is just not
>> correct. Try it out in C, and see if it works. Check the 5.005_03
>> sources first, to see how exactly it happens there (doio.c).
> 
>> Is this the perl that comes with RedHat? If so, chuck it and compile
>> your own. Your problem might just go away. it wouldn't be the only thing
>> that suddenly would repair itself.
> 
> Heh. Tried that. However it seems that there's an error going on somewhere
> in linux: linux's key_t is an int, which (apparently) implies a signed int.

Yes. An int is signed.

> As such my understanding is that my specifying a key of ffe0ffe0 _should_
> fail?

It should, but didn't you say that you had C code that did the same,
but that worked? That's what threw me a bit.

Martien
-- 
Martien Verbruggen              | 
Interactive Media Division      | 
Commercial Dynamics Pty. Ltd.   | values of Beta will give rise to dom!
NSW, Australia                  | 


------------------------------

Date: Thu, 9 Nov 2000 09:39:09 +0930
From: "Wyzelli" <wyzelli@yahoo.com>
Subject: Re: HELP HOMEWORK!!!
Message-Id: <6SlO5.18$4c.2571@vic.nntp.telstra.net>

"Milan Miladinovic" <vortex@ptt.yu> wrote in message
news:8ub1i9$202$1@nnrp1.deja.com...
> Hello,
> I got for home work to do this
>
> *
> Consider the following program:
>
>   #! /usr/local/bin/perl5.003 -w
>
>   {
>         my($string) = "brad<hello>3hello";
>         $string =~ /^[^\d]{2,4}<([^>]+)>\d?\1$/;
>         if( defined($1) ) {
>                 print "$1\n";
>         } else {
>                 print "not found\n";
>         }
>   }
>
> Explain what the regular expression is trying to match?

Indeed but it is a pretty poor re anyway.

It matches - start of string : ^
start a characters class : [
negate the character class (not this stuff) : ^
numbers : \d
end character class : ]
match minimum and maximum of previous item (min 2 max 4): {2,4}
That section would be better written as \D{2,4} since \D == [^d]
the character < : <
start capturing into $1:

$1 is the first capturing parentheses, $2 the second etc
a character class : [
'not >': ^> # ie anything except >
end character class : ]
1 or more of the previous item ( in this case one or more of anything
that is not a >) : +
end capturing into $1: )
the character > : >
a number : \d
that number is optional : ?
whatever was captured into $1 : \1
The end of the string : $

So the re matches anything between the < and > tags as long as the first
tag is preceded by 2-4 non numbers after the start of string and the
contents of the tag are repeated at the end of the string separated from
the > tag by an optional number.

It is also particularly dangerous to print $1 after only a 'defined'
test as the content of $1 may have been set by a previous match, and a
failure of this re will not render $1 'undefined'.  It is better to test
for success of the match before doing anything with $1.

if ($string =~ /^\D{2,4}<([^>]+)>\d?\1$/){
    print $1;
}
else {
    print "not found\n";
}

Wyzelli
--
($a,$b,$w,$t)=(' bottle',' of beer',' on the wall','Take one down, pass
it around');
for(reverse(1..100)){$s=($_!=1)?'s':'';$c.="$_$a$s$b$w\n$_$a$s$b\n$t\n";
$_--;$s=($_!=1)?'s':'';$c.="$_$a$s$b$w\n\n";}print"$c*hic*";





------------------------------

Date: Wed, 8 Nov 2000 19:27:33 -0500
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: help on improving code (pine2mutt-script ca 130 lines)
Message-Id: <slrn90jrrl.aa5.tadmc@magna.metronet.com>

On Wed, 08 Nov 2000 22:08:38 GMT, Jan Schaumann 
   <jschauma@www.netmeister.org> wrote:
>
>having just changed from pine to mutt I decided to write a little script that
>converts the .addressbook into a mutt-alias-file. Here's what I have come up
>with - it does the job, but I'd like to learn Perl in more depths and would
>appreciate any feedback on how to improve the code, how to make it more
>"perlish" etc.


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


A most excellent start!


>#declaration of variables used up here
>my $PINE =  $ENV{HOME} . "/.addressbook";


I think most people would use interpolation rather than
concatenation for that:

   my $PINE =  "$ENV{HOME}/.addressbook";



>#declaration of varibales we use lateron
>my $nick = "";
>my $name = "";
>my $email = "";
>my $tmp = "";


1) those do not need to be file-scoped. You should limit variable
   scope to the smallest possible area. Declare them in your
   while loop body.

2) you do not need to assign the empty string. If you use them
   "like a string" they will look like the empty string. If you
   use them like a number, they will look like zero.


>###
>### command-line arguments handling


There are modules for that, so

[ snip ]

>### end command line arguments handling


>open(PINE, "$PINE") or die "Cannot open pine's addressbook \"$PINE\"!\n";
>open(MUTT, ">$MUTT") or die "Cannot open mutt's \"$MUTT\"!\n";


You should include the $! variable in your diagnostic message. It
contains info that will help diagnose failures.

You might want to choose something besides a double quote for
wrapping the filename, like a single quote.

Or use an alternate delimiter form of double quoted string:

   open(MUTT, ">$MUTT") or die qq/Cannot open mutt's "$MUTT"!  $!\n/;


>while (<PINE>)
>{
>    unless(/^#DELETED/) # pine keeps deleted email-addresses for a while


You can save a whole level of indent by using next() to skip
entries that you don't want to process:

   next if /^#DELETED/;


>    {
>        if (/\(/)
>        {
>            # pine has email-lists in parentheses
>            s/\(//;


You can save a step by doing the s/// in the conditional:

   if ( s/\(// ) 


>            /(.*?)\t(.*?)\t(.*?)$/;
>            $nick = $1;
>            $name = $2;
>            $tmp = $3;


Here we have a Biggie. Not just a stylistic comment like all
of the rest:

Never ever use the dollar-digit variables unless you have
first tested to see if the match succeeded:


   if ( /(.*?)\t(.*?)\t(.*?)$/ ) {
      $nick = $1;
      ...


The dollar-digit variables are only set on a _successful_ match.
If you haven't tested the success of the match, you can't really
be sure which pattern match it was that set their values.

-----

I don't see that non-greediness is needed either:

   if ( /([^\t]*)\t([^\t]*)\t(.*)$/ ) {

-----

Probably best, would be to use a pattern match in list context:

   ($nick, $name, $tmp) = /([^\t]*)\t([^\t]*)\t(.*)$/;


>        if (($tmp) and (/^\s/)) # we have an email-list
>        {
>            s/\n|\s//;


Errr, \n is one of the \s characters, so it is redundant:

   s/\s//;


>### now tell .muttrc where to look for aliases
>
>my $found = 0;
>
>open(MUTTRC, "$ENV{HOME}/.muttrc");


You should always check the return value from open() calls:

   open(MUTTRC, "$ENV{HOME}/.muttrc") || die ...


-- 
    Tad McClellan                          SGML consulting
    tadmc@metronet.com                     Perl programming
    Fort Worth, Texas


------------------------------

Date: 9 Nov 2000 00:33:15 GMT
From: daniel@chetlin.com (Daniel Chetlin)
Subject: Re: Help with HTML::Parser module
Message-Id: <8ucrcb0pdv@news2.newsguy.com>

On Wed, 08 Nov 2000 14:35:35 GMT, Bart Lateur <bart.lateur@skynet.be> wrote:
[snip]
> * It is VERY memory intensive. I've had a test case where I had an
>out-of-memory error for processing a 15k HTML file. Keeping a whole
>database of records in memory all at once (25000 items, the printed out
>version makes a book of over 1000 pages), on the same computer, is no
>problem. Now, 15k is a small HTML file.

Hmm, this surprises me. Is there any chance you have that 15k file still
sitting around? I've used TreeBuilder quite a bit without memory
problems.

> * If your HTML file isn't 100% complying to the official specs, I think
>this module will choke on it.

This is definitely untrue. TreeBuilder is specifically *designed* to
handle the HTML that's "out there". In fact, if you want to have an idea
of how common browsers (wrongly) interpret HTML, TreeBuilder is your
best bet, because it cuts the same corners so as to be useful for
real-world HTML.

-dlc


------------------------------

Date: 9 Nov 2000 00:51:56 GMT
From: daniel@chetlin.com (Daniel Chetlin)
Subject: Re: Help with HTML::Parser module
Message-Id: <8ucsfc07c5@news1.newsguy.com>

On 8 Nov 2000 12:48:00 -0100,
 Juan Eliseo Carrasco Díaz <eliseo@cocoon.ulpgc.es> wrote:
>I trying to delete all the <font face="Arial"> and <font face="Times new
>
>roman"> marks and its respective </font> marks of my HTML pages, but I
>can't find an easy way.
[snip example]
>Somebody say me that HTML::Parse module can help me. I downloaded it. I
>read the documentation, but I don't know how to start. (I'm a beginner).

Hopefully you'll take this as a fishing line, not as fish.

  #!/usr/bin/perl

  use warnings;
  use strict;
  use HTML::Parser;

  my $p = HTML::Parser::->new(api_version => 3);
  $p->handler(default => sub { print @_ }, 'text');
  $p->handler(start => \&find_font, 'tagname, attr, self, text');
  $p->parse($_) while <>;
  $p->eof;

  sub find_font {
      my ($tagname, $attr, $self, $text) = @_;
      print $text and return unless $tagname eq 'font';
      print $text and return unless exists $attr->{face}
          and $attr->{face} =~ /arial|times new roman/i;
      $self->handler(end => \&end_font, 'tagname, text, self');
  }

  sub end_font {
      my ($tagname, $text, $self) = @_;
      print $text and return unless $tagname eq 'font';
      $self->handler(end => undef);
  }

Note that this solution doesn't deal perfectly well with nested `font'
tags -- to do that correctly would require a minor addition of a counter
to maintain state.

You might also take a look at HTML::TokeParser, which comes bundled with
HTML::Parser. It's a slightly easier interface to get used to, and would
handle this task quite well.

-dlc


------------------------------

Date: Thu, 09 Nov 2000 00:42:17 GMT
From: nodo70@my-deja.com
Subject: Re: HELP
Message-Id: <8ucrt9$kv1$1@nnrp1.deja.com>

Thanks for your response.  I looked "at" help index and still cannot
find where it said you can activate a job run at certain time and every
certain interval at all.

In article <8ubl4301uru@enews3.newsguy.com>,
  "John Hansknecht" <jhansknecht@hanstech.com> wrote:
> Go to NT Help index and lookup the "at command". This is the NT
equivalent
> to cron and you can use it to schedule a job to run on a regular
basis.
>
> John Hansknecht
> jhansknecht 'at' hanstech.com
>
> <nodo70@my-deja.com> wrote in message news:8u9p41
$2bc$1@nnrp1.deja.com...
> > Anyone can help me to write a simple code that run every 5
minutes?  I
> > know how to set it up in Unix for cron job but I am using NT I just
wan
> > to to run my program to check the system every 5 mins.  Thanks for
your
> > help.
> >
> > -nodo
> >
> >
> > Sent via Deja.com http://www.deja.com/
> > Before you buy.
>
>


Sent via Deja.com http://www.deja.com/
Before you buy.


------------------------------

Date: Thu, 09 Nov 2000 00:21:13 GMT
From: research@ev1.net
Subject: How would you delete the topmost line of a file?
Message-Id: <8ucqlj$jpg$1@nnrp1.deja.com>

As the subject reads, how would you remove the topmost line of a file?

TIA!
Ken


Sent via Deja.com http://www.deja.com/
Before you buy.


------------------------------

Date: Thu, 09 Nov 2000 00:45:55 GMT
From: tjla@guvfybir.qlaqaf.bet (Gwyn Judd)
Subject: Re: How would you delete the topmost line of a file?
Message-Id: <slrn90jsu0.mk2.tjla@thislove.dyndns.org>

I was shocked! How could research@ev1.net <research@ev1.net>
say such a terrible thing:
>As the subject reads, how would you remove the topmost line of a file?

This is in the FAQ

-- 
Gwyn Judd (print `echo 'tjla@guvfybir.qlaqaf.bet' | rot13`)
More people are flattered into virtue than bullied out of vice.
		-- R.S. Surtees


------------------------------

Date: Wed, 08 Nov 2000 17:00:48 -0800
From: Jeff Zucker <jeff@vpservices.com>
Subject: Re: How would you delete the topmost line of a file?
Message-Id: <3A09F740.10D9224A@vpservices.com>

research@ev1.net wrote:
> 
> As the subject reads, how would you remove the topmost line of a file?
> 

while(<IN>){ print OUT unless $.==1 }

-- 
Jeff


------------------------------

Date: Wed, 8 Nov 2000 20:30:14 -0500
From: "Casey R. Tweten" <crt@kiski.net>
Subject: Re: How would you delete the topmost line of a file?
Message-Id: <Pine.OSF.4.21.0011082029540.8238-100000@home.kiski.net>

On Nov 9 around 12:21am, research@ev1.net hammered out this masterpiece:

: As the subject reads, how would you remove the topmost line of a file?

$. != 1 ? print : 1 while <DATA>;

__DATA__
This is a file
I am printing
All the lines
but the first.


-- 
print(join(' ', qw(Casey R. Tweten)));my $sig={mail=>'crt@kiski.net',site=>
'http://home.kiski.net/~crt'};print "\n",'.'x(length($sig->{site})+6),"\n";
print map{$_.': '.$sig->{$_}."\n"}sort{$sig->{$a}cmp$sig->{$b}}keys%{$sig};
my $VERSION = '0.01'; #'patched' by Jerrad Pierce <belg4mit at MIT dot EDU>



------------------------------

Date: Thu, 09 Nov 2000 01:59:38 GMT
From: Tom Briles <sariq@texas.net>
Subject: Re: I do not Understand Perl Formats
Message-Id: <3A0A050A.108B4D2E@texas.net>

john_s_brown@my-deja.com wrote:
> 
> I have read through Programming Perl (3rd edition) chapter number 7,
> which tells about Perl Formats. But still I don't understand even the
> basics.

Try

perldoc perlform

- Tom


------------------------------

Date: Wed, 8 Nov 2000 12:28:03 +0800
From: "­»´ä¸}" <crud_alex@yahoo.com>
Subject: I dunno if that's kinda offtopic
Message-Id: <8ucraa$no9$1@taliesin.netcom.net.uk>

how to get ultraedit highlighting the perl variables?in ultraedit they are
treated as normal text and is rather hard to read the codes.

any helps are appreciated




------------------------------

Date: Wed, 8 Nov 2000 16:51:13 -0700
From: Travis Lawall <tlawall@score.leaguelink.com>
Subject: Ideas? Anyone, please.....
Message-Id: <Pine.LNX.4.10.10011081501010.3610-100000@score.leaguelink.com>

hello all,

I am looking for ideas and input on the following issue I am having with
the GnuPG::Interface modlue. Here is what occurs. I have a perl module,
Crypt, which is a subclass of GnuPG::Interface class. I use it in a script
from the command line or by itself in the debugger under perl 5.6.0 and
perl 5.005_3 with no problems at all. However when I use the Crypt module
under mod_perl with perl version 5.6.0 the print $input @$message seems to
fail by not encrypting the data being printed to $input but by encrypting
a null. This is not the case when running it under Apache/mod_perl/Perl
5.005_3, here it succedes in passing the data to the gpg process via the
print $input @$message line. The only thing I can think of is that
something wierd is occuring whereby it is ignoring the IO::Handle I am
passing as the stdin and somehow selecting the parent's stdin which is
/dev/null. There are no other error messages or signifigant output to
report and the only other oddity is I cannot seem to build and install
without errors IO::Handle for perl 5.6.0, included below is the attempt to
build and install IO-1.20 even though it is already up to date.

thanks in advance for any advice or flames that this message may cause....

Travis

[tlawall@thunder IO-1.20]$ make
mkdir blib
mkdir blib/lib
mkdir blib/arch
mkdir blib/arch/auto
mkdir blib/arch/auto/IO
mkdir blib/lib/auto
mkdir blib/lib/auto/IO
mkdir blib/man3
cp IO/Poll.pm blib/lib/IO/Poll.pm
cp IO/Socket/INET.pm blib/lib/IO/Socket/INET.pm
cp IO/Socket.pm blib/lib/IO/Socket.pm
cp IO/Select.pm blib/lib/IO/Select.pm
cp IO/Pipe.pm blib/lib/IO/Pipe.pm
cp IO/Handle.pm blib/lib/IO/Handle.pm
cp IO/Socket/UNIX.pm blib/lib/IO/Socket/UNIX.pm
cp IO/File.pm blib/lib/IO/File.pm
cp IO.pm blib/lib/IO.pm
cp IO/Dir.pm blib/lib/IO/Dir.pm
cp IO/Seekable.pm blib/lib/IO/Seekable.pm
/usr/bin/perl -I/usr/local/lib/perl5/5.6.0/i686-linux 
-I/usr/local/lib/perl5/5.6.0 /usr/local/lib/perl5/5.6.0/ExtUtils/xsubpp 
-typemap /usr/local/lib/perl5/5.6.0/ExtUtils/typemap IO.xs > IO.xsc && mv
IO.xsc IO.c cc -c  -fno-strict-aliasing -I/usr/local/include
-D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -O2     -DVERSION=\"1.20\"
-DXS_VERSION=\"1.20\" -fpic -I/usr/local/lib/perl5/5.6.0/i686-linux/CORE
-DI_POLL  IO.c In file included from
/usr/local/lib/perl5/5.6.0/i686-linux/CORE/perl.h:24,
from
IO.xs:9: /usr/local/lib/perl5/5.6.0/i686-linux/CORE/config.h:2306:
warning:
`I_POLL' redefined *Initialization*:1: warning: this is the location of
the
previous definition IO.xs: In function `XS_IO__Seekable_getpos':
IO.xs:208:
`sv_undef' undeclared (first use in this function) IO.xs:208: (Each
undeclared
identifier is reported only once IO.xs:208: for each function it appears
in.)
IO.xs: In function `XS_IO__File_new_tmpfile': IO.xs:252: `sv_undef'
undeclared
(first use in this function) make: *** [IO.o] Error 1


the test script I run from the cmdline looks like:


use Crypt;

$crypt = new Crypt;
$crypt->public_key('XXXXXX');
$crypt->home_dir('/home/defaultuser/.gnupg');
$crypt->encrypt_data(["Some test data"]);
print join("",@{$crypt->output()});





the crypt module looks like:



package Crypt;

use strict;
use GnuPG::Interface;
use GnuPG::Handles;
use IO::Handle;
use vars qw( @ISA ) ;

@ISA = qw( GnuPG::Interface );

sub new {

    my ($ref, @args) = @_;
    my $class = ref($ref) || $ref;
    my $self = $class->SUPER::new();
    bless ($self, $class);

    ### initialize the GnuPG stuff;
    $self->options->hash_init(  armor   => 1, 
                                verbose => 1,
                                homedir => '/home/defaultuser/.gnupg' );

    $self->options->meta_interactive( 0 );   # disable stdout/stderr
    return $self;
}

sub public_key {
    my $self = shift;
    if (@_) {
        my  $publickey = shift;
        $self->options->push_recipients( $publickey );
    } else {
        return $self->options->recipients();
    }
}

sub home_dir {
    my $self = shift;
    if (@_) {
        my $homedir = shift;
        $self->options->homedir( $homedir );
    } else {
        return $self->options->homedir();
    }
}

sub encrypt_data {
    my $self = shift;
    my $message = shift;
    my @encrypted = ();

    ### setup the handles
    my ( $output, $error ) = ( IO::Handle->new(), IO::Handle->new());

    my ( $input, $output, $error ) = ( IO::Handle->new(),
                                       IO::Handle->new(),
                                       IO::Handle->new());

    ### setup the GnuPG handles
    my $handles = GnuPG::Handles->new( stdin    => $input,
                                       stdout   => $output,
                                       stderr   => $error);

    $self->encrypt( handles => $handles );
    print $input @$message;
    close $input;
    
    @encrypted = <$output>;  # reading the output from gpg, the encrypted
message
    $self->{_OUTPUT} = \@encrypted;

    my @stderror = <$error>;
    $self->{_ERRORS} = \@stderror;

    wait;  # clean up the finished GnuPG process

    close $output;
    close $error;

    return \@encrypted;
}

sub output{
    my $self = shift;
    return $self->{_OUTPUT};
}

sub errors{
    my $self = shift;
    return $self->{_ERRORS};
}

sub reset_errors{
    my $self = shift;
    $self->{_ERRORS} = [];
}

1;

__END__





------------------------------

Date: 08 Nov 2000 15:29:11 -0600
From: Ren Maddox <ren.maddox@tivoli.com>
Subject: Re: Need Help with a Regular Expression
Message-Id: <m3puk6kva0.fsf@dhcp11-177.support.tivoli.com>

medi@cybershell.com writes:
[snip]
>       $v =~ m/($GramInt)|($GramString)|($GramFloat)|($GramHex)/;
[snip]
> Note how the first line has successfully managed to capture the
> float. In contrast when I'm looping thru the hash I don't match
> the float correctly. Instead I get [][23][.45]. ie the matched
> and post-matched are wrong. Similarly the hex part does not
> work. Int and String are doing their job correctly.

[][23][.45] was from the Int match, not the Float match.

I common misconception is that Perl's regexes will *always* match the
longest possible match.  That is far from the truth.  For the greedy
quantifiers (which you are using), it is true that they will match as
much as possible.  However, even more important is that they will
match as *soon* as possible.

What this means is (well, it means lots of things, but the one I'm
getting at is...) that if you have a multiple alternations that can
match, the first one that can match *will* match.

In your particular case, it looks like you *might* be able to solve
the problem by anchoring the patterns.  Or, that may be completely
inappropriate for your needs.  If you can use it, then changing (for
example):

  $GramInt = '\d+';

to:

  $GramInt = '^\d+$';

Will force it to *only* match (non-signed) integers rather than
matching an integer portion of a longer construct.

HTH,
-- 
Ren Maddox
ren@tivoli.com


------------------------------

Date: Thu, 09 Nov 2000 01:37:36 GMT
From: nodo70@my-deja.com
Subject: Net::Telnet & Net::Ping
Message-Id: <8ucv50$ngs$1@nnrp1.deja.com>

Anyone know what is wrong with the script below if I just want to write
to error log file if the hostname is not alive, cannot telnet to it, or
user/password is incorrect and just keep on next hostname, not
terminate the script at failing?  I try to run with the NT hostname
which doesn't support telnet and it still die, not writing to error log
file and move on next hostname as I expected it.  I also try to run
with either user/password incorrect and it also die.  Any suggestion?
Thanks in advance.

my $user   = 'nodo';
my $pass   = 'nodo00';
my @host   = ('nodo-00','nodo-01','nodo-02');
my $cmd    = 'vmstat 1 2';
foreach (@host) {
my $ping   = Net::Ping->new("icmp",10);
my $result = $ping->ping($_);
if ($result) {
    my $telnet = Net::Telnet->new(-host => $_,
                                  -timeout => 30);
    if ($telnet) {
       if ($telnet->login($user, $pass)) {
          my @output = $telnet->cmd($cmd);
          $telnet->close;
          print @output;
       }
       else {
          writeErrorLog ("Login failed");
       }
    }
    else {
       writeErrorLog ("Cannot connect to $host: $!");
    }
}
else {
  writeErrorLog ("$host is not alive");
}
}

sub writeErrorLog {
    my ($str) = @_;
    my ($errorLogFile) = "error.log";

    if (stat($errorLogFile)) {
       open (ERRORLOG, ">>$errorLogFile") || die "Cannot append
$errorLogFile to write\n";
    }
    else {
       open (ERRORLOG, ">$errorLogFile") || die "Cannot open
$errorLogFile to write\n";
    }
    print ERRORLOG "$str\n\n";
    close ERRORLOG;
}


Sent via Deja.com http://www.deja.com/
Before you buy.


------------------------------

Date: Thu, 09 Nov 2000 00:38:49 GMT
From: cfedde@fedde.littleton.co.us (Chris Fedde)
Subject: Re: OOP and information hiding
Message-Id: <tmmO5.252$Bf7.189810176@news.frii.net>

In article <8ua60d$elh$1@towncrier.cc.monash.edu.au>,
Damian Conway <damian@cs.monash.edu.au> wrote:
>   > You can still build nice things if everyone makes lego bricks; you can
>   > also make things together with velcro, or by using bolts. But velcro
>   > doesn't stick to lego. I better make lego bricks when I want to reuse
>   > someone else lego bricks, and work hard if I also want to incorperate
>   > someones velcro.
>
>The alternative offered by every other OO language is to *only* have
>lego, or *only* have velcro. Sure it's easier to write some types
>of classes if everything is just a glorified struct, or if everything
>is a list, but it's also appallingly limiting and frequently inefficient.
>

Please excuse me for saying it, but some of the conventions that
we are beginning to adopt in Perl to support OO smack of the
techniques that we used with Fortran-4 to support structured
programming.

I guess that I'm asking for two bits of advice.  First, what
should the "best practice" for Perl-OO instance variables be?
And, is that practice simple enough that we can expect authors of
inheritable CPAN modules to adopt it?

chris
-- 
    This space intentionally left blank


------------------------------

Date: 9 Nov 2000 01:05:41 GMT
From: damian@cs.monash.edu.au (Damian Conway)
Subject: Re: OOP and information hiding
Message-Id: <8uct95$ujo$1@towncrier.cc.monash.edu.au>

cfedde@fedde.littleton.co.us (Chris Fedde) writes:

   > I guess that I'm asking for two bits of advice.  First, what
   > should the "best practice" for Perl-OO instance variables be?
   > And, is that practice simple enough that we can expect authors of
   > inheritable CPAN modules to adopt it?

I'm not sure that there can ever be one "best" practice.

Surely it will always depend on where the most appropriate
balance between performance, maintainability, and safety lies
for a given application?

But if pressed, I think the Tie::Securehash module represents the
closest thing to a "best practice" for most applications. That's why
I've proposed most of its features as standard mechanisms in Perl 6.

I certainly think it's simple enough to warrant wider use.

You just replace the normal hash-based constructor of the class:

        sub new {
                my ($class, $arg1, $arg2, $arg3) = @_;
                return bless {
                              __attr1 => $arg1,
                              __attr2 => $arg2,
                              __attr3 => $arg3,
                             }, $class;
        }


with a securehash-based one:

        use Tie::SecureHash;

        sub new {
                my ($class, $arg1, $arg2, $arg3) = @_;
                return Tie::SecureHash->new($class,
                                            __attr1 => $arg1,
                                            __attr2 => $arg2,
                                            __attr3 => $arg3,
                                           );
        }

That's it. The object acts like a hash, but the double-underscored
attributes are private, and don't suffer from collisions with derived
class objects.

Of course, the trade-off is performance, since the object is actually
a tied hash (which is always slower to access). But if you develop under
'safe' mode:

        use Tie::SecureHash 'safe';

then you can release under 'fast' mode:

        use Tie::SecureHash 'mode';

and the performance hit disappears too.


Damian


------------------------------

Date: 16 Sep 99 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 16 Sep 99)
Message-Id: <null>


Administrivia:

The Perl-Users Digest is a retransmission of the USENET newsgroup
comp.lang.perl.misc.  For subscription or unsubscription requests, send
the single line:

	subscribe perl-users
or:
	unsubscribe perl-users

to almanac@ruby.oce.orst.edu.  

| NOTE: The mail to news gateway, and thus the ability to submit articles
| through this service to the newsgroup, has been removed. I do not have
| time to individually vet each article to make sure that someone isn't
| abusing the service, and I no longer have any desire to waste my time
| dealing with the campus admins when some fool complains to them about an
| article that has come through the gateway instead of complaining
| to the source.

To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.

To request back copies (available for a week or so), send your request
to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
where x is the volume number and y is the issue number.

For other requests pertaining to the digest, send mail to
perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
sending perl questions to the -request address, I don't have time to
answer them even if I did know the answer.


------------------------------
End of Perl-Users Digest V9 Issue 4849
**************************************


home help back first fref pref prev next nref lref last post