[18810] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 978 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu May 24 18:06:23 2001

Date: Thu, 24 May 2001 15:05:23 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <990741923-v10-i978@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Thu, 24 May 2001     Volume: 10 Number: 978

Today's topics:
        $? after close <nickmarkham@mailandnews.com>
    Re: $? after close <ren@tivoli.com>
        $^O value for PERL on a Macintiosh <leona_browning@hotmail.com>
    Re: ActivePerl <andy@wood7.fsbusiness.co.uk>
    Re: Array slice: how about the remainder? <mischief@velma.motion.net>
    Re: Array slice: how about the remainder? <krahnj@acm.org>
    Re: Calling function reference <kris.verbeeck@chello.be>
    Re: Calling function reference <kris.verbeeck@chello.be>
    Re: Calling function reference <uri@sysarch.com>
    Re: Capturing STDERR in backticked cmd (in W98) <mischief@velma.motion.net>
        Converting VB to PERL (passing parameters) <roinestad@hot_no_spam_mail.com>
    Re: date question <gtoomey@usa.net>
    Re: DBI Microsoft SQL Server. <fty@mediapulse.com>
        dbi, fork and ipc-shareable - having problems <djberge@uswest.com>
    Re: easiest way to find no. of keys in a hash (Craig Berry)
        find executable files only <cinglesi@puc.cl>
        getting perl internal calculated hash value? (Mike Eggleston)
    Re: Hash reference and copying <mischief@velma.motion.net>
    Re: Help slim down Perl code (Sweth Chandramouli)
    Re: Help slim down Perl code <uri@sysarch.com>
    Re: How to match the password created in Linux shadow s <mischief@velma.motion.net>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Thu, 24 May 2001 15:16:24 -0400
From: "Nicholas R. Markham" <nickmarkham@mailandnews.com>
Subject: $? after close
Message-Id: <9ejmj8$1if2$1@newsfeeds.rpi.edu>

As I understand it, when I close a file handle that's a pipe, the exit
status of the program the pipe is connected to should get put in $?.  It
appears to me, however, that $? is actually 256 times the exit status.  Is
this what's supposed to happen?



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

Date: 24 May 2001 14:48:20 -0500
From: Ren Maddox <ren@tivoli.com>
Subject: Re: $? after close
Message-Id: <m3k836bkaj.fsf@dhcp9-172.support.tivoli.com>

On Thu, 24 May 2001, nickmarkham@mailandnews.com wrote:

> As I understand it, when I close a file handle that's a pipe, the
> exit status of the program the pipe is connected to should get put
> in $?.  It appears to me, however, that $? is actually 256 times the
> exit status.  Is this what's supposed to happen?

From perlvar(1):

     $?      The status returned by the last pipe close, backtick
             (``) command, or system() operator.  Note that this
             is the status word returned by the wait() system
             call (or else is made up to look like it).  Thus,
             the exit value of the subprocess is actually ($? >>
             8), and $? & 127 gives which signal, if any, the
             process died from, and $? & 128 reports whether
             there was a core dump.  (Mnemonic: similar to sh and
             ksh.)

So, $? >> 8.

-- 
Ren Maddox
ren@tivoli.com


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

Date: Thu, 24 May 2001 22:59:50 +0100
From: "Leona Browning" <leona_browning@hotmail.com>
Subject: $^O value for PERL on a Macintiosh
Message-Id: <9ejt3n$nbk$1@newsg3.svr.pol.co.uk>

Hi
Anyone know what Print $^O returns for Perl runnin on a Macintosh ?

I've used the above method to trap for a windows machine now I need to
isolate some code for Macperl and I dont have access to a Mac

Thanks in advance




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

Date: Thu, 24 May 2001 22:04:44 +0100
From: "Andrew Wood" <andy@wood7.fsbusiness.co.uk>
Subject: Re: ActivePerl
Message-Id: <9ejt6m$3ei$1@news8.svr.pol.co.uk>

