[12288] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 5888 Volume: 8

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Jun 4 13:07:17 1999

Date: Fri, 4 Jun 99 10:01:28 -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           Fri, 4 Jun 1999     Volume: 8 Number: 5888

Today's topics:
        Please help with associative arrays of arrays! (EXCHANGE:RICH1:2L14)
    Re: Please help with associative arrays of arrays! (Andrew Allen)
    Re: Please help with associative arrays of arrays! RABM@prodigy.net
        problem running under taint checking (Alan Young)
    Re: s/a*/x/g behavior <gellyfish@gellyfish.com>
    Re: s/a*/x/g behavior <dgris@moiraine.dimensional.com>
    Re: Structures in PERL (J. Moreno)
    Re: using sendmail with CGI.pm <jdporter@min.net>
    Re: What is the meaning of '.' in @INC? (David Cantrell)
    Re: Win32::Process::GetExitCode - meaning (Michel Dalle)
        Special: Digest Administrivia (Last modified: 12 Dec 98 (Perl-Users-Digest Admin)

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

Date: Fri, 04 Jun 1999 09:42:10 -0500
From: "Chow, Larry (EXCHANGE:RICH1:2L14)" <chow@americasm01.nt.com>
Subject: Please help with associative arrays of arrays!
Message-Id: <3757E5C1.C8D92E02@americasm01.nt.com>

Our perl guru is not in today and I would like to get this script
working...

Basically I have an associative array in which it's members are arrays:

open(DB,"$pat_rel_db") or die "Couldn't open $pat_rel_db for read: $!";
while(<DB>)
{
   ($pid,$date,$user,$junk)=split(/~/,$_,4);
   $pid=uc($pid);
   push(@{$Pat_Rel{$pid}},$user);  <<<<< HERE IS WHERE IT IS DEFINED
}
close(DB);

later I want to see how many members are in the array of a specific
$Pat_Rel{$pid}.  to reference
each member I should be able to use $Pat_Rel{$pid}[1] (ie to reference
2nd member)

So how come perl has a problem with finding out the number of elements
in the array using $# ?

   if ($#Pat_Rel{$pid} > 1) {
      for ($i=0; $i<=$#Pat_Rel{$pid}; $i++) {
         if ($Pat_Rel{$pid}[$i] eq "anam\@nt.com") {
            return 1;
         }
      }
   }

ERRORs are:

Can't use subscript on array length at
/opt/corp/mnt/mtxfs/2lxx/s700/bin/pacs_update.pl line 261, near "$pid}"
Can't use subscript on array length at
/opt/corp/mnt/mtxfs/2lxx/s700/bin/pacs_update.pl line 262, near "$pid}"
Execution of /opt/corp/mnt/mtxfs/2lxx/s700/bin/pacs_update.pl aborted
due to compilation errors.

If I try to add {}'s to the expression it gives different errors about
syntax.

   if (${#Pat_Rel{$pid}} > 1) {

Any ideas?  Please reply via email.  Thanks!



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

Date: 4 Jun 1999 16:20:03 GMT
From: ada@fc.hp.com (Andrew Allen)
Subject: Re: Please help with associative arrays of arrays!
Message-Id: <7j8ubj$cmp$1@fcnews.fc.hp.com>

Chow, Larry (EXCHANGE:RICH1:2L14) (chow@americasm01.nt.com) wrote:
: Our perl guru is not in today and I would like to get this script
: working...

: Basically I have an associative array in which it's members are arrays:

: later I want to see how many members are in the array of a specific
: $Pat_Rel{$pid}.  to reference
: each member I should be able to use $Pat_Rel{$pid}[1] (ie to reference
: 2nd member)

: So how come perl has a problem with finding out the number of elements
: in the array using $# ?

Because you're syntax isn't quite right...

:    if ($#Pat_Rel{$pid} > 1) {

This should be:

$#{$Pat_Rel{$pid}}

the rule is simple: any place the _name_ of an array can go,
{expression} can be substituted, where expression evaluates to an
array reference.

$x{$y}[$z] is really just a syntactic shortcut to ${$x{y}}[$z] (to
which you can then see the above rule apply).

Andrew


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

Date: 04 Jun 1999 12:34:18 -0400
From: RABM@prodigy.net
Subject: Re: Please help with associative arrays of arrays!
Message-Id: <uogiv9b79.fsf@prodigy.net>

>>>>> "Larry" == Chow, Larry (EXCHANGE:RICH1:2L14) <chow@americasm01.nt.com> writes:

    Larry> Our perl guru is not in today and I would like to get this script
    Larry> working...

    Larry> Basically I have an associative array in which it's members are arrays:

    Larry> open(DB,"$pat_rel_db") or die "Couldn't open $pat_rel_db for read: $!";
    Larry> while(<DB>)
    Larry> {
    Larry>    ($pid,$date,$user,$junk)=split(/~/,$_,4);
    Larry>    $pid=uc($pid);
    Larry>    push(@{$Pat_Rel{$pid}},$user);  <<<<< HERE IS WHERE IT IS DEFINED
    Larry> }
    Larry> close(DB);
    Larry> later I want to see how many members are in the array of a specific
    Larry> $Pat_Rel{$pid}.  to reference
    Larry> each member I should be able to use $Pat_Rel{$pid}[1] (ie to reference
    Larry> 2nd member)

    Larry> So how come perl has a problem with finding out the number of elements
    Larry> in the array using $# ?

    Larry>    if ($#Pat_Rel{$pid} > 1) {

You want: 

    if ( $#{ $Pat_Rel{$key} } > 1 ) {


    Larry>       for ($i=0; $i<=$#Pat_Rel{$pid}; $i++) {
    Larry>          if ($Pat_Rel{$pid}[$i] eq "anam\@nt.com") {
    Larry>             return 1;
    Larry>          }
    Larry>       }
    Larry>    }

    Larry> ERRORs are:

    Larry> Can't use subscript on array length at
    Larry> /opt/corp/mnt/mtxfs/2lxx/s700/bin/pacs_update.pl line 261, near "$pid}"
    Larry> Can't use subscript on array length at
    Larry> /opt/corp/mnt/mtxfs/2lxx/s700/bin/pacs_update.pl line 262, near "$pid}"
    Larry> Execution of /opt/corp/mnt/mtxfs/2lxx/s700/bin/pacs_update.pl aborted
    Larry> due to compilation errors.

    Larry> If I try to add {}'s to the expression it gives different errors about
    Larry> syntax.

    Larry>    if (${#Pat_Rel{$pid}} > 1) {

    Larry> Any ideas?  Please reply via email.  Thanks!


-- 


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

Date: Fri, 04 Jun 1999 16:41:47 GMT
From: alany@2021.com (Alan Young)
Subject: problem running under taint checking
Message-Id: <375af77f.2693518@news.supernews.com>

Hello all!

I'm having a problem running a script under taint checking.

I'm using the Date::Manip subroutine by Sullivan Beck, which when
trying to obtain the full file path in Date::Manip::FullFilePath uses
the line

my($cwd) = cwd;

and I get the following error:

Insecure $ENV{PATH} while running with -T switch at
/u/alany/lib/perl5/Cwd.pm line 82.

This is the subroutine in Cwd.pm:

sub _backtick_pwd {
    my $cwd;
    chop($cwd = `pwd`);
    $cwd;
}

I tried doing the following:

sub _backtick_pwd {
    my $cwd;
    my $pwd = "";
	$pwd =~ /^(\w)$/;
    $pwd = $1;
    chop($cwd = `$pwd`);
    $cwd;
}

and got the same error message.

$ENV{PATH} is

/u/alany/bin:/usr/local/bin:/stronghold/ssl/bin:/usr/bin:/usr/ccs/bin:/usr/contr
ib/bin:/opt/nettladm/bin:/opt/pd/bin:/opt/upgrade/bin:/bin:/opt/hpnp//bin:/opt/p
erf/bin:/usr/wp/offbin:/2021bin:/o2obin:/usr/local/bin:.

What is insecure about this path? and how is it affecting the pwd
command?

Alan


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

Date: 4 Jun 1999 16:12:53 +0100
From: Jonathan Stowe <gellyfish@gellyfish.com>
Subject: Re: s/a*/x/g behavior
Message-Id: <3757ecf5@newsread3.dircon.co.uk>

Daniel Grisinger <dgris@moiraine.dimensional.com> wrote:
> Jonathan Feinberg <jdf@pobox.com> writes:
> 
>> james_peregrino@harvard.edu (James Peregrino) writes:
>> 
>> > why doesn't "H" match /a*/?
>> 
>> In what way can the letter "H" be said to be "zero or more a's"?
> 
> I must be confused, in what way can the letter `H' _not_
> be said to be "ZERO or more a's".
> 

Because it is not zero characters and it is not an 'a' ;-}

/J\
-- 
Jonathan Stowe <jns@gellyfish.com>



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

Date: 04 Jun 1999 10:13:49 -0600
From: Daniel Grisinger <dgris@moiraine.dimensional.com>
Subject: Re: s/a*/x/g behavior
Message-Id: <m3yai0vt8i.fsf@moiraine.dimensional.com>

Jonathan Stowe <gellyfish@gellyfish.com> writes:

> James Peregrino <james_peregrino@harvard.edu> wrote:
> > Hi,
> >    I was explaining regular expressions to someone, and as I was
> > changing expressions around and showing how the results differed, I said
> > that
> > 
> > $_ = "Haas";
> > s/a*/x/g;
> > print "$_\n";
> > 
> > should print out "xxxx".  But instead it prints out "xHxxsx".  My
> > reasoning falls apart at the beginning - why doesn't "H" match /a*/ ?
> > 
> 
> It is probably easier to say why it matches what it does match.  Which
> is 0 or more instances of the character 'a' - which matches the abscence
> of the character in the nothingness that is at the beginning and of the 
> string and the 'aa' in the middle - as neither 'H' nor 's' are zero or
> more instances of 'a' these dont match.

Your explanation doesn't seem quite right to me.  I'm going to start
from the same place you did--showing what was matched.

   $_ = 'Haas';
   s/a*/x/g;

Starting from the zero-width position at ^ the regex tries
to match 0 or more instances of the literal character `a'.
Since there are indeed 0 a's at the start of the string
the expression matches and replaces ^ with `x'.  Now the
target string looks like-

    xHaas

Now, the regular expression engine hasn't advanced to the
next point in the expression yet, it's positioned between
the `x' and the `H'.  It should match here because there
are still no a's to match.  It doesn't match, though, because
perl's regex engine advances when it determines that it could
match the null string an infinite number of times.

Next it tries and fails to match `a' at `H'.  After advancing the
regex it matches the string `aa' and replaces it with `x'.  The
target string now looks like-
    
    xHxs

and the match is positioned after the second x, before the s.
It hasn't matched here yet, so the infinite null avoidance
doesn't do anything, the expression matches the zero-width
point between the `x' and `s' and replaces it with an `x'.
The target string is now-

    xHxxs

The infinite null avoidance happens and the regex is advanced to
the `s'.  This doesn't match `a' and the regex is advanced to
the zero-width point after the `s'.  This does match and is replaced
with an `x'.  The target string is now-

    xHxxsx

Since the regex has now reached the end of the string it
terminates, leaving the observed result.

Hope this helps.

dgris
-- 
Daniel Grisinger          dgris@moiraine.dimensional.com
perl -Mre=eval -e'$_=shift;;@[=split//;;$,=qq;\n;;;print 
m;(.{$-}(?{$-++}));,q;;while$-<=@[;;' 'Just Another Perl Hacker'


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

Date: Fri, 4 Jun 1999 12:03:41 -0400
From: planb@newsreaders.com (J. Moreno)
Subject: Re: Structures in PERL
Message-Id: <1dsvi50.135lltw1bv2wvfN@roxboro0-0002.dyn.interpath.net>

Tom Christiansen <tchrist@mox.perl.com> wrote:

>      [courtesy cc of this posting mailed to cited author]
> 
> In comp.lang.perl.misc, 
>     "Mike Rizzo" <mrizzo@ismd.ups.com> writes:
> :I am having a little bit of trouble figuring out how to go about creating a
> :so called structure in PERL.
> 
> Have you read the perldsc manpage yet?  The hash is Perl's record
> structure.

I have, and haven't seen what I think is a more serious lack -- what's
the best way to have the equivalent of a list of records?  Currently I
use a bunch of hashes, but whenever I do I get the nagging feeling that
there's a better way just around the corner.

-- 
John Moreno


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

Date: Fri, 04 Jun 1999 14:25:11 GMT
From: John Porter <jdporter@min.net>
Subject: Re: using sendmail with CGI.pm
Message-Id: <7j8njq$e4i$1@nnrp1.deja.com>

In article <7j8iem$c3c$1@nnrp1.deja.com>,
  landre@my-deja.com wrote:
> Here is a script that works on its own:
>
> open(MAIL,"|$mailprog -t");

Any particular reason you're utterly ignoring the wisdom of the ages,
and not checking the result of open()?

Any particular reason you're not using Net::SMTP?


> within a much bigger script that uses CGI.pm and

> if ( $action eq "process" ) {
>     &validData();
>     &writeLog();
>     &confemail();
>     print "Location: https://some.dir.com/etc...";

What do those functions do?  Specifically, do they die if any
errors are found?  I hope so, because otherwise you're going
to drop through to the print "Location: " even on errors -- bad.

If you're using CGI.pm, I would recommend using the redirect()
method, rather than printing your own "Location: " header.


> sub confemail {
> # Next mail an order confirmation to the client:
>
> and you know the rest.

I do?  If it's that code you posted above, then I fault you for
not checking for error conditions and dying on them.


--
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: Fri, 04 Jun 1999 16:30:22 GMT
From: NukeEmUp@ThePentagon.com (David Cantrell)
Subject: Re: What is the meaning of '.' in @INC?
Message-Id: <3759fd8d.89433087@news.insnet.net>

On Fri, 21 May 1999 18:07:14 +0200, "Vincent Vanbiervliet"
<vincent_vanbiervliet@be.ibm.com> said:

>I have this in my @INC:
>
>d:\Perl\lib
>d:\Perl\site\lib
>.
>
>This works on the command line, but not with my webserver. For example, if I
>use a require in /cgi-bin/asubdir/ascript.pl, and I have that 'required'
>file in /cgi-bin/asubdir/, it doesn't work.
>Why not?

Because your webserver is broken.  It should set the current directory
to /cgi-bin/asubdir before running the script but it doesn't.  let me
guess, you're running IIS or PWS?

Prepend this little snippet to your script; it will set the current
working directory to something a little more sane.

$path=$ENV{'PATH_TRANSLATED'};
$path=~s/(.*)[\\\/][^\\\/]*/$1/;
chdir($path);

[Copying newsgroup posts to me by mail is considered rude]

-- 
David Cantrell, part-time Unix/perl/SQL/java techie
                full-time chef/musician/homebrewer
                http://www.ThePentagon.com/NukeEmUp


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

Date: Fri, 04 Jun 1999 16:47:10 GMT
From: michel.dalle@usa.net (Michel Dalle)
Subject: Re: Win32::Process::GetExitCode - meaning
Message-Id: <7j8vv2$d7p$1@news.mch.sbs.de>

In article <928502946.497218@gate.logis.cz>, "Pavel Kotala" <pkotala@logis.cz> wrote:
>When I use  Win32::Process::GetExitCode and Process is running, I receive
>value
>
>259
>
>When process is not running, I receive
>
>3221225786
>
>What are meaning of these values? What other values can I get?

Here is what Microsoft has to say on the return code of GetExitCodeProcess
in the Win32 API (STILL_ACTIVE = 259) :

Return Values
If the function succeeds, the return value is nonzero. 

If the function fails, the return value is zero. To get extended error 
information, call GetLastError. 

Remarks
If the specified process has not terminated, the termination status returned 
is STILL_ACTIVE. If the process has terminated, the termination status 
returned may be one of the following: 

7 The exit value specified in the ExitProcess or TerminateProcess function. 

7 The return value from the main or WinMain function of the process. 

7 The exception value for an unhandled exception that caused the process to 
terminate. 

Now you know as much as any Microsoft specialist :-)

Michel.


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

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

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