[25497] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 7741 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sat Feb 5 14:05:49 2005

Date: Sat, 5 Feb 2005 11:05:11 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Sat, 5 Feb 2005     Volume: 10 Number: 7741

Today's topics:
    Re: Can't use an undefined value as a HASH reference <nospam@sbcglobal.net>
    Re: Can't use an undefined value as a HASH reference <nospam@sbcglobal.net>
        Exception handling in class: question <mjl69mjl69@myaccmyacc.net>
    Re: Exception handling in class: question (Anno Siegel)
    Re: Exception handling in class: question <mjl69mjl69@myaccmyacc.net>
    Re: Exception handling in class: question <mjl69mj...@myaccmyacc.net>
    Re: Exception handling in class: question (Anno Siegel)
        Perl for data encryption hitachi4@rediffmail.com
    Re: Perl for data encryption <nospam@bigpond.com>
    Re: perl style: can I combine two steps into one? (Anno Siegel)
    Re: perl style: can I combine two steps into one? (Anno Siegel)
        perl telnet (not www) bbs? <gargoyle@no.spam>
    Re: perl telnet (not www) bbs? (David Efflandt)
    Re: perl telnet (not www) bbs? <gargoyle@no.spam>
    Re: perl telnet (not www) bbs? <gargoyle@no.spam>
    Re: Regular expression woes (News)
    Re: Why aren't 'warnings' on by default? <postmaster@castleamber.com>
    Re: Why aren't 'warnings' on by default? <wyzelli@yahoo.com>
    Re: Why aren't 'warnings' on by default? (Anno Siegel)
    Re: Why aren't 'warnings' on by default? (Anno Siegel)
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Sat, 05 Feb 2005 05:54:48 GMT
From: Josh McAdams <nospam@sbcglobal.net>
Subject: Re: Can't use an undefined value as a HASH reference
Message-Id: <IcZMd.25641$wi2.20068@newssvr11.news.prodigy.com>

