[12314] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 5914 Volume: 8

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Jun 7 18:07:21 1999

Date: Mon, 7 Jun 99 15:00:23 -0700
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Mon, 7 Jun 1999     Volume: 8 Number: 5914

Today's topics:
    Re: [Question]: Finding a file pattern (Tad McClellan)
        Address Resolution Using Perl to Query Exchange <Mike.McKinlay@hboc.com>
    Re: Amazon-like Restaurant Review/Rating Script Needed <rootbeer@redcat.com>
        cookies <mark@sparkyland.demon.co.uk>
    Re: cookies <upsetter@ziplink.net>
    Re: FAQ 7.14: How can I pass/return a {Function, FileHa <*@qz.to>
    Re: HELP: Can't find winsock.h / .ph !!! <gellyfish@gellyfish.com>
        How to package up perl scripts and interpreter for ship lvirden@cas.org
    Re: How to package up perl scripts and interpreter for  <dtbaker@bus-prod.com>
    Re: Is (surprisingly, amazingly) slow? <aqumsieh@matrox.com>
    Re: left$ in basic -- also in perl? (Philip 'Yes, that's my address' Newton)
        Log idle users off UNIX server script avramil@my-deja.com
    Re: Looking for a shopping cart script!!! kteicher@apk.net
    Re: NT Services <gellyfish@gellyfish.com>
    Re: Password Generator <*@qz.to>
        perl and win *.dll <ytong@club-internet.fr>
    Re: Perl/RE savvy??? (Ilya Zakharevich)
    Re: Possible compiler error when passing associative ar <gellyfish@gellyfish.com>
    Re: Possible compiler error when passing associative ar <jeromeo@atrieva.com>
    Re: Possible compiler error when passing associative ar <sugalskd@netserve.ous.edu>
    Re: read-accessing hash element implicitely defines has <aqumsieh@matrox.com>
        Split <perini@buffalo.edu>
    Re: Syntax for square roots? <jdporter@min.net>
    Re: Unzipping Files for WebTV <gellyfish@gellyfish.com>
        Using string variable as name of subroutine to call <tlawrence@globix.com>
    Re: Using string variable as name of subroutine to call (Tad McClellan)
    Re: Using string variable as name of subroutine to call <uri@sysarch.com>
    Re: Wanted-Web Builder Seeking Fame & Fortune <gellyfish@gellyfish.com>
    Re: Win32:  How to set PW for a service that logs in as <xrxoxtxhxdx@xrxoxtxhx.xnxextx>
        Special: Digest Administrivia (Last modified: 12 Dec 98 (Perl-Users-Digest Admin)

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

Date: Mon, 7 Jun 1999 11:06:39 -0400
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: [Question]: Finding a file pattern
Message-Id: <v5ngj7.80o.ln@magna.metronet.com>

VGOEL (Vgoel@cris.com) wrote:

: I am at my wits end.  I have checked the FAQs, the Perl Cookbook and the
: Camel book but I cannot figure out how to do this.  I am basically calling a
: sub like ProcessArgs($dirname, $filepat).  Here is the code snippet of
: ProcessArgs:

: sub ProcessArgs {

: my @x = split (/\;/, $_[0]);
: my $i;
: foreach $i (@x) {
: print "checking $i\n";
: opendir(DH, $i);


   You should check the return value from opendir() just like for open().

   ... but you do not need opendir() at all if you are going to 
   glob() anyway.

   [ It is better, generally, to forsake glob() in favor of
     opendir/readdir/grep though!
   ]

: my @files;
: my @files = glob("$_[1]");


   This will search in the current directory.

   You either need to chdir() or modify the glob:

      my @files = glob("$dir/$_[1]");

: print "@files\n";
: closedir(DH);}
: }

: But this does not seem to work.  This code should basically sniff out the
: $_[0] dir for all patterns matching $_[1] and return the $_[1].  I know I am
: a morono so please point me to the right direction for tackling this
: problem.


   Forget about filename globbing.

   Do it with opendir() and friends instead.


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


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

Date: Mon, 7 Jun 1999 16:18:14 -0500
From: "Michael J. McKinlay" <Mike.McKinlay@hboc.com>
Subject: Address Resolution Using Perl to Query Exchange
Message-Id: <7jhcpe$24g$1@isrv1.hbocvan.com>

I've seen some hints and ideas floating around -- is there anyone actually
using perl LDAP to query an Exchange server to resolve an address?

We have an app on IIS that can generate SMTP mail, but you have to know the
proper address.  Resolving the username against Exchange will give us the
SMTP address.

We could probably employ an ActiveX control here but want to stay within the
confines of basic perl and HTML.

Thanks in advance,
Mike McKinlay
Senior Technical Consultant
McKessonHBOC







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

Date: Mon, 7 Jun 1999 13:38:46 -0700
From: Tom Phoenix <rootbeer@redcat.com>
Subject: Re: Amazon-like Restaurant Review/Rating Script Needed
Message-Id: <Pine.GSO.4.02A.9906071338060.17029-100000@user2.teleport.com>

On Sun, 6 Jun 1999, Dr. Excel wrote:

> I'm dying to find a script that can handle my needs.

No need to die for that....

If you're wishing merely to _find_ (as opposed to write) programs,
this newsgroup may not be the best resource for you. There are many
freeware and shareware archives which you can find by searching Yahoo
or a similar service. Hope this helps!

-- 
Tom Phoenix       Perl Training and Hacking       Esperanto
Randal Schwartz Case:     http://www.rahul.net/jeffrey/ovs/



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

Date: Mon, 7 Jun 1999 21:08:50 +0100
From: "Mark Lewis" <mark@sparkyland.demon.co.uk>
Subject: cookies
Message-Id: <928786469.24151.0.nnrp-04.c1edbf26@news.demon.co.uk>

hello everybody!

newbie to perl...

does anybody know how to maintame a cookie just for a single browser
session: ie if a user has been authenticated once, I do not want them to be
authenticated again. so when they move between pages they will not be forced
to logon twice.  but I would like to force a user to logon again if it is a
new session within there browser.

hope i'm being clear,

thanks is advance,
sparky




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

Date: Mon, 07 Jun 1999 20:22:18 GMT
From: Scratchie <upsetter@ziplink.net>
Subject: Re: cookies
Message-Id: <_RV63.2163$nn.676971@news.shore.net>

Mark Lewis <mark@sparkyland.demon.co.uk> wrote:
: does anybody know how to maintame a cookie just for a single browser
: session: ie if a user has been authenticated once, I do not want them to be
: authenticated again. so when they move between pages they will not be forced
: to logon twice.  but I would like to force a user to logon again if it is a
: new session within there browser.

: hope i'm being clear,

Yes, but it has nothing to do with Perl. If you set a cookie with no
expiration date it should expire when the user closes her browser.

--Art
-- 
--------------------------------------------------------------------------
                    National Ska & Reggae Calendar
                  http://www.agitators.com/calendar/
--------------------------------------------------------------------------


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

Date: 7 Jun 1999 20:23:56 GMT
From: Eli the Bearded <*@qz.to>
Subject: Re: FAQ 7.14: How can I pass/return a {Function, FileHandle, Array, Hash, Method, Regex}?
Message-Id: <eli$9906071543@qz.little-neck.ny.us>

In comp.lang.perl.misc, Tom Christiansen  <perlfaq-suggestions@perl.com> wrote:
> (This excerpt from perlfaq7 - Perl Language Issues 
>     ($Revision: 1.28 $, $Date: 1999/05/23 20:36:18 $)
> part of the standard set of documentation included with every 
> valid Perl distribution, like the one on your system.
> See also http://language.perl.com/newdocs/pod/perlfaq7.html
> if your negligent system adminstrator has been remiss in his duties.)
> 
>   How can I pass/return a {Function, FileHandle, Array, Hash, Method, Regex}?
> 
>     With the exception of regexes, you need to pass references to these
>     objects. See the section on "Pass by Reference" in the perlsub

If you want to pass a compiled regexp (ie from the qr// operator),
then you are passing a reference even if it doesn't seem like it.

#!perl
require 5.005;
my $re = qr/foo/;

print '$re is a ref of type ', ref $re, "\n";
__END__

:r! perl -x %
$re is a ref of type Regexp

Elijah
------
submitting a patch to perlfunc.pod documenting Regexp refs now


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

Date: 7 Jun 1999 20:35:22 -0000
From: Jonathan Stowe <gellyfish@gellyfish.com>
Subject: Re: HELP: Can't find winsock.h / .ph !!!
Message-Id: <7jhaea$6k0$1@gellyfish.btinternet.com>

On Mon, 07 Jun 1999 22:19:47 +1000 silent1@bigpond.com wrote:
> Help!
> 
> I can't find the file winsock.h / winsock.ph which socket.ph in my Perl
> requires!
> 
> Running  Perl 5.00402 for Win95 from CPAN.
> 

I would download the latest Activestate distribution from:

   <http://www.activestate.com/ActivePerl>

It is undoubtedly easier than trying to sort out all the bits that may
be missing from your curreent installation.

/J\
-- 
Jonathan Stowe <jns@gellyfish.com>
Some of your questions answered:
<URL:http://www.btinternet.com/~gellyfish/resources/wwwfaq.htm>
Hastings: <URL:http://www.newhoo.com/Regional/UK/England/East_Sussex/Hastings>


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

Date: 7 Jun 1999 19:29:02 GMT
From: lvirden@cas.org
Subject: How to package up perl scripts and interpreter for shipping
Message-Id: <7jh6hu$ibo$1@srv38s4u.cas.org>

Assume someone has some perl scripts that they wish to ship to a customer.
Assume as well that for whatever reason, the decision is made to ship
a binary perl interpreter to the customer to run said scripts.

Has anyone a technique for determining the minimal libraries to ship
along with the interpreter?  Is there perhaps a technique which
would create a single executable perl interpreter which was completely
self-contained (had no dependencies on additional runtime components
other than the perl script one wanted to run)?
-- 
<URL: mailto:lvirden@cas.org> Quote: Saving the world before bedtime.
<*> O- <URL: http://www.purl.org/NET/lvirden/>
Unless explicitly stated to the contrary, nothing in this posting
should be construed as representing my employer's opinions.


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

Date: Mon, 07 Jun 1999 16:05:01 -0500
From: Dan Baker <dtbaker@bus-prod.com>
Subject: Re: How to package up perl scripts and interpreter for shipping
Message-Id: <375C33FD.726066A@bus-prod.com>



lvirden@cas.org wrote:
> 
> Assume someone has some perl scripts that they wish to ship to a customer.
> Assume as well that for whatever reason, the decision is made to ship
> a binary perl interpreter to the customer to run said scripts.
-------------
http://www.perl2exe.com/
Dan


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

Date: Mon, 7 Jun 1999 13:41:55 -0400 
From: Ala Qumsieh <aqumsieh@matrox.com>
Subject: Re: Is (surprisingly, amazingly) slow?
Message-Id: <x3yso833o2k.fsf@tigre.matrox.com>


"Jonathan" <jonathan@meanwhile.freeserve.co.uk> writes:

> A couple of weeks ago there was a posting on c++ moderated and
> comp.lang.python called "An efficient split function".
> Among other things it contained Perl and Python code to - well, to do this:
> 
> 
>     my $count = 0;
>     my @v;
>     while (<STDIN>) {
>         @v = split(/\|/);
>         $count++;
>     }
>     print "$count\n";
> 
> 
> In other words, to count the total number of field separated data items in a
> file.

Actually, the above code simply counts the number of lines in the
input stream. It's speed really depends on the input, but I will be
very surprised if it is faster in Python than in Perl. What was the
exact Python code?



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

Date: Mon, 07 Jun 1999 19:48:16 GMT
From: nospam.newton@gmx.net (Philip 'Yes, that's my address' Newton)
Subject: Re: left$ in basic -- also in perl?
Message-Id: <375c2116.358767@news.nikoma.de>

[Posted and a courtesy copy mailed]

On Mon, 07 Jun 1999 11:07:57 GMT, Richard Lawrence
<ralawrence@my-deja.com> wrote:

>Bit of a silly question this but I can't seem to find much information
>(I'm probably looking in the wrong place).
>
>In the dim dark depths of time I vaugly remember a left$ command which
>took a string and a number (n) and returned the first n chars so:
>
>  left$("hello",2) = he
>  left$("fish and chips", 7) = fish an
>  left$("bottoms", 99999) = bottoms
>
>Is there any equivilant in Perl? I've been looking through the
>programming perl book and some web help but haven't seemed to see
>anything that would indicate Perl can do this (which I'm sure it can).

What you're looking for is substr(). Have a look in perlfunc for it.
Specifically,

    left$(var$, x) --> substr($var, 0, x)
    mid$(var$, x, y) --> substr($var, x, y)
    mid$(var$, x) --> substr($var, x)
    right$(var$, x) --> substr($var, -x)

Cheers,
Philip

-- 
Philip Newton <nospam.newton@gmx.net>


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

Date: Mon, 07 Jun 1999 20:16:01 GMT
From: avramil@my-deja.com
Subject: Log idle users off UNIX server script
Message-Id: <7jh99r$pc$1@nnrp1.deja.com>

Hello all,

Does anyone know of a perl script that will log users off a UNIX server
after a certain amount of idle time?

If anyone can point me to some code, an ftp site, a URL, etc., it would
be greatly appreciated.

Thanks,

Lou Avrami


Sent via Deja.com http://www.deja.com/
Share what you know. Learn what you don't.


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

Date: Mon, 07 Jun 1999 18:52:03 GMT
From: kteicher@apk.net
Subject: Re: Looking for a shopping cart script!!!
Message-Id: <7jh4cf$uvq$1@nnrp1.deja.com>

http://www.onlineorders.net has tons of shopping cart info.  It
probably has what you need.


In article <7jdh3v$rkt$1@nnrp1.deja.com>,
  suzanne@wbom.com wrote:
> Hi All,
>
> I am in search of a shopping cart script that allows for customers to
> enter and store their info for future orders... sort of like
Amazon.com
> has.
>
> I tried MiniVend but it just never sets up right.. MiniVend is exactly
> what I am looking for, or something very close to it. I don't care if
> its not a free script!!!
>
> Can some one please point me in the direction of something comparible
> to MiniVend or if you have use MiniVend how about some HELP!!! The
damn
> thing is driving me crazy!!!!
>
> Please e-mail me with any help you can provide!
>
> Thanks!
> Suzanne
> suzanne@wbom.com
>
> Sent via Deja.com http://www.deja.com/
> Share what you know. Learn what you don't.
>


Sent via Deja.com http://www.deja.com/
Share what you know. Learn what you don't.


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

Date: 7 Jun 1999 20:53:09 -0000
From: Jonathan Stowe <gellyfish@gellyfish.com>
Subject: Re: NT Services
Message-Id: <7jhbfl$6k3$1@gellyfish.btinternet.com>

On Mon, 7 Jun 1999 16:05:53 +0200 Arjan Huijzer wrote:
> We have a couple of Perl Server-programs that we want to run as a NT
> Service, so the server programs are running in the background and are
> started automatically when our machines reboots.
> 

Someone posted a full explanation on how to do this a while back - if
you do a 'Power Search' in Dejanews <http://www.deja.com> for SRVANY.EXE
in this group then you will almost certainly pop something up.  You
do need the NT server resource kit though.

/J\
-- 
Jonathan Stowe <jns@gellyfish.com>
Some of your questions answered:
<URL:http://www.btinternet.com/~gellyfish/resources/wwwfaq.htm>
Hastings: <URL:http://www.newhoo.com/Regional/UK/England/East_Sussex/Hastings>


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

Date: 7 Jun 1999 21:43:40 GMT
From: Eli the Bearded <*@qz.to>
Subject: Re: Password Generator
Message-Id: <eli$9906071706@qz.little-neck.ny.us>

In comp.lang.perl.misc, Ben Coleman <tnguru@termnetinc.com> wrote:
> NukeEmUp@ThePentagon.com (David Cantrell) wrote:
> 
> >A good method is to use a large dictionary, choose two random words
> >and concatenate them with a random non-alphabetic character in the
> >middle
> 
> A.K.A. "The Compuserve Method".  This works out fairly well as long as you
> keep the words short.

Very easy to implement. Here it is with some capitalization thrown in.

#! perl -w
use strict;
my $dict = '/usr/dict/words';
my @words;

# This will include the null seperator.
my @seps = split(/(.)/, '!@#$%^&*-=+|:;,./');

# These are the salt chars for crypt().
my @salt = ( 'a'..'z', 'A'..'Z', '0'..'9', '.', '/');
srand;

if (@ARGV) {
  print "User\tPassword\tEncrypted password\n";
} else {
  print "Usage: $0 username [...]\n";
}

my $user;
foreach $user (@ARGV) {
  my $pw = &generate;

  print "$user\t$pw\t" . crypt($pw,&salt) . "\n";
}

sub generate () {
  my $out = 'badpassword';

  if (!@words) {
    open DICT, $dict or die "$dict: $!\n";

    # Words must be 3 to 5 letters.
    @words = grep(/^\w{3,5}$/, <DICT>);
    close DICT;
  }

  while ($out =~ /^[a-z]+$/) {
    $out = $words[rand(@words)] . $seps[rand(@seps)];

    $out = ucfirst($out) if rand(4)>1;

    if (rand(4)>1) {
      $out .= ucfirst($words[rand(@words)]);
    } else {
      $out .= $words[rand(@words)];
    }

    # Since we don't chop/chomp our input...
    $out =~ tr/\n//d;

    if (length($out) < 8 ) {
      my $sep = '';
      while(!$sep) {
	$sep = $seps[rand(@seps)];
      }
      $out .= $sep;
    }

  }

  return $out;
}

sub salt () {
  return $salt[rand(@salt)] . $salt[rand(@salt)];
}

__END__

:r! perl -x % alice bob charles deborah evan frances george helen igor jane
User	Password	Encrypted password
alice	Leper|Dark	v44OiMJdIIw0w
bob	Barr=Cane	uqiPKKu7NxMxw
charles	ReckInch	cwMPABoMcQWzA
deborah	Gibbs+eagle	p1wThEhoi52mU
evan	TireGrebe	RY4dk6q3CapV6
frances	Lousy|Delta	mbpSd5B8Yp/K2
george	foil/Poke	/QgJ4UjA3Y9B6
helen	DennyCard	4PxyBbG0eTmuw
igor	ArubaRaul	VUw8ewqquBwfU
jane	Emory;kind	m4zj9bjyPNg8M

Elijah
------
use of a better dictionary left as an exercise for the reader


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

Date: Mon, 07 Jun 1999 21:55:04 +0000
From: YANG Tong <ytong@club-internet.fr>
Subject: perl and win *.dll
Message-Id: <375C3FB8.6FBFCA4F@club-internet.fr>


Hi,

A simple question : the wonderful perl can he handle a *.dll ? 

                            And

Perl can he dialog in a network in native ? Or must I add a module for
dialog in a network ?


Thanks for your comprehensive.



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

Date: 7 Jun 1999 21:46:16 GMT
From: ilya@math.ohio-state.edu (Ilya Zakharevich)
Subject: Re: Perl/RE savvy???
Message-Id: <7jhej8$hsd$1@mathserv.mps.ohio-state.edu>

[A complimentary Cc of this posting was sent to Larry Rosler
<lr@hpl.hp.com>],
who wrote in article <MPG.11c582307bb0900e989b7d@nntp.hpl.hp.com>:
> > Obviously, I could write '/^(des|desc|descr|descri|describ|describe)$/'
> > (which I guess is really the most efficient...) but shouldn't it be
> > possible to write it in a more compact way?
> 
> The best I can do is factor it from the left.  The '(?:' parentheses 
> stop the regex engine from doing unnecessary storing of the intermediate 
> matches.
> 
> /^des(?:c(?:r(?:i(?:be?)?)?)?)?$/i

I do not know which is more readable, but one can achieve the same by

  /^des(c|$)(r|$)(i|$)(be?|$)$/

(though it may be less effecient).  Of course, the proper solution is
to use substr:

   length($input) >= 3 and (substr $pattern, length($input)) eq lc $input

Ilya


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

Date: 7 Jun 1999 21:53:39 -0000
From: Jonathan Stowe <gellyfish@gellyfish.com>
Subject: Re: Possible compiler error when passing associative array
Message-Id: <7jhf13$6ms$1@gellyfish.btinternet.com>

On Mon, 7 Jun 1999 13:10:16 -0500 Lee Pasquali wrote:
> 
> 
> I am converting a perl cgi from perl-v5.001 to perl-v5.005_03. The cgi
> contains code simular to that listed below.
> 
> 
> local ($a, $b, $c, %assoc);
> 
> $a = "a";
> $b = "b";
> $c = "c";
> 
> $assoc{one} = "11";
> $assoc{two} = "22";
> 
> &print_values($a, $b, %assoc, $c);
> 
> 
> 
> sub print_values
> {
> 
>         local($sub_a, $sub_b, %sub_assoc, $sub_c) = @_;
> 
> 
>         print " value passed #1 **$_[0]**\n";
>         print " value passed #2 **$_[1]**\n";
>         print " value passed #3 **$_[2]**\n";
>         print " value passed #4 **$_[3]**\n";
>         print " value passed #5 **$_[4]**\n";
> 
>         print "\n\n";
> 
>         print " sub_a **$sub_a**\n";
>         print " sub_b **$sub_b**\n";
>         for $key (keys %sub_assoc)
>         {
>                 print " sub_assoc - Key: $key Value: $sub_assoc{$key}\n";
>         }
>         print " sub_c **$sub_c**\n";
> 
>         return;
> }
> 
> 
> When this code is executed by perl-v5.001 the following results are
> obtained.
> 
>  value passed #1 **a**
>  value passed #2 **b**
>  value passed #3 **two**
>  value passed #4 **22**
>  value passed #5 **one**
> 
> 
>  sub_a **a**
>  sub_b **b**
>  sub_assoc - Key: one Value: 11
>  sub_assoc - Key: two Value: 22
>  sub_c **c**
> 
> 
> 
> 
> When the code is executed by perl-v5.005_03 the following incorrect results
> are obtained.
> 
>  value passed #1 **a**
>  value passed #2 **b**
>  value passed #3 **two**
>  value passed #4 **22**
>  value passed #5 **one**
> 
> 
>  sub_a **a**
>  sub_b **b**
>  sub_assoc - Key: one Value: 11
>  sub_assoc - Key: two Value: 22
>  sub_assoc - Key: c Value:
>  sub_c ****
> 
> 
> As one can see, perl has a bug such that it does not find the end of the
> associative array correctly in the subroutine.
> 

Bug ?

If you had run this as you should with the -w flag then you would have seen:

Odd number of elements in hash assignment at ./hashthing.pl line 19.
 value passed #1 **a**
 value passed #2 **b**
 value passed #3 **two**
 value passed #4 **22**
 value passed #5 **one**


 sub_a **a**
 sub_b **b**
 sub_assoc - Key: one Value: 11
 sub_assoc - Key: two Value: 22
Use of uninitialized value at ./hashthing.pl line 34.
 sub_assoc - Key: c Value: 
Use of uninitialized value at ./hashthing.pl line 36.
 sub_c ****

Hmm .. Why that ?

The bug is in your code and the clue is the first warning about the Odd
number of elements there ...

You cant pass a hash to a subroutine like that, that is with another
scalar following it in the argument list, because all the elements of
the hash are passed to the subroutine in a flat list - what you are passing
to your subroutine is the list :

  a,b,one,11,two,22,c

Then when you do :

   local($sub_a, $sub_b, %sub_assoc, $sub_c) = @_; 

the first two items in the list from @_ are assigned to $sub_a and $sub_b,
so far so good, however the problem comes when you try to assign to
that hash because it basically sucks up the remaining three items, giving
rise to the warning above and leaving $sub_c undefined.

To fix this you will need to either alter the order of the arguments to
the subroutine so the hash (or indeed an array ) is last in the list
or you will need a pass a reference to the hash which is a scalar.

For the latter you would end up with something like:


#!/usr/bin/perl -w

use strict;

my $a = "a";
my $b = "b";
my $c = "c";

my %assoc = (
              one => '11',
              two => '22'
            );

print_values($a, $b, \%assoc, $c);



sub print_values
{

        my ($sub_a, $sub_b, $sub_assoc, $sub_c) = @_;

        print " sub_a **$sub_a**\n";
        print " sub_b **$sub_b**\n";
        for my $key (keys %{$sub_assoc})
        {
                print " sub_assoc - Key: $key Value: $sub_assoc->{$key}\n";
        }
        print " sub_c **$sub_c**\n";

}

You will also notice that I have altered your local() to my() as that is
most probably what you want to use in this case.

Why the difference in behaviour between 5.001 and 5.005 - I'm sure
someone will come along with the actual reason for the change but it
appears that in the earlier version the hash will only suck up an even
number of items for keys and values, but in the later version it doesnt
try to second guess what you are trying to do - that there is a warning
indicates that this is now deliberate behaviour rather than a bug.  At a
guess I would think that it probably was to achieve consistency between
arrays and hashes when put in a list context like this.

I would check out the perlsub manpage.

/J\
-- 
Jonathan Stowe <jns@gellyfish.com>
Some of your questions answered:
<URL:http://www.btinternet.com/~gellyfish/resources/wwwfaq.htm>
Hastings: <URL:http://www.newhoo.com/Regional/UK/England/East_Sussex/Hastings>


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

Date: Mon, 07 Jun 1999 12:02:19 -0700
From: Jerome O'Neil <jeromeo@atrieva.com>
To: Lee Pasquali <pasquali@uthscsa.edu>
Subject: Re: Possible compiler error when passing associative arrays
Message-Id: <375C173B.6C98DCB6@atrieva.com>

You are misunderstanding the way perl passed arguments to subroutines. 
The mechanism is outlined in perlsub.  Because you are porting, I'll
guess that you are working from the old documentaion.  I have no way of
knowing what they say, but more recent versions of the documentation say
thusly:

The Perl model for function call and return values is simple: all
functions are passed as parameters one single flat list of scalars, and
all functions
likewise return to their caller one single flat list of scalars. Any
arrays or hashes in these call and return lists will collapse, losing
their
identities--but you may always use pass-by-reference instead to avoid
this. Both call and return lists may contain as many or as few scalar
elements as you'd like. (Often a function without an explicit return
statement is called a subroutine, but there's really no difference from
the
language's perspective.) 

Lee Pasquali wrote:

> local ($a, $b, $c, %assoc);
> 
> $a = "a";
> $b = "b";
> $c = "c";
> 
> $assoc{one} = "11";
> $assoc{two} = "22";
> 
> &print_values($a, $b, %assoc, $c);

So what you have realy done is this:

@realy_gets_passed = qw{a b c one 11 two 22 c};
print_values(@realy_gets_passed);

> 
> sub print_values
> {
> 
>         local($sub_a, $sub_b, %, $sub_c) = @_;

Because all print_values() sees from the caller is a flat list, the
scalar $sub_c gets slurped into %sub_assoc and creates a new key index
from it.  You can verify this by adding the following to your code.

print qq{The hash slurped my scalar!\n} if exists $sub_assoc{c};

 
> As one can see, perl has a bug such that it does not find the end of the
> associative array correctly in the subroutine.

There is no such thing as "the end" of an associative array.
 
> Has anyone else seen this bug?

No, but we've seen lots of "unbugs" discovered here.

> Does anyone know where I can obtain a buglist and patches for v5.005_03?

I would check http://www.perl.com/bugs/index.html to start, but it's a
bit stale, and apparently no longer maintained.  :-(

> Does this bug exist in versions previous to v5.005_03?

What bug?

> Who do I notify that this bug exists?

Well, you might try the p5p list, but I think they would laugh at you.

> Thanks for any help in advance!

No problem!

-- 
Jerome O'Neil, Operations and Information Services
Atrieva Corporation, 600 University St., Ste. 911, Seattle, WA 98101
jeromeo@atrieva.com - Voice:206/749-2947 
The Atrieva Service: Safe and Easy Online Backup  http://www.atrieva.com


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

Date: 7 Jun 1999 21:00:28 GMT
From: Dan Sugalski <sugalskd@netserve.ous.edu>
Subject: Re: Possible compiler error when passing associative arrays
Message-Id: <7jhbtc$jr0$1@news.NERO.NET>

Lee Pasquali <pasquali@uthscsa.edu> wrote:


: I am converting a perl cgi from perl-v5.001 to perl-v5.005_03. The cgi
: contains code simular to that listed below.

[Snip]

: sub print_values
: {

:         local($sub_a, $sub_b, %sub_assoc, $sub_c) = @_;


You're taking advantage of a *bug* in 5.001. Hashes and arrays always get
flattened to a list when being passed to subs, and have for ages.
(Probably day one, but I haven't been around that long) 

Older versions of perl5 would, when filling in hashes, take pairs of
scalars from @_ and use them as key/value pairs. If there was an odd
number of scalars, the last single one would not get put in the hash,
instead being left on @_ for later shifts to snag. So, since you passed
only one parameter after the hash, it got left alone. If you'd passed more
than one, perl would have snagged pairs of them and put them in the hash
too. 

Perl 5.005 doesn't do this. If there's an odd number of elements it
uses the last one as a key with undef as its value. In fact, if you'd run
with the -w switch, you'd probably have seen this error:

Odd number of elements in hash assignment at foo line bar

or something very much like it.

Bottom line--bug in your code exploiting a bug in old versions of perl.
Change over to using references instead and you'll be doing much better.
(Use a prototype for your sub of $$\%$ and the code that uses the sub
doesn't even need to know there's been a bugfix)

						Dan


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

Date: Mon, 7 Jun 1999 16:52:29 -0400 
From: Ala Qumsieh <aqumsieh@matrox.com>
Subject: Re: read-accessing hash element implicitely defines hash, or I found a bug?
Message-Id: <x3yr9nn3f8z.fsf@tigre.matrox.com>


Luca de Marinis <loop@entranet.co.uk> writes:

> I have a question which may as well be very stupid, but is puzzling me.
> As the subject says, I have this piece of code:
> 
> warn "ok:$Self->{Session}\n";
> warn "weird: $Self->{Session}->{'s'}\n";
> warn ("not ok:$Self->{'Session'}\n");
> 
> ok:
> weird:
> not ok:HASH(0x89e08c)
> 
> This is with perl 5.004 running under mod_perl/apache
> 
> Am I missing out something? is this normal behaviour? 

Yes and yes. You are experiencing what is known as
"autovivification". When you try to access a non-existing element of a
hash, Perl will automatically create one for you. This is probably a
misfeature (not a bug, since it is well-known and documented), which
can not be "fixed" since many programs already depend on it. You can
overcome it by testing with exists() before trying to access the
element.

Searching through the docs/FAQs, I could only find two little
mentionings of autovivification; one if perlfaq4 and the other in
perlguts. Judging from the number of questions it draws, I suggest
that autovivification be explained more thoroughly (or at least
mentioned many more times) in the docs; possible in perldata, or
perldsc.

HTH,
Ala



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

Date: Mon, 7 Jun 1999 17:14:20 -0400
From: "Bob Perini" <perini@buffalo.edu>
Subject: Split
Message-Id: <7jhd0h$j93$1@prometheus.acsu.buffalo.edu>

I've got this directory name, and I need to split on a frontslash character
here is what I have

@directory=split (/ \ /,$directory1);

This line will not work, it constantly gives me a syntax error. How do I put
this character into the split function?

Thanks,
Bob Perini




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

Date: Mon, 07 Jun 1999 19:15:40 GMT
From: John Porter <jdporter@min.net>
Subject: Re: Syntax for square roots?
Message-Id: <7jh5oj$vip$1@nnrp1.deja.com>

In article <375C07DE.4BA03F97@nowhere.com>,
  User <user@nowhere.com> wrote:
> I have been trying to find if perl can take the square roots of
> numbers.  The "^" does not work if I try 2^0.5.
> For that matter I can't square numbers either.

You would do well to read the perlop and perlfunc documents if
you expect to get very far with perl.

>From perlop:

	Binary "**" is the exponentiation operator.

So 2 ** 5 = 32.
And from perlfunc:

     sqrt EXPR
     sqrt    Return the square root of EXPR.  If EXPR is omitted,
             returns square root of $_.

hth, hand,
--
John Porter
Put it on a plate, son.  You'll enjoy it more.


Sent via Deja.com http://www.deja.com/
Share what you know. Learn what you don't.


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

Date: 7 Jun 1999 20:24:04 -0000
From: Jonathan Stowe <gellyfish@gellyfish.com>
Subject: Re: Unzipping Files for WebTV
Message-Id: <7jh9p4$6js$1@gellyfish.btinternet.com>

On Mon, 7 Jun 1999 01:07:52 -0400 (EDT) Tiffany Silver wrote:
> I have access to a server that allows full cgi scripting, including
> permissions. 
> 
> The server allows access to a GUNZIP program. The program is located at:
> /usr/contrib/bin/gunzip 
> 
> I want to write a short perl script to allow me to unzip files on the
> server. I cannot do it in my client workstation because it is a WebTV. 
> 

Probably the best bit of advice I could give would to be to sling the
WebTV out and get a grownups 'pootey.  We have had sporadic posts here
from people who want to do a variety of otherwise simple tasks because
they were similarly hobbled.  But you arent going to go with that one are
you ?

> I am able to FTP zip files from their places on the Web to my server. 
> 
> WHAT is the perl statement that allows me to unzip? Exactly HOW do I
> include the /usr/contrib/bin/gunzip file in my program?
> 

Under usual circumstances I would advocate typing 'perldoc -f system'
at some command prompt however thats out of the question here.  I would
suggest that you browse over to <http://language.perl.com> and find the
perlfunc manpage that is available online there - you will want to look
at the entry for system() -  while you are there you probably want to
look at the rest of the wonderful documentation that can be found there
if you intend to use Perl for anything useful.

You should by now have got an introductory e-mail if you havent monkeyed
with your reply-to address;  that should give you some other pointers.

Anyhow what I want to know is when someone is going to port Linux and/or
Perl to the WebTV platform ?

/J\
-- 
Jonathan Stowe <jns@gellyfish.com>
Some of your questions answered:
<URL:http://www.btinternet.com/~gellyfish/resources/wwwfaq.htm>
Hastings: <URL:http://www.newhoo.com/Regional/UK/England/East_Sussex/Hastings>


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

Date: Mon, 07 Jun 1999 15:58:22 -0400
From: Tristan Lawrence <tlawrence@globix.com>
Subject: Using string variable as name of subroutine to call
Message-Id: <375C245E.C312D78@globix.com>

Hello!

I have a situation which I was able to solve this way:

# $billing is one of A, B, C
# run the appropriate subroutine "code"+billing code
$subroutine_name = lc($billing);
$subroutine_name = "code".$subroutine_name;
&$subroutine_name($data);

This works, but I wanted to figure out why it works, and if there is a
better way to do it.

While researching, I ran into FAQ 7.28 on this ng, which didn't say much
about subroutines but seemed to say that something like this would be
better:

$subs{'A'} = \&codea;
$subs{'B'} = \&codeb;
$subs{'C'} = \&codec;
&{$subs{$billing}}($data);

I'm still figuring this stuff out (no CS background) so I'm not really
sure why they work, much less which is preferable.

Any comments or suggestions (or help :) would be much appreciated.

Tristan Lawrence


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

Date: Mon, 7 Jun 1999 11:22:50 -0400
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: Using string variable as name of subroutine to call
Message-Id: <a4ogj7.s3o.ln@magna.metronet.com>

Tristan Lawrence (tlawrence@globix.com) wrote:

: I have a situation which I was able to solve this way:


[ snip use of Symbolic Reference to run subroutine ]


: This works, but I wanted to figure out why it works, 


   See the "Symbolic references" section in perlref.pod for why
   they work.


: and if there is a
: better way to do it.


   There is without a doubt a better way to do it.


: While researching, I ran into FAQ 7.28 on this ng, 


   All right! Posting the FAQs and docs worked at least once!


: which didn't say much
: about subroutines but seemed to say that something like this would be
: better:

[snip using code refs instead, repeated in code below ]

: I'm still figuring this stuff out (no CS background) so I'm not really
: sure why they work, much less which is preferable.


   See the URL below. Maybe it will help explain why a hash of
   code refs is better than using Symbolic references:

      http://www.plover.com/~mjd/perl/varvarname.html


: Any comments or suggestions (or help :) would be much appreciated.


   Never use Symbolic references!

   Settle down with perlref.pod, and figure out how to get around
   with "references" in Perl.


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


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

Date: 07 Jun 1999 17:09:37 -0400
From: Uri Guttman <uri@sysarch.com>
Subject: Re: Using string variable as name of subroutine to call
Message-Id: <x73e0390q6.fsf@home.sysarch.com>

>>>>> "TM" == Tad McClellan <tadmc@metronet.com> writes:

  TM> Tristan Lawrence (tlawrence@globix.com) wrote:

  TM> [ snip use of Symbolic Reference to run subroutine ]

  TM> : Any comments or suggestions (or help :) would be much appreciated.


  TM>    Never use Symbolic references!

unless you really, really know what you are doing. which eliminates about
%99 of all perl hackers. symrefs have their use but it is usually in
obscure or dark corners. 

uri

-- 
Uri Guttman  -----------------  SYStems ARCHitecture and Software Engineering
uri@sysarch.com  ---------------------------  Perl, Internet, UNIX Consulting
Have Perl, Will Travel  -----------------------------  http://www.sysarch.com
The Best Search Engine on the Net -------------  http://www.northernlight.com


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

Date: 6 Jun 1999 22:25:07 -0000
From: Jonathan Stowe <gellyfish@gellyfish.com>
Subject: Re: Wanted-Web Builder Seeking Fame & Fortune
Message-Id: <7jesg3$5qg$1@gellyfish.btinternet.com>

On Sun, 06 Jun 1999 15:40:15 GMT John Panas wrote:
> 
> This is not for everyone...but if your tyhe right
> person you and I will know it the first time we talk.
> 

Leaving the grammar aside - I thought you were talking about a job not
marriage - but I've been wrong before.

/J\
-- 
Jonathan Stowe <jns@gellyfish.com>
Some of your questions answered:
<URL:http://www.btinternet.com/~gellyfish/resources/wwwfaq.htm>
Hastings: <URL:http://www.newhoo.com/Regional/UK/England/East_Sussex/Hastings>


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

Date: Mon, 7 Jun 1999 13:10:28 -0700
From: "Dave Roth" <xrxoxtxhxdx@xrxoxtxhx.xnxextx>
Subject: Re: Win32:  How to set PW for a service that logs in as a local user?
Message-Id: <CDV63.7146$D_5.195772@news2.giganews.com>

Robert Hampton wrote in message <7jgigt$o96$1@bgtnsc01.worldnet.att.net>...
>I've got  some services logging in as a local user account on an NT server.
>When I change the password of the local user account, I need to update the
>password for each service that uses the local account for logging in.
>
>I've been scrounging David Roth's book on Win32 programming with Perl, but
I
>haven't seen this solution yet.  'Scuse me if I missed something obvious.

This did not make it into the book but it did make it into the
paper we are presenting at the USENIX LISA-NT 99 conference in July. This
code will configure the Scheduler service (it's service name is "schedule")
to log on with a particular user/password. The service will be
configured to load automatically. It also will grant the specified user
with the right to logon as a service.



use Win32;
use Win32::Service;
use Win32::Win32::API;
use Win32::Lanman;

ConfigService( "Schedule", "MyUserId", "MyUserPwd" );

sub ConfigService
{
 my( $Service, $User, $Password ) = @_;

 my $OpenSCManager = new Win32::API( 'advapi32.dll', 'OpenSCManager',
 P,P,L ], L );
 my $OpenService = new Win32::API( 'advapi32.dll', 'OpenService', [ L,P,L ],
L );
 my $CloseServiceHandle = new Win32::API( 'advapi32.dll',
'CloseServiceHandle', [ L ], I );
 my $SCHandle, $ServiceHandle;
 my $ServiceString, $UserString, $PasswordString;
 my %ServiceStatus;
 my $UnicodeFiller = "";

 print "Configuring the $Service service ...\n";

 $Result = Win32::Service::GetStatus( '', $Service, \%ServiceStatus );

 # Service status 1 == Service has stopped
 $Result = Win32::Service::StopService( '', $Service ) if( 1 !=
$ServiceStatus->{CurrentState} );

 # Convert the string to UNICODE if needed
 $UnicodeFiller = "\x00" if( Win32::API::IsUnicode() );
 ( $ServiceString = $Service ) =~ s/(.)/$1$UnicodeFiller/g;
 ( $UserString = $User ) =~ s/(.)/$1$UnicodeFiller/g;
 ( $PasswordString = $Password ) = s/(.)/$1$UnicodeFiller/g;

 # The flag 0x00F003F requests to open the service manager with full access
 if( $SCHandle = $OpenSCManager->Call( 0, 0, 0x000F003F ) )
 {
  # The flag 0xC0000000 requests GENERIC_READ and GENERIC_WRITE
  if( $ServiceHandle = $OpenService->Call( $SCHandle, $ServiceString,
0xC0000000 ) )


    my $ChangeServiceConfig = new Win32::API( 'advapi32.dll',
'ChangeServiceConfig', [ L,L,L,L,P,P,P,P,P,P,P ], I );

    # The 0x00000010 flag represents that the service will logon as a user
account
    # AND it will create it's own process (not share process space with
other services)
    # The 0xFFFFFFFF flag represents no change to this attribute.
    # The 0x00000002 flag represents the service is to auto start
    my $Result = $ChangeServiceConfig->Call( $ServiceHandle,
                         0x00000010,
                         0x00000002,
                         0xFFFFFFFF,
                         0,
                         0,
                         0,
                         0,
                         $UserString,
                         $PasswordString,
                         0 );
    if( $Result )
    {
      print "Granting the $User account the privilege to logon as a
service\n";

      # Grant the service account with the privilege to logon as a
service...
      $Result = Win32::Lanman::GrantPrivilegeToAccount( '',
'SeServiceLogonRight', [$User] );
      if( ! $Result )
      {
        print " Could not grant the privilege: ";
        print Win32::FormatMessage( Win32::Lanman::GetLastError() );
      }
    }
    else
    {
      print " Could not modify the '$Service' service: ";
      print Win32::FormatMessage( Win32::GetLastError() );
    }

    $CloseServiceHandle->Call( $ServiceHandle );
  }
  else
  {
    print "Could not open the '$Service' service: ";
    print Win32::FormatMessage( Win32::GetLastError() );
    }
  $CloseServiceHandle->Call( $SCHandle );
 }
 else
 {
  print " Could not open the service manager: ";
  print Win32::FormatMessage( Win32::GetLastError() );
 }

 Win32::Service::StartService( '', $Service );
}


dave
--
=================================================================
Dave Roth                                ...glittering prizes and
Roth Consulting                      endless compromises, shatter
<rothd at roth dot net>                 the illusion of integrity
http://www.roth.net
Win32, Perl, C++, ODBC, Training

Our latest Perl book is now available:
"Win32 Perl Programming: The Standard Extensions"
http://www.roth.net/books/extensions/






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

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


Administrivia:

Well, after 6 months, here's the answer to the quiz: what do we do about
comp.lang.perl.moderated. Answer: nothing. 

]From: Russ Allbery <rra@stanford.edu>
]Date: 21 Sep 1998 19:53:43 -0700
]Subject: comp.lang.perl.moderated available via e-mail
]
]It is possible to subscribe to comp.lang.perl.moderated as a mailing list.
]To do so, send mail to majordomo@eyrie.org with "subscribe clpm" in the
]body.  Majordomo will then send you instructions on how to confirm your
]subscription.  This is provided as a general service for those people who
]cannot receive the newsgroup for whatever reason or who just prefer to
]receive messages via e-mail.

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.misc (and this Digest), send your
article to perl-users@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.

The Meta-FAQ, an article containing information about the FAQ, is
available by requesting "send perl-users meta-faq". The real FAQ, as it
appeared last in the newsgroup, can be retrieved with the request "send
perl-users FAQ". Due to their sizes, neither the Meta-FAQ nor the FAQ
are included in the digest.

The "mini-FAQ", which is an updated version of the Meta-FAQ, is
available by requesting "send perl-users mini-faq". It appears twice
weekly in the group, but is not distributed in the digest.

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 V8 Issue 5914
**************************************

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