Kay

As much as I feel part of the entire world, and learnt a bit of German at
school,
I feel that for the benefit of non-German speaking readers of this
newsgroup,
could you possibly post in English, or find an equivalent German newsgroup.
Eg.  de.comp.lang.perl.misc

Mit freundlichen Grüßen,
Andy


Kay Schulz <kay_schulz@yahoo.com> wrote in message
news:kay_schulz-DC0062.18225623052001@news.t-online.com...
> Hi
> unter UNIX sage ich
> #!/bin/perl
>
> wie mache ich das unter Windows 2000?
> Oder geht das da gar nicht
> ich kann meine Programme mit
> perl Programm
> aufrufen aber dass es selber startet habe ich nicht
> hinbekommen
> Danke
> Kay
>
> --
> Kay Schulz




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

Date: Thu, 24 May 2001 19:12:22 -0000
From: Chris Stith <mischief@velma.motion.net>
Subject: Re: Array slice: how about the remainder?
Message-Id: <tgqn8m4kcv6610@corp.supernews.com>

Godzilla! <godzilla@stomp.stomp.tokyo> wrote:
> John W. Krahn wrote:
>  
>> Chris Stith wrote:

> (snipped)

>> According to my tests only nobull's, MJD's, and mine produced the
>> correct results (I couldn't test Joe's as I don't have 5.6)
>> If you just want fast code that produces random or nonexistant results I
>> can do that too. :-)

Neither of mine worked? Gee, that's a pity. I wish someone else
would test mine, because they work on two versions of perl for
me. 

[snip]

> Chris Stith tested the same codes along with codes written
> by himself, Anno Siegel and NoBull. There is no indication
> of any problems in Chris Stith's article.

If there are any problems with my post, it would most likely
be in my own code. I tested it myself, but I welcome anyone
to test it as well.

Ren's works well -- it's the same as Joe's except it eliminates
the deleted array elements that Joe's does not. If you had 5.6.x,
you'd be able to tell they both give the same results (except
for the printing of extra spaces around the deleted array elements
for Joe's) in my test script as do MJD's and nobull's.

I get the same results for Anno's, John Lin's, Kira's, both of
mine, MJD's, Ren's and nobull's give the exact same printout
under this test script skeleton (except MJD's leaves @chosen
in a different order):

    #!/usr/local/bin/perl -w
    use strict;
    use diagnostics;

    my @array = (0..19);
    my @chosen = (1..5,17..18);
    my @go_picnic = @array[@chosen];  # those who are chosen go picnic

    ### code to be tested goes here

    print "@chosen\n";
    print "@stay_home\n";

To be more clear about John Lin's method, I copied the version 
he posted at Date: 2001-05-22 19:21:40 PST, which was in response
to a post of mine. I'm not sure if that's the same as any of the
others he posted.

> Perhaps your bruised ego is speaking on your behalf?

I would certainly hope John Krahn's ego is not bruised because
I did not benchmark his code. I didn't recognize the name
John W. Krahn, and frankly I didn't know it would be important
to him. So, John K., if you're reading this, I'm sorry I didn't
benchmark your methods (I see two that you posted). I still don't
see how you can claim that Ren, Kira, Anno, and John Lin didn't
post working code.

If there's still some discrepancies about someone's code, I can
post my benchmark source. I did make a couple of very minor
changes to other people's code for the benchmarks -- I added 'my'
a couple of places to make one run under strict and I benchmarked
against nobull's without the call to sort (which he suggested
could be a good idea in his post).

Chris

-- 
Programming is a tool. A tool is neither good nor evil. It is
the user who determines how it is used and to what ends.



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

Date: Thu, 24 May 2001 20:19:02 GMT
From: "John W. Krahn" <krahnj@acm.org>
Subject: Re: Array slice: how about the remainder?
Message-Id: <3B0D6CD5.E855C69F@acm.org>