Big and Blue wrote:
> Josh McAdams wrote:
> 
>>
>> Poor example on my part, here is the real code:
>>
>>  perl -MData::Dumper -Mstrict -e 'print join "\n", keys %{eval(`perl
>>  -MData::Dumper -e "print Dumper(\\\%ENV)"`)}'
> 
> 
>    The inner perl command produces output of the form:
> 
> $VAR1 = \{k1 => v1, k2 => v2..... };
> 
> You are using the result of eval()ing that as a HASH reference, which 
> seems odd to me.
> 
> What do you actually wish to achieve?
> 

The goal is to import the environment from a shell script into the 
current Perl scripts environment.  To do this, I am sourcing the shell 
script and printing it's environment to standard output:

qx{
   . /shell/script.sh
   perl -MData::Dumper -e "print Dumper(\\\%ENV)"
}

This is occurring within a containing Perl script that rebuilds the hash 
from Data::Dumper's output and then cycles through the hash picking out 
changed environment variables.

I've gotten everything working pretty well right now, but am having to 
turn off strict 'vars' for this hash-rebuilding section.

Thanks for all of your help!


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

Date: Sat, 05 Feb 2005 16:44:37 GMT
From: Josh McAdams <nospam@sbcglobal.net>
Subject: Re: Can't use an undefined value as a HASH reference
Message-Id: <4204F7F4.7060904@sbcglobal.net>

Josh McAdams wrote:
> Big and Blue wrote:
> 
>> Josh McAdams wrote:
>>
>>>
>>> Poor example on my part, here is the real code:
>>>
>>>  perl -MData::Dumper -Mstrict -e 'print join "\n", keys %{eval(`perl
>>>  -MData::Dumper -e "print Dumper(\\\%ENV)"`)}'
>>
>>
>>
>>    The inner perl command produces output of the form:
>>
>> $VAR1 = \{k1 => v1, k2 => v2..... };
>>
>> You are using the result of eval()ing that as a HASH reference, which 
>> seems odd to me.
>>
>> What do you actually wish to achieve?
>>
> 
> The goal is to import the environment from a shell script into the 
> current Perl scripts environment.  To do this, I am sourcing the shell 
> script and printing it's environment to standard output:
> 
> qx{
>   . /shell/script.sh
>   perl -MData::Dumper -e "print Dumper(\\\%ENV)"
> }
> 
> This is occurring within a containing Perl script that rebuilds the hash 
> from Data::Dumper's output and then cycles through the hash picking out 
> changed environment variables.
> 
> I've gotten everything working pretty well right now, but am having to 
> turn off strict 'vars' for this hash-rebuilding section.
> 
> Thanks for all of your help!

I finally found the answer... Data::Dumper returns it's output as:

	$VAR1 = { ...

In this case, $VAR1 is not scoped, so strict complains.  When I changed 
the code to:

perl -MData::Dumper -Mstrict -e 'print join "\n", keys %{eval('my ' . 
`perl -MData::Dumper -e "print Dumper(\\\%ENV)"`)}'

it worked.

Thanks again for all of the help.


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

Date: 5 Feb 2005 15:52:15 GMT
From: mjl69 <mjl69mjl69@myaccmyacc.net>
Subject: Exception handling in class: question
Message-Id: <36k8dfF5561e0U1@individual.net>



package MyClass;


use warnings;
use strict;

sub new
{
	my $invocant = shift;
	my $dbh = shift;
	my $class = ref($invocant) || $invocant;  # Object or class name
	my $self = { };
	$self->{_error} = '';
	bless($self, $class);
	return $self;
}
sub error
{
	my $invocant = shift;
	return $invocant->{_error};
}
### Is error handling ok or...
sub my_method
{
	my $invocant = shift;
	my $arg = shift;
	if ($arg == 1)
	{		
		eval
		{
			#do stuff
		};
		if ($@)
		{
			$invocant->{_error} = $@;
			return undef;
		}
		else {return 'success'}
	}
	elsif ($arg ==2)
	{
		eval
		{
			#do stuff
		};
		if ($@)
		{
			$invocant->{_error} = $@;
			return undef;
		}
		else {return 'success'}
	}
	elsif ($arg == 3)
	{
		eval
		{
			#do stuff
		};
		if ($@)
		{
			$invocant->{_error} = $@;
			return undef;
		}
		else {return 'success'}
	}
}
### Is this better?
sub my_method2
{
	my $invocant = shift;
	my $arg = shift;
	eval
	{
		if ($arg == 1)
		{		
			#do stuff
		}
		elsif ($arg ==2)
		{
			#do stuff
		}
		elsif ($arg == 3)
		{
			#do stuff
		}
	};
	if ($@)
	{
		$invocant->{_error} = $@;
		return undef;
	}
	else {return 'success'}
}
### Or, does it just depend on the situation?

### Thanks for advice - mjl


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

Date: 5 Feb 2005 16:19:46 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Exception handling in class: question
Message-Id: <cu2rn2$6tr$1@mamenchi.zrz.TU-Berlin.DE>

mjl69  <mjl69mjl69@myaccmyacc.net> wrote in comp.lang.perl.misc:

[snip 23 lines of code]

> ### Is error handling ok or...

[snip 44 lines of code]

> ### Is this better?

[snip 26 lines of code]

> ### Or, does it just depend on the situation?

Come on.  What is the significant difference?  I'm not going to read
that much code to find out.

Anno


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

Date: 5 Feb 2005 17:14:58 GMT
From: mjl69 <mjl69mjl69@myaccmyacc.net>
Subject: Re: Exception handling in class: question
Message-Id: <36kd8iF4vve10U1@individual.net>


[snip 23 lines of code] 


> ### Is error handling ok or... 

[snip 44 lines of code] 


> ### Is this better? 

[snip 26 lines of code] 


> ### Or, does it just depend on the situation? 

Come on.  What is the significant difference?  I'm not going to read 
that much code to find out. 


Anno 

Should all methods be wrapped in a single eval block as standard practice for exception handling or should they be sprinkled through code where needed?  I was just stating my question in Perl :-)

mjl


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

Date: 5 Feb 2005 17:18:22 GMT
From: mjl69 <mjl69mj...@myaccmyacc.net>
Subject: Re: Exception handling in class: question
Message-Id: <36kdeuF53cns3U1@individual.net>


> [snip 23 lines of code] 
> 
> 
> > ### Is error handling ok or... 
> 
> [snip 44 lines of code] 
> 
> 
> > ### Is this better? 
> 
> [snip 26 lines of code] 
> 
> 
> > ### Or, does it just depend on the situation? 
> 
> Come on.  What is the significant difference?  I'm not going to read 
> that much code to find out. 
> 
> 
> Anno 
> 
> Should all methods be wrapped in a single eval block as standard practice for exception handling or should they be sprinkled through code where needed?  I was just stating my question in Perl :-)
> 
> mjl


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

Date: 5 Feb 2005 18:07:58 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Exception handling in class: question
Message-Id: <cu321u$asq$1@mamenchi.zrz.TU-Berlin.DE>

mjl69  <mjl69mj...@myaccmyacc.net> wrote in comp.lang.perl.misc:
> 
> > [snip 23 lines of code] 
> > 
> > 
> > > ### Is error handling ok or... 
> > 
> > [snip 44 lines of code] 
> > 
> > 
> > > ### Is this better? 
> > 
> > [snip 26 lines of code] 
> > 
> > 
> > > ### Or, does it just depend on the situation? 
> > 
> > Come on.  What is the significant difference?  I'm not going to read 
> > that much code to find out. 
> > 
> > 
> > Anno 
> > 
> > Should all methods be wrapped in a single eval block as standard
> practice for exception handling or should they be sprinkled through code
> where needed?  I was just stating my question in Perl :-)

No, you were hiding your question in Perl verbiage.  Three or five lines
of uncommented code may be okay, near a hundred isn't.  I didn't even see
you used "eval" in the code, not to mention the different ways you use it
in different parts.

As for your question, it is unclear why you use "eval" at all. It is not
the standard error handling mechanism in Perl.  If you must use it, make
its scope as small as possible, that is, treat every case individually.
Only use it if the exception can't be otherwise anticipated.  Don't catch
division by zero that way, for instance.  Standard error handling is
through the standard module Carp.

OTOH, if you deliberately want to use "eval" for exception handling,
take a look at some of the "Exception" modules on CPAN, or write your
own.  Don't use "eval" directly for that.

Anno


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

Date: 5 Feb 2005 04:55:43 -0800
From: hitachi4@rediffmail.com
Subject: Perl for data encryption
Message-Id: <1107608143.270527.129710@o13g2000cwo.googlegroups.com>

Hi all
        I am working on Sybase. There are several databases for which I
want to encrypt the data with keeping the data integrity.
Here I am using a approch to have a mapping file which will contain the
Origianl Value and masked Value. So each time a select a table to mask
the value first I am looking into this mapping file for the presence of
that value. So if it is there I am directly picking of that encrypted
value otherwise generating a new value and putting that value into the
mapping file.
        I am using Perl for the above. But as the data size is huge, it
takes too much time to complete the encryption. Can anybody suggest any
performance improvement tips for the same.


Thanking in advance

-Hitachi.



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

Date: Sun, 06 Feb 2005 01:39:51 +1000
From: Gregory Toomey <nospam@bigpond.com>
Subject: Re: Perl for data encryption
Message-Id: <36k7m8F50i6ovU1@individual.net>

hitachi4@rediffmail.com wrote:

> Hi all
>         I am working on Sybase. There are several databases for which I
> want to encrypt the data with keeping the data integrity.
> Here I am using a approch to have a mapping file which will contain the
> Origianl Value and masked Value. So each time a select a table to mask
> the value first I am looking into this mapping file for the presence of
> that value. So if it is there I am directly picking of that encrypted
> value otherwise generating a new value and putting that value into the
> mapping file.
>         I am using Perl for the above. But as the data size is huge, it
> takes too much time to complete the encryption. Can anybody suggest any
> performance improvement tips for the same.
> 
> 
> Thanking in advance
> 
> -Hitachi.

Maybe a symmetric cipher like RC4
http://search.cpan.org/~dbrobins/Net-SSH-Perl-1.26/lib/Net/SSH/Perl/Cipher/RC4.pm

gtoomey


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

Date: 5 Feb 2005 18:40:15 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: perl style: can I combine two steps into one?
Message-Id: <cu33uf$asq$2@mamenchi.zrz.TU-Berlin.DE>

John Bokma  <postmaster@castleamber.com> wrote in comp.lang.perl.misc:
> Michael Slass wrote:


> >|         ++$hack_count{$1};
> 
> I recommend using $hack_count{$1}++;

Why?

Anno


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

Date: 5 Feb 2005 19:03:22 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: perl style: can I combine two steps into one?
Message-Id: <cu359q$cn0$1@mamenchi.zrz.TU-Berlin.DE>

mjl69  <mjl69mj...@myaccmyacc.net> wrote in comp.lang.perl.misc:
> 
> > mjl69 wrote:
> > 
> > [ snip ]
> > 
> > my @report =
> > 
> >     map { [ $_->[ 1 ], $_->[ 0 ] ] }
> >     sort { $b->[ 0 ] <=> $a->[ 0 ] }
> >     map { [ $hack_count{ $_ }, $_ ] }
> >     keys %hack_count; 
> > 
> > Amazing how things can become more readable by careful reformating :-D
> 
> I was just looking for a place to use the Schwartzian Transform.  It is
> kind of a stretch.  He did not really need the elements of the anonymous
> array reversed at the end (the beginning).

It is not a good example to demonstrate the Schwartzian Transform.  Its
point is to avoid the repeated calculation of a sort key by replacing
it with access to a Perl data structure (a list of pairs).  When sorting
by the values of a hash, we already have a data structure that gives
fast access to the sort keys -- the hash itself.  There is little
point in building another for sorting.  That the OP *wants* a very
similar data structure is a different consideration.

On the other hand, the Schwartzian transform doesn't hinge on he fact
that the sort key is the first element of each pair.  Building the
wanted structure from the start and indexing on 1 wouldn't make it
less of one.  The final (top) step is unnecessary and missing now,
so it's only half of a Schwartzian still.

    sort { $b->[ 1] <=> $a->[ 1] }
    map [ $_, $hack_count{ $_}],
    keys %hack_count;

Anno


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

Date: Sat, 05 Feb 2005 05:35:26 GMT
From: gargoyle <gargoyle@no.spam>
Subject: perl telnet (not www) bbs?
Message-Id: <yWYMd.36737$BQ2.542@bignews6.bellsouth.net>

Do they exist?  Google isn't very helpful.  I found something called
Fusion GS, but the links are all broken.

Just wondering...  I'd rather write my own, but at the same time I'd
like to see what's been done before.


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

Date: Sat, 5 Feb 2005 10:23:56 +0000 (UTC)
From: efflandt@xnet.com (David Efflandt)
Subject: Re: perl telnet (not www) bbs?
Message-Id: <slrnd097ls.fao.efflandt@typhoon.xnet.com>

On Sat, 05 Feb 2005 05:35:26 GMT, gargoyle <gargoyle@no.spam> wrote:
> Do they exist?  Google isn't very helpful.  I found something called
> Fusion GS, but the links are all broken.
> 
> Just wondering...  I'd rather write my own, but at the same time I'd
> like to see what's been done before.

Are you looking for a client (Net::Telnet) or a server (like a telnetd)?
Some basic examples of servers are in 'perldoc perlipc'


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

Date: Sat, 05 Feb 2005 14:28:49 GMT
From: gargoyle <gargoyle@no.spam>
Subject: Re: perl telnet (not www) bbs?
Message-Id: <BK4Nd.16958$qJ3.2635@bignews1.bellsouth.net>

On 2005-02-05, David Efflandt <efflandt@xnet.com> wrote:
> Are you looking for a client (Net::Telnet) or a server (like a telnetd)?
> Some basic examples of servers are in 'perldoc perlipc'

No, this is totally different, though I guess it's somewhat close to a
telnet server + login shell in functionality.

I'm talking about oldschool dial-in (and now telnet) BBS software, like
these two (except they're coded in C):
http://daydream.iwn.fi/
http://mconv.sourceforge.net/


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

Date: Sat, 05 Feb 2005 14:55:40 GMT
From: gargoyle <gargoyle@no.spam>
Subject: Re: perl telnet (not www) bbs?
Message-Id: <M75Nd.16959$qJ3.2346@bignews1.bellsouth.net>

On 2005-02-05, gargoyle <gargoyle@no.spam> wrote:
> I'm talking about oldschool dial-in (and now telnet) BBS software

Ah, finally found one written in Perl:
http://karma.sf.net/
Well most of it at least.  It looks like he did the terminal I/O stuff
in C though...


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

Date: 5 Feb 2005 02:55:03 -0800
From: "Mark (News)" <news@mail.adsl4less.com>
Subject: Re: Regular expression woes
Message-Id: <1107600903.924199.17280@z14g2000cwz.googlegroups.com>

Is it true that if zero-width negative look-ahead is not available,
there is always an alternative regex to do the job?



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

Date: 5 Feb 2005 05:47:38 GMT
From: John Bokma <postmaster@castleamber.com>
Subject: Re: Why aren't 'warnings' on by default?
Message-Id: <Xns95F3F20B3A2F9castleamber@130.133.1.4>

Chris Mattern wrote:

> Basically, mjl, it's the cause of probably 90% of the evils in
> software design: backwards compatibility.  -w (the precursor of
> use warnings) as we know it today and the restrictions it puts 
> on your code are relatively recent (of course, in this case 
> "relatively recent" still means over ten years ago...).  Since
> there's a lot of old perl code out there written before this,
> if you made use warnings the default, that code which had been
> running perfectly fine would suddenly start emitting warnings.
> This would make a lot of people unhappy...
 
Yup. I have been working 2 years ago on a huge Perl project, and one of the 
first things I did was turning strict and warnings on.

I found quite some weird/bad constructions and actual bugs that way, but it 
took a lot of time to got it running under strict and warnings. 

-- 
John                   Small Perl scripts: http://johnbokma.com/perl/
               Perl programmer available:     http://castleamber.com/
            Happy Customers: http://castleamber.com/testimonials.html
                        


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

Date: Sat, 05 Feb 2005 07:13:45 GMT
From: "Peter Wyzl" <wyzelli@yahoo.com>
Subject: Re: Why aren't 'warnings' on by default?
Message-Id: <Jm_Md.148136$K7.19555@news-server.bigpond.net.au>

"John Bokma" <postmaster@castleamber.com> wrote in message 
news:Xns95F3F20B3A2F9castleamber@130.133.1.4...
: Chris Mattern wrote:
:
: > Basically, mjl, it's the cause of probably 90% of the evils in
: > software design: backwards compatibility.  -w (the precursor of
: > use warnings) as we know it today and the restrictions it puts
: > on your code are relatively recent (of course, in this case
: > "relatively recent" still means over ten years ago...).  Since
: > there's a lot of old perl code out there written before this,
: > if you made use warnings the default, that code which had been
: > running perfectly fine would suddenly start emitting warnings.
: > This would make a lot of people unhappy...
:
: Yup. I have been working 2 years ago on a huge Perl project, and one of 
the
: first things I did was turning strict and warnings on.
:
: I found quite some weird/bad constructions and actual bugs that way, but 
it
: took a lot of time to got it running under strict and warnings.

First thing I do when looking at someone else's code is turn them both on, 
and look at the resultant errors/warnings.

A recent example is a publicly available 'blogging' script that does use 
'my' declarations, but inappropriately (ie, declares the same variable name 
three times in the same scope - 'declaraton masks earlier in same scope'). 
That gives some idea about the types of problems to be encountered 
elsewhere.  Gives you some idea of what the original programmer does or 
doesn't know.

P
-- 
print "Just another Perl Hacker";




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

Date: 5 Feb 2005 17:29:52 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Why aren't 'warnings' on by default?
Message-Id: <cu2vqg$9m5$1@mamenchi.zrz.TU-Berlin.DE>

John Bokma  <postmaster@castleamber.com> wrote in comp.lang.perl.misc:
> Chris Mattern wrote:

[...]

> > there's a lot of old perl code out there written before this,
> > if you made use warnings the default, that code which had been
> > running perfectly fine would suddenly start emitting warnings.
> > This would make a lot of people unhappy...
>  
> Yup. I have been working 2 years ago on a huge Perl project, and one of the 
> first things I did was turning strict and warnings on.
> 
> I found quite some weird/bad constructions and actual bugs that way, but it 
> took a lot of time to got it running under strict and warnings. 

A general recommendation is to make old code warnings-clean, but not to
bother with strict "vars" (the hard part of strict).  As you have observed,
it takes a lot of time, and you don't gain very much with a program that
was written without a view to lexical scope.  Variables simply won't *have*
the small scope they could have, and changing that is far from trivial.

Of course, if the code has a long future ahead it may pay to do the
necessary partial re-write.  Hey, "Refactoring Perl 4 to 5" would
have been a big success... ten years ago.

Anno


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

Date: 5 Feb 2005 17:35:12 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Why aren't 'warnings' on by default?
Message-Id: <cu304g$9m5$2@mamenchi.zrz.TU-Berlin.DE>

Big and Blue  <No_4@dsl.pipex.com> wrote in comp.lang.perl.misc:
> Peter Scott wrote:
> > 
> > Many people, myself included, agree with you.  Even
> > the perl man page is on your side:
> > 
> > 	BUGS
> >                The -w switch is not mandatory.
> 
>     However, if you have to remember to switch it on it might switch on 
> other parts of your brain, and that will help with your coding.

Doesn't work.  Once you decide to use strict and warnings regularly, you'll
find means (like a template file), that let you forget about coding them
every time.

Anno


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

Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 6 Apr 01)
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: due to the current flood of worm email banging on ruby, the smtp
server on ruby has been shut off until further notice. 

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 V10 Issue 7741
***************************************


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