Chris Stith wrote:
> 
> > John W. Krahn wrote:
> >> According to my tests only nobull's, MJD's, and mine produced the
> >> correct results (I couldn't test Joe's as I don't have 5.6)
> >> If you just want fast code that produces random or nonexistant results I
> >> can do that too. :-)
> 
> Neither of mine worked? Gee, that's a pity. I wish someone else
> would test mine, because they work on two versions of perl for
> me.

$ perl -v

This is perl, version 5.005_03 built for i586-linux

> If there are any problems with my post, it would most likely
> be in my own code. I tested it myself, but I welcome anyone
> to test it as well.

From the two_loops code that you posted the other day.

my @array = ( 'AA' .. 'DV' );
my @chosen = (0,3,5,7,21,35,63,66,68);
print 'Size of @array = ', scalar @array, "\n\@array = @array\n";
print 'Size of @chosen = ', scalar @chosen, "\n\@chosen = @chosen\n\n";

#sub two_loops {
my @go_picnic = @array[ @chosen ];  # those who are chosen go picnic
my @stay_home = ();
my $vec = 0;
for( @chosen ) {
    vec( $vec, $_, 1) = 1;
    }
for( my $i = 0; $i < @array; $i++ ) {
    unless( vec($vec, $i, 1) ) {
        push @stay_home, $array[$i];
        }
    }
print 'Size of @stay_home = ', scalar @stay_home, "\n\@stay_home =
@stay_home\n";
print 'Size of @go_picnic = ', scalar @go_picnic, "\n\@go_picnic =
@go_picnic\n\n";
#}
__END__

$ try-as.pl
Size of @array = 100
@array = AA AB AC AD AE AF AG AH AI AJ AK AL AM AN AO AP AQ AR AS AT AU
AV AW AX AY AZ BA BB BC BD BE BF BG BH BI BJ BK BL BM BN BO BP BQ BR BS
BT BU BV BW BX BY BZ CA CB CC CD CE CF CG CH CI CJ CK CL CM CN CO CP CQ
CR CS CT CU CV CW CX CY CZ DA DB DC DD DE DF DG DH DI DJ DK DL DM DN DO
DP DQ DR DS DT DU DV
Size of @chosen = 9
@chosen = 0 3 5 7 21 35 63 66 68

Size of @stay_home = 90
@stay_home = AB AC AG AI AJ AK AL AM AN AO AP AQ AR AS AT AU AW AX AY AZ
BA BB BC BD BE BF BG BH BI BK BL BM BN BO BP BQ BR BS BT BU BV BW BX BY
BZ CA CB CC CD CE CF CG CH CI CJ CK CM CN CP CR CS CT CU CV CW CX CY CZ
DA DB DC DD DE DF DG DH DI DJ DK DL DM DN DO DP DQ DR DS DT DU DV
Size of @go_picnic = 9
@go_picnic = AA AD AF AH AV BJ CL CO CQ


You will notice that the element "AE" does not show up in either array.


John
-- 
use Perl;
program
fulfillment


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

Date: Thu, 24 May 2001 18:30:20 GMT
From: Kris Verbeeck <kris.verbeeck@chello.be>
Subject: Re: Calling function reference
Message-Id: <3B0D542E.250B55AE@chello.be>

Uri Guttman wrote:

>   n> If it is possible to do so the best solution is simply to switch to
>   n> using hard references:
> 
>   n> my $func = 'doit'; # Sybolic ref
>   n> my $func = \&doit; # Hard ref
> 
> so if that is the best solution, why did you even clear up his symref
> problem?

I'm glad he cleared it up because the reference is defined as a string
in a configuration file, i.e. symbolic reference

> a dispatch table is very easy to create and use and is safe.

And need it to be much more dynamic than that.


but thanks anyway for the tips.


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

Date: Thu, 24 May 2001 18:32:31 GMT
From: Kris Verbeeck <kris.verbeeck@chello.be>
Subject: Re: Calling function reference
Message-Id: <3B0D54B2.BD1EE800@chello.be>

Kris Verbeeck wrote:

> And need it to be much more dynamic than that.

I meant "I need it..."


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

Date: Thu, 24 May 2001 18:48:29 GMT
From: Uri Guttman <uri@sysarch.com>
Subject: Re: Calling function reference
Message-Id: <x7ae424m81.fsf@home.sysarch.com>

>>>>> "KV" == Kris Verbeeck <kris.verbeeck@chello.be> writes:

  >> so if that is the best solution, why did you even clear up his symref
  >> problem?

  KV> I'm glad he cleared it up because the reference is defined as a string
  KV> in a configuration file, i.e. symbolic reference

no, you can still do a dispatch table. you are not thinking clearly here.

  >> a dispatch table is very easy to create and use and is safe.

  KV> And need it to be much more dynamic than that.

and why is a symbolic ref more dynamic than hard refs for subs? you have
not made any points for that argument.

you will eventually shoot yourself in the foot (or head) if you let sub
calls be directly made with symrefs.

uri

-- 
Uri Guttman  ---------  uri@sysarch.com  ----------  http://www.sysarch.com
SYStems ARCHitecture and Stem Development ------ http://www.stemsystems.com
Learn Advanced Object Oriented Perl from Damian Conway - Boston, July 10-11
Class and Registration info:     http://www.sysarch.com/perl/OOP_class.html


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

Date: Thu, 24 May 2001 21:46:55 -0000
From: Chris Stith <mischief@velma.motion.net>
Subject: Re: Capturing STDERR in backticked cmd (in W98)
Message-Id: <tgr0af5411t58f@corp.supernews.com>

pt <mnemotronic@mind\no-spam/spring.com> wrote:
>     I'm trying to redirect STDERR to STDOUT so that I can capture both
> STDERR and STDOUT output of a backticked command.  I've tried the
> suggested:

> @Results = `$cmd 2>&1` ;

>     I don't understand how that would work under Windows ... The I/O
> redirection looks like a unixy kinda thing.

>     My idea is:

> {
>    local *STDERR = *STDOUT ;
>    @Results = `$cmd` ;
> }

>     This works when "$cmd" names an EXE with params (i.e. "get blah.blah
> *.??v"), but not when "$cmd" is a BATCH file which itself runs
> executables (specifically, various cross-compiling tools from Tasking

This is because the batch file is being interpreted by your
command interpreter, which is then running _another_ program.
Even if you grab the command interpreter's STDERR, you can't
really coerce it into grabbing the STDERR of the program it is
running for you. 

> .... formerly BSO).  When running the BATCH I just get the STDOUT.
> STDERR still goes to the console.
>     Environment is W98SE running from a DOS window with ActiveState.

I'm not sure there's a way to do this, short of replacing the
batch files with full-fledged programs which capture the
output and pass it on, or duplicating the actions of the
batch files in your own program in the first place.

Chris
-- 
Ooweeooo I look just like Buddy Holly, and you're Mary Tyler Moore.
I don't care what they say about us anyway. No I don't care about
that! -- Weezer, "Buddy Holly"


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

Date: Thu, 24 May 2001 15:07:09 -0600
From: Michael Roinestad <roinestad@hot_no_spam_mail.com>
Subject: Converting VB to PERL (passing parameters)
Message-Id: <3B0D77FD.784EAD3@hot_no_spam_mail.com>

Greetings,
    I am trying to use an ActiveX function that will fill out two
Variant array of doubles.  The problem is I do not know how to pass
these variables in a manner that they can be filled out like they do in
VB.

The setup for VB is as follows:
----------------------------------------------------------------------------------

Dim minExt As Variant
Dim maxExt As Variant

' Return the bounding box for the line and return the minimum
' and maximum extents of the box in the minExt and maxExt variables.

lineObj.GetBoundingBox minExt, maxExt
' minExt would contain for example [ 0.0 0.0 0.0 ] and extMax would
contain [ 1.0 1.0 0.0 ].
----------------------------------------------------------------------------------

I have tried different combinations for hours can't seem to find a
situation that works.  Here is some of the methods I have tried.

$Entity->GetBoundingBox($minPoint, $maxPoint);
- or -
my $minPoint = Variant(VT_R8 | VT_ARRAY | VT_BYREF, qw(0 0 0));
my $maxPoint = Variant(VT_R8 | VT_ARRAY | VT_BYREF, qw(0 0 0));
$Entity->GetBoundingBox($minPoint, $maxPoint);
- or -
$Entity->GetBoundingBox(\$minPoint, \$maxPoint);
- or -
$Entity->GetBoundingBox(@$minPoint, @$maxPoint);

Any help at all would be greatly appreciated,
Michael Roinestad




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

Date: Fri, 25 May 2001 07:40:57 +1000
From: "Gregory Toomey" <gtoomey@usa.net>
Subject: Re: date question
Message-Id: <1%eP6.13140$hV3.18157@newsfeeds.bigpond.com>


"Calin Guga" <CalinG@cfgroup.ca> wrote in message
news:227P6.240891$Z2.2673447@nnrp1.uunet.ca...
> Hello there,
>
>     Does anybody know how to convert a date in Perl, for ex. 01/01/2001
and
> to tell what day of the week that was(like Monday...Sunday)?
> Thanks a lot for your help,
> Calin
>

Here's a quick solution:

The two routines below work out days between dates and days of the week
Q.How may days between 15-jan-1999 and 5-jul-2001
A. date_ymd("20010715") - date_ymd("19990105");
Q . What day is 21-mar-2001.
A. weekday(date_ymd("20010321"));

sub date_ymd {
        my($year)=substr($_[0],0,4);
        my($month)=substr($_[0],4,2);
        my($day)=substr($_[0],6,2);
        my(@months) = (0,31,59,90,120,151,181,212,243,273,304,334);
        return
$year*365+int(($year-1)/4)+$months[$month-1]+$day($year%4==0&&$month>=3?1:0)
+5;
}

sub weekday {
        my ($offset)=@_;
        my(@wday) = ( "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" );

        return $wday[$offset%7];
}

gtoomey




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

Date: Thu, 24 May 2001 18:25:36 GMT
From: "Jay Flaherty" <fty@mediapulse.com>
Subject: Re: DBI Microsoft SQL Server.
Message-Id: <AmcP6.128036$ho6.8172769@news5.aus1.giganews.com>


"Vjay LaRosa" <vjayl@emc.com> wrote in message
news:3B0BCC72.1E5F3954@emc.com...
> Hello,
> I was hoping that some one could help me. I need to access a SQL server
7.0 Database on Win2K.
> Does any one have any expierience with this? If so and you are willing to
give me a few pointers

install activestate perl
use ppm to install DBI
use ppm to install DBD::ODBC
read the docs that come with the module.

If you mean to access SQL Server from a linux box then look at:
freeTDS or the dbi proxy. There are also some commercial ODBC-ODBC bridge
software out there (search google groups)
myself, I use the freeTDS driver and then use the DBD::Sybase module.

jay





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

Date: Thu, 24 May 2001 16:09:54 -0500
From: "Mr. Sunray" <djberge@uswest.com>
Subject: dbi, fork and ipc-shareable - having problems
Message-Id: <3B0D78A2.14C2E619@uswest.com>

Hi all,

Perl 5.6 on bughat 6.2.

Ok - I thought I'd try and optimize a series of sql SELECT statements by
forking each one and storing the results in a shared memory object.

Here's the code - I'm reading a series of sql select statements from a
file, fork'ing a child for each one, executing the 'fetch' within the
child and trying to store the results in an array for later retrieval.

The problem seems to be with the shared memory objects.  Either the
array of results grows each time I run the program or else I get "Can't
use an undefined value as an ARRAY reference at
/usr/local/lib/perl5/site_perl/5.6.0/IPC/Shareable.pm line 446, <GEN1>
chunk whatever".

WARNING - be prepared to use 'ipcs' and 'ipcrm' if you want to play with
this script!  You may have stray memory objects floating around
afterwards.

Be sure to run this/your program at least twice to make sure your shared
memory objects aren't "collecting".

#!/usr/local/bin/perl -w

use strict;
use DBI;
use DBD::Oracle;
use IPC::Shareable;
use IO::File;

use constant DB => 'myDB';
use constant USER => 'user';
use constant PASSWD => 'passwd';
use constant DRIVER => 'Oracle';

# File contains 4 sql SELECT statements.
# You can use "select sysdate from dual" if you like, so long as it
works.
use constant SQLFILE => 'file.sql';

my($dbh, $sth, @results, @allRecords);
my $if = IO::File->new(SQLFILE) or die "Couldn't open file: $!\n";

# I am not entirely sure what the proper settings for these should be.
# I've tried various combinations with no (or bad) luck
my $glue = 'data';
my %options = (create => 'yes', exclusive => 0, mode => 0644)
tie @allRecords, 'IPC::Shareable', $glue, { %options } or die "Tie
failed: $!\n";

$/ = "";  # We're going to read each 'select' statement as an input
record
while(my $query = <$if>){
   chomp($query);

   my $child = fork();
   die "Can't fork: $!\n" unless defined $child;

   if($child == 0){

        # Not sure if I need 'InactiveDestroy' here or not
        $dbh = DBI->connect(DB,USER,PASSWD,DRIVER,
            {RaiseError=>1,PrintError=>1,InactiveDestroy=>1}
        );

        $sth = $dbh->prepare($query);
        $sth->execute();
        while( my $hash_ref = $sth->fetchrow_hashref() ){
            push(@results, $hash_ref);
        }

        #+++++++++++++++++++++++++++++++++++++++++++++
        # '@allRecords' should contain a reference to an array of hash
        # reference for each select statement (thus, four total).
        #+++++++++++++++++++++++++++++++++++++++++++++
        push(@allRecords, \@results);

        $sth->finish();
        $dbh->disconnect();
        exit 0;
    }
}

close($if) or die "Unable to close input file: $!\n";

#+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
# I expect to see four array references here.  When I try this, I either
get "Can't use
# undefined value as an array reference" warnings from the
'Shareable.pm' module
#  or the list keeps growing and growing each time I run the program.
What do I need to do?
#+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
foreach my $ref(@allRecords){
    print "Ref is: $ref\n";
}







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

Date: Thu, 24 May 2001 20:05:56 -0000
From: cberry@cinenet.net (Craig Berry)
Subject: Re: easiest way to find no. of keys in a hash
Message-Id: <tgqqd4t39jkq6b@corp.supernews.com>

R (smrtalec@nospam.earthlink.net) wrote:
: what is the easiest way to find the number of keys ( entries) in a hash ?

Evaluate 'keys %hash' in a scalar context.

-- 
   |   Craig Berry - http://www.cinenet.net/~cberry/
 --*--  "God becomes as we are that we may be as he is."
   |               - William Blake


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

Date: Thu, 24 May 2001 16:34:06 -0400
From: "Claudio Inglesi" <cinglesi@puc.cl>
Subject: find executable files only
Message-Id: <GeeP6.6911$cy3.140007@maule>

Does anyone know how to use the find command so that it only finds files
that are executable (files whose permissions are set as executable for the
user, group or everybody).
Thanks.
Claudio Inglesi
Chile - South America




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

Date: Thu, 24 May 2001 20:46:04 GMT
From: mikee@kensho.eggtech.com (Mike Eggleston)
Subject: getting perl internal calculated hash value?
Message-Id: <slrn9gqsoc.dae.mikee@kensho.eggtech.com>


I have a desire to look at the hash value that perl has generated
for the entries in a given hash. I know how to manipulate the
hash, but I have never before thought of just what perl call
a given hash.

Anyone know?

Mike


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

Date: Thu, 24 May 2001 21:02:15 -0000
From: Chris Stith <mischief@velma.motion.net>
Subject: Re: Hash reference and copying
Message-Id: <tgqtmno1c32o4d@corp.supernews.com>

dave <usted@cyberspace.org> wrote:
> I am grabbing values from a DB using DBI and I get the result via:

> $hash_ref = $sth->fetchrow_hashref('NAME_lc');

> I can then get to the values of each result via:

> $hash_ref->{name_of_field}

> My question is this:  How can I create a real hash from this reference
> instead of dereferencing it in this way?  I would like to do:

> %result = $$hash_ref;

> and then be able to handle %result as a regular hash so that I can
> copy it and strip it out of various things.

Others have shown you how to do this using symbolic references,
which are no stricture clean nor recommended practice.

Try this:
    my %result = %{ $hash_ref };

If you want to figure out how that works, read perlref and perlreftut.
You can read these as HTML at http://www.perldoc.com or on a Windows
system with ActiveState Perl or Indigo Perl, you can read them in
man format on most *n?x boxes, or you can read them using perldoc
anywhere Perl is properly installed.

Chris

-- 
Get real!  This is a discussion group, not a helpdesk. You post
something, we discuss its implications. If the discussion happens to
answer a question you've asked, that's incidental. -- nobull, clp.misc



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

Date: Thu, 24 May 2001 18:58:56 GMT
From: sweth+perl@gwu.edu (Sweth Chandramouli)
Subject: Re: Help slim down Perl code
Message-Id: <QRcP6.26059$G5.4736722@news1.rdc1.md.home.com>

In article <x7g0du4pbz.fsf@home.sysarch.com>,
Uri Guttman  <uri@sysarch.com> wrote:
>symrefs and eval should only be used when there is absolutely no other
>way to do it. a few areas that qualify are generating perl code on the
>fly (not closures, but perl text), and installing things in the symbol
>table (as done with Exporter and in some AUTOLOAD uses). there are a few
>other places as well and those areas are generally for experts so the
>rule is no symrefs or eval unless you know why you must use them.
	Do you count giving variables more user-friendly names
among the valid uses?  I occasionally have code with blocks like

for my $option (keys %options) {
   my $varname;
   if (defined ($options{$option}{varname})) {
      no strict 'refs';
      $varname = $options{$option}{varname}
      if (defined ($options{$option}{value})) {
         $$varname = $options{$option}{value}
      } else {
         $$varname = $options{$option}{default}
      };
   };
};

	, where one of the keys for %options might be, say, "debug",
which I know I will be testing against quite often; rather than typing out
$options{debug}{value} every time, I can just define $options{debug}{varname}
to be 'debug', and reference $::debug in my tests later.  It's not the
prettiest solution, but I'm not sure that it's pure evil.

	-- Sweth.

-- 
Sweth Chandramouli ; <sweth+perl@gwu.edu>


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

Date: Thu, 24 May 2001 20:41:08 GMT
From: Uri Guttman <uri@sysarch.com>
Subject: Re: Help slim down Perl code
Message-Id: <x74rua4h0c.fsf@home.sysarch.com>

>>>>> "SC" == Sweth Chandramouli <sweth> writes:

  SC> In article <x7g0du4pbz.fsf@home.sysarch.com>,
  SC> Uri Guttman  <uri@sysarch.com> wrote:
  >> symrefs and eval should only be used when there is absolutely no other
  >> way to do it. a few areas that qualify are generating perl code on the

  SC> 	Do you count giving variables more user-friendly names
  SC> among the valid uses?  I occasionally have code with blocks like

  SC> for my $option (keys %options) {
  SC>    my $varname;
  SC>    if (defined ($options{$option}{varname})) {
  SC>       no strict 'refs';
  SC>       $varname = $options{$option}{varname}
  SC>       if (defined ($options{$option}{value})) {
  SC>          $$varname = $options{$option}{value}
  SC>       } else {
  SC>          $$varname = $options{$option}{default}
  SC>       };
  SC>    };
  SC> };

  SC> 	, where one of the keys for %options might be, say, "debug",
  SC> which I know I will be testing against quite often; rather than typing out
  SC> $options{debug}{value} every time, I can just define $options{debug}{varname}
  SC> to be 'debug', and reference $::debug in my tests later.  It's not the
  SC> prettiest solution, but I'm not sure that it's pure evil.

you can take a ref to the location and just use $$debug.

you can define a closure that has the debug flag as a value and call
that instead

you can manage the namespace with the Exporter which is safer than you
doing it yourself.

plenty of other ways to do it without using symrefs (or only indirectly
with exporter).

it is not the case that symrefs are pure evil. but the ease of which
people think they are useful is the problem. they are used all the time
when you use modules that export stuff, but the code that does the
symref stuff is isolated and stable. if you roll your own symref code it
is highly likely it will break one day.

i use symrefs in once case to install closure methods in an
AUTOLOAD. but that is very isolated and stable.

seeing symrefs used (and promoted) for data structures is the biggest
evil use as that is never needed.

uri

-- 
Uri Guttman  ---------  uri@sysarch.com  ----------  http://www.sysarch.com
SYStems ARCHitecture and Stem Development ------ http://www.stemsystems.com
Learn Advanced Object Oriented Perl from Damian Conway - Boston, July 10-11
Class and Registration info:     http://www.sysarch.com/perl/OOP_class.html


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

Date: Thu, 24 May 2001 19:21:54 -0000
From: Chris Stith <mischief@velma.motion.net>
Subject: Re: How to match the password created in Linux shadow suite?
Message-Id: <tgqnqi7djus7fb@corp.supernews.com>

Joel Ray Holveck <joelh@juniper.net> wrote:
>>> Variable $p is my login password and $passwd is my encripted password
>>> in /etc/shadow, after I run the script, I got ...
>>> % shadow_match.pl
>>> $1$QR/J8Kwx$l8A4IHdLZylsCALdmhy30.,$1p327sCxfpMs
>>> no match
>>> Am I doing it correctly?
>> Sorta.
>> You're using a DES crypt routine to match an MD5 password.
>> Use Crypt::PasswordMD5 or something similar from the CPAN.

> I thought that Perl crypt used the system's libc crypt so it would get
> MD5, etc for free.  Am I mistaken?

Certain systems don't seem to work this way. When using PAM for
authentication, for example, the method within PAM can be switched
by configuration between shadowed and unshadowed passwords, and
different handlers can be installed for any PAM-based authentication
method. I've run across several systems (particularly RedHat Linux
but others as well) which can also be configured for either DES or MD5.

The DES crypt and the MD5 crypt are often both available somewhere
on the system, in case application programs need the DES crypt
routine. Therefore, I've had occasion to use the Crypt::PasswordMD5
module on systems where Perl's crypt points to DES and the system
password file uses MD5 with PAM.

I've also run across a thread not long ago in which the OP had
two machines, one MD5 and one DES, on which he wanted to run the
same Perl program. Crypt::PasswordMD5 was my recommendation then
as well. That should be easy enough to find on http://groups.google.com
if anyone is interested.

Chris

-- 
People understand instinctively that the best way for computer programs to
communicate with each other is for each of the them to be strict in what they
emit, and liberal in what they accept. The odd thing is that people themselves
are not willing to be strict in how they speak, and liberal in how they listen.
 -- Larry Wall, 2nd State of the Onion Address, August 1998



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

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.  

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 978
**************************************


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