[19755] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 1950 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Oct 17 21:05:49 2001

Date: Wed, 17 Oct 2001 18:05:10 -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: <1003367110-v10-i1950@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Wed, 17 Oct 2001     Volume: 10 Number: 1950

Today's topics:
    Re: Creating a hash from a sub that parses XML <thunderbear@bigfoot.com>
    Re: Creating a hash from a sub that parses XML <jemptyg@rwmc.net>
    Re: Creating a hash from a sub that parses XML (Tad McClellan)
    Re: Creating a hash from a sub that parses XML (Tad McClellan)
    Re: Creating a hash from a sub that parses XML (Martien Verbruggen)
    Re: DBI::ProxyServer error on WindowsNT <rereidy@indra.com>
    Re: Entering Name-Value pairs - Still Confused <wsegrave@mindspring.com>
    Re: How can I send an html formatted email, preferably  <tintin@snowy.calculus>
    Re: how to find memory leaks in perl 5.004_04 <mjcarman@home.com>
    Re: how to find memory leaks in perl 5.004_04 <dtweed@acm.org>
    Re: how to get the user logon name with getlogin(). <tony_curtis32@yahoo.com>
    Re: IE6 Error - Perl Output <tintin@snowy.calculus>
    Re: Looking for DOS equiv to pause <tintin@snowy.calculus>
    Re: newbie question - how to rename files with Perl? <yes@yesIsuppose.org>
        Perl CGI problem printing Javascript... <bcarlso4@bellsouth.net>
    Re: Perl CGI problem printing Javascript... <tony_curtis32@yahoo.com>
        perl program converted to NT service-problems <Jamuna.Krishnappa@fmr.com>
    Re: precedence question <andrew@erlenstar.demon.co.uk>
    Re: precedence question <dtweed@acm.org>
    Re: precedence question <bart.lateur@skynet.be>
    Re: push, pop, shift, unshift, splice et al (John J. Trammell)
    Re: push, pop, shift, unshift, splice et al <spam@thecouch.homeip.net>
    Re: push, pop, shift, unshift, splice et al <tom.hoffmann@worldnet.att.net>
    Re: push, pop, shift, unshift, splice et al <thelma@alpha2.csd.uwm.edu>
    Re: push, pop, shift, unshift, splice et al (Michael Houghton)
        Splitting on value pairs <tintin@snowy.calculus>
    Re: Splitting on value pairs (Garry Williams)
    Re: Splitting on value pairs <bart.lateur@skynet.be>
    Re: Using a remote file with a Perl script (Garry Williams)
    Re: Writing and reading encrypted string (password) <Juha.Laiho@iki.fi>
    Re: Writing and reading encrypted string (password) <bart.lateur@skynet.be>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Thu, 18 Oct 2001 00:35:57 +0200
From: =?iso-8859-1?Q?Thorbj=F8rn?= Ravn Andersen <thunderbear@bigfoot.com>
Subject: Re: Creating a hash from a sub that parses XML
Message-Id: <3BCE07CD.6DBB8D52@bigfoot.com>

George Jempty wrote:
> 
> I'm looking for advice as to creating a hash from a sub that parses XML.

Looks like you are reinventing XML::Simple.
-- 
  Thorbjørn Ravn Andersen           "...plus... Tubular Bells!"
  http://bigfoot.com/~thunderbear


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

Date: Wed, 17 Oct 2001 23:48:57 GMT
From: "George Jempty" <jemptyg@rwmc.net>
Subject: Re: Creating a hash from a sub that parses XML
Message-Id: <1003362216.961551@airwave-sb.scottsbluff.net>

Thanks much; I was wondering if a module might do this, I was just
overwhelmed by the sheer number of them.  And the XML file I'm parsing is
"simple" indeed.

"Thorbjørn Ravn Andersen" <thunderbear@bigfoot.com> wrote in message
news:3BCE07CD.6DBB8D52@bigfoot.com...
> George Jempty wrote:
> >
> > I'm looking for advice as to creating a hash from a sub that parses XML.
>
> Looks like you are reinventing XML::Simple.
> --
>   Thorbjørn Ravn Andersen           "...plus... Tubular Bells!"
>   http://bigfoot.com/~thunderbear




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

Date: Thu, 18 Oct 2001 00:23:07 GMT
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Creating a hash from a sub that parses XML
Message-Id: <slrn9srv1a.m5t.tadmc@tadmc26.august.net>

George Jempty <jemptyg@rwmc.net> wrote:

>I'm looking for advice as to creating a hash from a sub that parses XML.


It would help if we could see some data...


>Here is my working subroutine:
>
>sub getHashFromXml


Are you enabling warnings? You should.


>I know it's not perfect, especially from the standpoint of "Perl idiom", but


Doesn't look too bad Perl-wise, as long as you are _certain_ that
you will never call getHashFromXml() more than one time in your
program. (but then it could be main code, no need for a subroutine...)

If you want to call it more than once, then you'll need to work
on it some more.


>So I know it "works", 


No, you know it works on the data you tried it with. 

I'll bet it can be broken by other data. I'll break it for
you in a separate followup  :-)


>but from searching the archives of this newsgroup I
>get the definite impression there might be a more efficient way to do this?!


You have a serious _XML_ problem that has nothing to do with Perl 
though. See my other followup.


>For instance I read that the hash will remain in memory after it is returned
>(maybe I misunderstood).  


You misunderstood, if you are talking about the code you posted.

You also didn't show us the subroutine call, but I guess it was
something like:

   my %hash = getHashFromXml( 'id', 'name', 'stuff.xml');

??

If so, then %hashFromXml goes away, but the data lives on 'cause
it was copied to some other memory location (%hash's).

I think you are probably talking about returning a *reference*
to a hash, but that isn't what your code does.

   perldoc perlreftut

can help you figure out how to return a reference to a hash instead
of a flattened out list of alternating key/value pairs.


>Plus I understand that it will get returned as a
>list, so maybe I should just send it back that way to begin with?!


The way you have it is fine (unless the hash is "big", then pass
a ref-to-hash instead).


>Any and all help will be appreciated.  It would be ideal if someone could
>point out where to modify what the sub returns, and then how to call the sub
>so as to create the desired hash.  


You are already creating the desired hash!

Maybe you want to know how to use a hash ref instead?

   my $href = getHashFromXml( 'id', 'name', 'stuff.xml');
   print "$_ ==>  $href->{$_}\n" for sort keys %$href;

and in getHashFromXml():

   return \%hashFromXml;

_Then_ the memory for %hashFromXml will hang around until $href
goes out of scope.


>Hope this isn't asking too much, that's
>why I provided my working code, perhaps it can help somebody else.


Thanks. Working code is a Really Good Idea.

Even better is "code that we can run" (with a main program and data).
Consider including that too the next time.


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


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

Date: Thu, 18 Oct 2001 00:23:09 GMT
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Creating a hash from a sub that parses XML
Message-Id: <slrn9ss55a.m5t.tadmc@tadmc26.august.net>

George Jempty <jemptyg@rwmc.net> wrote:

[
   You have been identified as the perpetrator of "that thread".

   So long (again).

   Didn't notice your name until the followups had already been written.
]


>I'm looking for advice as to creating a hash from a sub that parses XML.
>Here is my working subroutine:

[snip code]

>It's hard being the only developer, and my brain is
>fried right now....


You are NOT guaranteed to get all of the #PCDATA characters
in one char handler call. The parser is free to call your
char handler many times with a few characters each time.

So the usual approach is to "buffer chars in char handler" and
then "process and empty the buffer" in the endtag handler.

I've patched yours up to work with multiple char handler calls
below. It may still "not work" because we haven't seen your
data, but it illustrates the point at least.

The data used below is the promised "breaks your code" data.
Try that data with your original code and see what happens.


----------------------------------------
#!/usr/bin/perl
#use warnings; the non-shared closure thing was pointed out in other followup
use strict;

my %h = getHashFromXml( 'id', 'name', 'hash.xml');
print "$_  ==>  $h{$_}\n" for sort keys %h;


sub getHashFromXml
{
  my $keyTag = shift;
  my $valueTag = shift;

  my $keyMatch = "";
  my $valueMatch = "";
  my $isKey = 0;
  my $isValue = 0;
  my $gotPair = 0;
  my %hashFromXml;

  use XML::Parser;

  my $parser = new XML::Parser
  (
    Handlers =>
    {
      Char => \&char_handler,
      End => \&end_handler,
   Start => \&start_handler
    }
  );

  $parser->parse( join '', <DATA> );
  return %hashFromXml;

  sub char_handler
  {
    $keyMatch .= $_[1] if ($isKey);
    $valueMatch .= $_[1] if ($isValue);
    $gotPair++ if ($keyMatch && $valueMatch);
  }

  sub end_handler
  {
    $isKey-- if ($isKey);
    $isValue-- if ($isValue);
    if ($keyMatch && $valueMatch)
    {
      $hashFromXml{$keyMatch} = $valueMatch;
      $keyMatch = "";
      $valueMatch = "";
    }
  }

  sub start_handler
  {
    $isKey++ if ($_[1] eq $keyTag);
    $isValue++ if ($_[1] eq $valueTag);
  }
}

__DATA__
<data>
<id>ID-1</id> <name>Value 1</name>
<id>ID-2</id> <name>Standard &amp; Poors</name>
<id>ID-3</id> <name>Value 3</name>
</data>
----------------------------------------


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


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

Date: Thu, 18 Oct 2001 01:02:13 GMT
From: mgjv@tradingpost.com.au (Martien Verbruggen)
Subject: Re: Creating a hash from a sub that parses XML
Message-Id: <slrn9ssagl.l88.mgjv@verbruggen.comdyn.com.au>

On Wed, 17 Oct 2001 18:40:20 GMT,
	George Jempty <jemptyg@rwmc.net> wrote:

(line wrapped to fit in 72 characters)
http://groups.google.com/groups?
	as_umsgid=WcSK3.895%24ry3.9280%40news.rdc1.ne.home.com

Martien
-- 
Martien Verbruggen              | My friend has a baby. I'm writing
                                | down all the noises the baby makes so
Trading Post Australia Pty Ltd  | later I can ask him what he meant -
                                | Steven Wright


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

Date: Wed, 17 Oct 2001 16:27:39 -0600
From: Ron Reidy <rereidy@indra.com>
Subject: Re: DBI::ProxyServer error on WindowsNT
Message-Id: <3BCE05DB.86B853BB@indra.com>

Keith Clay wrote:
> 
> Folks,
> 
> When we configure dbiproxy with 'mode'=>'thread', we get the following
> error.  We just installed activestate perl 5.6 on the machine along
> with the appropriate DBI/DBD modules.  It works find in single
> connection mode.
> 
> ERROR:
> Can't call method "tid" on an undefined value at
> D:/Perl/site/lib/Net/Daemon/Log.pm line 75.
> 
> Thanks,
> 
> keith
This problem is from Log.pm.  Investigate this by looking at the file in
an editor.
-- 
Ron Reidy
Oracle DBA
Reidy Consulting, L.L.C.


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

Date: Wed, 17 Oct 2001 17:09:00 -0500
From: "William Alexander Segraves" <wsegrave@mindspring.com>
Subject: Re: Entering Name-Value pairs - Still Confused
Message-Id: <9ql049$1f3$1@slb2.atl.mindspring.net>

"Michael Carman" <mjcarman@home.com> wrote in message
news:3BCDE823.F6E150F5@home.com...
>
> Ah, you must be using a different version of PSI::ESP than I am. :) The
> thread got fragmented, which makes it harder to follow.

Indeed. In fact, I was responding more to the apparent desperation of the
OP. He seemed to be having difficulty with what to do after he hit  the
"Enter" key.

> My
> interpretation was that the OP didn't understand how to use the offline
> mode of CGI.pm. (For the unfamiliar, this feature allows you to supply
> data to a CGI script without running through a webserver -- useful for
> debugging.)

I see. Hopefully, the OP will see what you've posted and follow your
suggestions.

Personally, I like CGI.pm. OTOH, it seems to be overkill for light duty
stuff like converting the URL-encoded string of name=value pairs from a PDF
form submittal into FDF, so the form data can be saved for later use. I use
Perl, Perl + FDF-related subroutines, Perl + my own FDF.lib, or Perl +
CGI.pm, interchangeably.

> You seem to have interpreted it as him not understanding how
> data is supplied to a CGI script. Correct? I agree that the post was
> off-topic under the latter interpretation.
>
> -mjc

Yes and No. I think the OP didn't know how to supply the name=value pairs to
his Perl script at all, especially off-line. IMO, to test and debug his Perl
scripts for eventual use on a remote server, the OP (Dr. K.) should test and
debug them in the following order:
1. by running them off-line,
2. then, with either a local server running as localhost, or a web server
running on his LAN,
3. finally, on a remote web server, e.g., the host ISP.

Bill Segraves
Auburn, AL






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

Date: Thu, 18 Oct 2001 08:08:49 +1000
From: "Tintin" <tintin@snowy.calculus>
Subject: Re: How can I send an html formatted email, preferably using Net::SMTP?
Message-Id: <Yknz7.5$Pb2.115826@news.interact.net.au>


"Jon Feldhammer" <jonf@rgb.com> wrote in message
news:9qkov4$7kk@dispatch.concentric.net...
> I'm having a very hard time sending an email that a html enabled mail
> program will read as html.  I assume it has to do with the header line
> Content-Type: text/plain which needs to be Content-Type: text/html ... I
> can't seem to figure out how to change that line, or maybe that isnt' the
> problem.
>
> I've tried using the Mail::Header module but it is poorly documented and
> have had no luck.  I'd prefer to use SMTP rather than a direct open
> (SENDMAIL, "| sendmail -t") type thing to keep this script platform
> independent.

I'd use MIME::Lite




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

Date: Wed, 17 Oct 2001 17:02:14 -0500
From: Michael Carman <mjcarman@home.com>
Subject: Re: how to find memory leaks in perl 5.004_04
Message-Id: <3BCDFFE6.4E97FA58@home.com>

jimbo wrote:
> 
> "Jim Anderson" <james.h.anderson@ssmb.com> wrote
> >
>
> Your original premise was a waste of time, a waste of bandwidth and,
> yet, you couldn't resist posting anyway.  Might as well be a common,
> substance obsessed, junkie.

Oh, settle down. The original post was fine.

> Go on you tosser, [...]

Despite their popularity, ad hominem attacks are *not* the best way to
get your point across.

Everyone: Take a deep breath and refrain from posting until you can
behave rationally.

> post this question to comp.lang.perl.moderated.  You
> won't *EVER* see it there.  Why, because Dave was spot on.

No, Dave's advice was not "spot on." It missed the real point, as you
seem to have:

> If it's to big to post (even the potentially offending fragments),
> you can't show it to anyone, and the person or persons who wrote it
> won't support it with you, then why, in God's very great name, do
> **YOU** expect anyone else to be able, let alone willing, to help?

The OP never asked you to solve his problem. He asked if you knew of any
tools that he could use to solve it himself. Personally, I prefer this
type of question.

> > Clearly you don't understand that I'm asking whether there's a
> > general tool or method for tracking this sort of thing. I'm also
> 
> The sure as hell is, it's often referred to as the Perl Debugger.

The debugger is certainly a useful tool, but it's not a magic wand for 
isolating memory leaks. Tellling the OP to "use the debugger" is like
telling someone to look at the sun when they ask which way is north.
Yes, you can use the sun to find north. The OP wanted to know *how*.

So, if you have any *methods*, please share them, but don't tell us to
look at the sky -- we already know that there's a sun.

As I said in my original reply, the Devel::Leak module may help. (I've
never tried it myself.) About the only other diagnostic I'm aware of is
to sprinkle your code with system calls which check your memory usage
and print it out along with their location. Hopefully one of these
methods will yeild a smallish subset of the code where the problem
occurs. At that point you can scrutinize it to try to isolate the
problem. (It might be a problem in perl, but it could be something like
a scoping problem as well.)

> > asking if there is a set of known memory leaks in this version of
> > the perl interpreter.

Some; see the perldelta manpages for details.

> Lose the twisted sense of righteousness you seem to revel in. 
> Mature. Find personally rewarding pastimes.  Leave coding to the
> professionals.

You sound like a troll, and much more guilty of your allegations than
the person you direct them against. Perhaps you should take your own
advice.

-mjc


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

Date: Thu, 18 Oct 2001 00:15:18 GMT
From: Dave Tweed <dtweed@acm.org>
Subject: Re: how to find memory leaks in perl 5.004_04
Message-Id: <3BCE1DAF.4259F720@acm.org>

Michael Carman wrote:
> As I said in my original reply, the Devel::Leak module may help. (I've
> never tried it myself.) About the only other diagnostic I'm aware of is
> to sprinkle your code with system calls which check your memory usage
> and print it out along with their location. Hopefully one of these
> methods will yeild a smallish subset of the code where the problem
> occurs. At that point you can scrutinize it to try to isolate the
> problem. (It might be a problem in perl, but it could be something like
> a scoping problem as well.)

 ... which is just a much more verbose version of my advice, which was to
"learn enough Perl so that you can debug it yourself."

-- Dave Tweed


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

Date: Wed, 17 Oct 2001 17:21:35 -0500
From: Tony Curtis <tony_curtis32@yahoo.com>
Subject: Re: how to get the user logon name with getlogin().
Message-Id: <87d73lvrf4.fsf@limey.hpcc.uh.edu>

>> On Wed, 17 Oct 2001 22:39:09 +0100,
>> "WebBat" <webbat@btinternet.com> said:

> All, I need to find the user logon name. but each time i
> try using getlogin, it returns the user name on the
> server not the client.

stealth CGI question?

Try telling us what's really going on.  Seriously, we
can't guess what you're doing.  If we try, we'll probably
lead you on a wild goose chase.

> How can I determine the actual users name and not the
> server user name ?

Ask them!

This question is completely meaningless in a WWW
environment.

hth
t
-- 
Oh!  I've said too much.  Smithers, use the amnesia ray.


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

Date: Thu, 18 Oct 2001 08:20:37 +1000
From: "Tintin" <tintin@snowy.calculus>
Subject: Re: IE6 Error - Perl Output
Message-Id: <1wnz7.6$Uc2.168088@news.interact.net.au>


"RSL" <rlally1@nycap.rr.com> wrote in message
news:QHhz7.691154$T97.95041803@typhoon.nyroc.rr.com...
> How much more on topic can this be?  My question is can I change the error
> code from one value (say 404) to another from a Perl script?  Not a VB
> script or any other type of script but a Perl script.

Your question is offtopic.

Your Perl script outputs HTML.  OK, is that something other languages can
do.

in sh
echo "<H1>This is HTML</H1>"

in ksh
print "<H1>This is HTML</H1>"

in C
printf("%s\n","<H1>This is HTML</H1>");

etc, etc.

Get the idea?  Just because you can output HTML in Perl, doesn't mean it is
Perl's problem when the output is interpretted incorrectly.





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

Date: Thu, 18 Oct 2001 08:26:15 +1000
From: "Tintin" <tintin@snowy.calculus>
Subject: Re: Looking for DOS equiv to pause
Message-Id: <kBnz7.7$jb2.90201@news.interact.net.au>


"Lou Moran" <lmoran@wtsg.com> wrote in message
news:2d6rstk6foh6ku2lvokkq6b3bbi38ipjqn@4ax.com...
> On Wed, 17 Oct 2001 15:20:29 +0100, JMT <CCX138@coventry.ac.uk> wrote
> wonderful things about sparkplugs:
>
> SNIP
> >
> >print qq(Press any key to continue . . .);
> ><STDIN>;
>
> Good but it would have to print out "Press Enter to continue..."
>
> Thanks though.

And your limited Perl knowledge is not sufficient to work out how to change
the message?




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

Date: Wed, 17 Oct 2001 18:41:11 -0500
From: Brehm <yes@yesIsuppose.org>
Subject: Re: newbie question - how to rename files with Perl?
Message-Id: <tr4sst49cf2v6e7pjjq53v853rfqgh2h8q@4ax.com>

Thanks very much for your responses; this will help a great deal.

On Tue, 16 Oct 2001 23:41:41 -0400, Benjamin Goldberg
<goldbb2@earthlink.net> scribbled:

>Brehm wrote:
>> 
>> Hello-
>> 
>> I was hoping to dive into Perl by learning how to do a simple task.
>> 
>> I spend quite a bit of time renaming files.  I would like a script /
>> program I write to do this for me.
>
>> For example, I do the following to all files:
>
>That means you want File::Find
>
>> 
>> -removing "_-_"  & replacing with "-"
>> -converting to lowercase
>> -replacing an empty space with "_"
>
>The first is s///, the second lc, and the third is tr//.
>Since for each file, you probably want to do all of these to it, have
>the wanted sub make a copy of $_, do the transformations on it, and if
>the new name differs from the old, rename the file.
>
>find( sub {
>    my $foo = $_;
>    $foo =~ s/_-_/-/g; $foo = lc $foo; $foo =~ tr/ /_/s;
>    rename( $_, $foo ) if $foo ne $_;
>}, @directories );



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

Date: Wed, 17 Oct 2001 20:26:21 -0400
From: Brian Carlson <bcarlso4@bellsouth.net>
Subject: Perl CGI problem printing Javascript...
Message-Id: <3BCE21AD.2AFDD909@bellsouth.net>

I have a perl cgi script, that when ran, prints out javascript.  I have
the following in my page....

<SCRIPT LANGUAGE="Javascript" SRC="www.pschallenge.com/cgi-bin/bc.pl"
type="text/javascript">
</script>

This doesn't work.  I don't get the perl JS code ran on the browser.
But when I run the perl code from the command line, and paste it in the
page, it runs fine.

Any thoughts?

Thanks,
Brian




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

Date: Wed, 17 Oct 2001 19:17:28 -0500
From: Tony Curtis <tony_curtis32@yahoo.com>
Subject: Re: Perl CGI problem printing Javascript...
Message-Id: <878ze9vm1z.fsf@limey.hpcc.uh.edu>

>> On Wed, 17 Oct 2001 20:26:21 -0400,
>> Brian Carlson <bcarlso4@bellsouth.net> said:

> I have a perl cgi script, that when ran, prints out
> javascript.  I have the following in my page....

> <SCRIPT LANGUAGE="Javascript"
> SRC="www.pschallenge.com/cgi-bin/bc.pl"
> type="text/javascript"> </script>

> This doesn't work.  I don't get the perl JS code ran on
> the browser.  But when I run the perl code from the
> command line, and paste it in the page, it runs fine.

> Any thoughts?

off-topic for comp.lang.perl.misc.  This is either a web
server or client/browser configuration problem.

hth
t
-- 
Oh!  I've said too much.  Smithers, use the amnesia ray.


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

Date: Wed, 17 Oct 2001 14:23:44 -0400
From: Jamuna Krishnappa <Jamuna.Krishnappa@fmr.com>
Subject: perl program converted to NT service-problems
Message-Id: <3BCDCCAF.BC7987B3@fmr.com>

Hello everybody,

I have perl program which I converted to an NT service, and once it's
started, afer 1 or two days, it keeps dyieng..Any reason, Please help
me..I am very despearate.

I have used srvany.exe from ntresource kit..and used perl2exe to convert
from .pl to .exe.

Any input will be greatly appreciated...

Thanks in advance..

Jamuna



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

Date: 18 Oct 2001 01:14:51 +0100
From: Andrew Gierth <andrew@erlenstar.demon.co.uk>
Subject: Re: precedence question
Message-Id: <87y9m9reh0.fsf@erlenstar.demon.co.uk>

>>>>> "Richard" == Richard Trahan <rtrahan@monmouth.com> writes:

 Richard> In other words, I cannot find any set of rules that justify
 Richard> autoincrementing the second $a before the first.

you are confusing "precedence" with "order of evaluation". They are not
related.

The fact that the lexer and/or parser sees the tokens in a particular
order is not relevent - the two autoincrements are part of separate,
unrelated subexpressions and there is therefore no required ordering
between them.

-- 
Andrew.


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

Date: Thu, 18 Oct 2001 00:54:50 GMT
From: Dave Tweed <dtweed@acm.org>
Subject: Re: precedence question
Message-Id: <3BCE26FD.8610E6FA@acm.org>

Richard Trahan wrote:
> The fact is that lexers receive their tokens from the left, and since
> Perl is lexically a LALR language, a yacc-type parser can be built
> based on precedences and at most one look-ahead token.

You are assuming far too much about the relationship between the parsing
of the source code and the execution of the generated code.

> But if that were so, then the first [$a++] should be shifted off the
> parser stack before the equals sign is even reached, implying that $a
> should be incremented there, and not on the right.

No, the parser doesn't execute code at all. It generates code that
gets executed later, in the proper sequence.

> In other words, I cannot find any set of rules that justify
> autoincrementing the second $a before the first.
> 
> It is not generally true that everything on the right side of an
> equals sign gets evaluated first (not, and, or, xor, comma, list
> operators looking rightward), so your explanation, although
> appreciated, is not sufficient.

The SYNOPSIS section of "perldoc perlop" seems to be fairly explicit to
me about precedence and associativity. "=" is right-associative, which
means (among other things) that the right side is evaluated before the
left side. "not", "and", etc. have even lower precedence than "=".

-- Dave Tweed


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

Date: Thu, 18 Oct 2001 00:56:07 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: precedence question
Message-Id: <i4asst8s1ofh8ks4h35qk87dr56bl49t3k@4ax.com>

Richard Trahan wrote:

>$var[$a++] = $var[$a++] + $value; # (Wall, 3rd ed., p. 107)

>I cannot justify the answer based on my (apparently wrong)
>understanding of precedence.

Don't bother. That code is evil. Don't use it.

-- 
	Bart.


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

Date: Wed, 17 Oct 2001 17:18:12 -0500
From: trammell@haqq.hypersloth.invalid (John J. Trammell)
Subject: Re: push, pop, shift, unshift, splice et al
Message-Id: <slrn9ss0t3.b7u.trammell@haqq.hypersloth.net>

On 17 Oct 2001 15:04:16 -0700, JRoot <awkster@yahoo.com> wrote:
> I need to loop through an array, identifying each element
> then discarding the element thus leaving an empty array when
> the loop finishes.
> 
> I read the faq's and perldocs on push, pop, shift, unshift
> and splice. I thought I had it figured out but when I ran this
> little program as a test, it never empties the array. It stops
> half way apparently because it re-indexes the array each time
> it shifts ????

One way:

my @array = qw[ boo bar baz quux ];

GRIBBLE:
{
	last GRIBBLE unless @array;
	my $dude = pop @array;
	print "Dude: $dude\n";
	redo GRIBBLE;
}



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

Date: Wed, 17 Oct 2001 18:38:04 -0400
From: "Mina Naguib" <spam@thecouch.homeip.net>
Subject: Re: push, pop, shift, unshift, splice et al
Message-Id: <_Knz7.5231$ht.412712@weber.videotron.net>


"JRoot" <awkster@yahoo.com> wrote in message
news:9efa6216.0110171404.72550265@posting.google.com...
> I need to loop through an array, identifying each element
> then discarding the element thus leaving an empty array when
> the loop finishes.

Do not modify an array while iterating over it. It can get messy and
confusing.

See bottom for safe examples.

>
> I read the faq's and perldocs on push, pop, shift, unshift
> and splice. I thought I had it figured out but when I ran this
> little program as a test, it never empties the array. It stops
> half way apparently because it re-indexes the array each time
> it shifts ????
>
> Is there someway I can get around this behaviour??
> Please don't send me back to the faq'a ... I'm all popped out.
>
> Thanks for the help
>
> #!perl -w
>
> use strict;
>
> my($x, $y);
> my @x = (1...10);
>
> foreach $x(@x){
>    print "# Element $x\n";
>    print "# Array: @x\n";
>    $y = shift(@x);
>    print "# Element removed: $y\n";
> }
>

Here's one approach I can think of:

while ($x = $x[0]) {
   print "# Element $x\n";
   print "# Array: @x\n";
   $y = shift(@x);
   print "# Element removed: $y\n";
}

Here's another:

while ($x = shift(@x)) {
   print "# Element just removed: $x\n";
   print "# Array: @x\n";
}



I'm sure there are others.




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

Date: Wed, 17 Oct 2001 22:40:52 GMT
From: Tom Hoffmann <tom.hoffmann@worldnet.att.net>
Subject: Re: push, pop, shift, unshift, splice et al
Message-Id: <UNnz7.143215$W8.3449280@bgtnsc04-news.ops.worldnet.att.net>

On Wednesday 17 October 2001 18:04, JRoot wrote:

> I need to loop through an array, identifying each element
> then discarding the element thus leaving an empty array when
> the loop finishes.
> 
> I read the faq's and perldocs on push, pop, shift, unshift
> and splice. I thought I had it figured out but when I ran this
> little program as a test, it never empties the array. It stops
> half way apparently because it re-indexes the array each time
> it shifts ????
> 
> Is there someway I can get around this behaviour??

Use a hash instead of an array. The hash data structure is much more 
appropriate for your problem, IMO.


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

Date: 17 Oct 2001 23:00:12 GMT
From: Thelma Lubkin <thelma@alpha2.csd.uwm.edu>
Subject: Re: push, pop, shift, unshift, splice et al
Message-Id: <9ql2hs$t2h$1@uwm.edu>

JRoot <awkster@yahoo.com> wrote:
: I need to loop through an array, identifying each element
: then discarding the element thus leaving an empty array when
: the loop finishes.

: I read the faq's and perldocs on push, pop, shift, unshift
: and splice. I thought I had it figured out but when I ran this
: little program as a test, it never empties the array. It stops
: half way apparently because it re-indexes the array each time
: it shifts ????

: Is there someway I can get around this behaviour??
: Please don't send me back to the faq'a ... I'm all popped out.

: Thanks for the help

: #!perl -w

: use strict;

: my($x, $y);
: my @x = (1...10);

: foreach $x(@x){
:    print "# Element $x\n";
:    print "# Array: @x\n";
:    $y = shift(@x);
:    print "# Element removed: $y\n";
: }

: # Element 1
: # Array: 1 2 3 4 5 6 7 8 9 10
: # Element removed: 1
: # Element 3
: # Array: 2 3 4 5 6 7 8 9 10
: # Element removed: 2
: # Element 5
: # Array: 3 4 5 6 7 8 9 10
: # Element removed: 3
: # Element 7
: # Array: 4 5 6 7 8 9 10
: # Element removed: 4
: # Element 9
: # Array: 5 6 7 8 9 10
: # Element removed: 5


 Is there a reason that you need to remove the elements one at a time?
 Why not print the elements and then set the array empty?

 #!perl -w

 use strict;

 my($x);
 my @x = (1...10);

 foreach $x(@x){
    print "# Element $x\n";
 }

 @x = ();




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

Date: 17 Oct 2001 20:22:22 -0400
From: herveus@Radix.Net (Michael Houghton)
Subject: Re: push, pop, shift, unshift, splice et al
Message-Id: <9ql7bu$e9$1@saltmine.radix.net>

Howdy!

In article <9efa6216.0110171404.72550265@posting.google.com>,
JRoot <awkster@yahoo.com> wrote:
>
>I read the faq's and perldocs on push, pop, shift, unshift
>and splice. I thought I had it figured out but when I ran this
>little program as a test, it never empties the array. It stops
>half way apparently because it re-indexes the array each time
>it shifts ????

You missed the part somewhere (I can't recall and am being too 
lazy to look it up) where it says not to add or remove elements
from an array that you are iterating over. That way lies 
unexpected behavior.
>
>Is there someway I can get around this behaviour??
>Please don't send me back to the faq'a ... I'm all popped out.
>
# untested code follows...

my @x = (1..10);
while (@x)
{
	my $y = shift @x;
	# do stuff with $y
}

yours,
Michael
-- 
Michael and MJ Houghton   | Herveus d'Ormonde and Megan O'Donnelly
herveus@radix.net         | White Wolf and the Phoenix
Bowie, MD, USA            | Tablet and Inkle bands, and other stuff
                          | http://www.radix.net/~herveus/


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

Date: Thu, 18 Oct 2001 09:37:23 +1000
From: "Tintin" <tintin@snowy.calculus>
Subject: Splitting on value pairs
Message-Id: <_Doz7.11$5p2.237596@news.interact.net.au>

I'm trying to parse a WELF (Webtrends Extended Log Format) file.

Each record is on a single line terminated by CRLF, and each field is a
simple id/value pair.  Each field is separated by whitespace, but if there
is whitespace in the value, it is enclosed in quotes.  For example:

id=firewall time="2001-10-14 12:01:05" fw=199.9.9.9 src=199.9.9.9

Obviously, I could do a simple split (if all values had no whitespace) to
get each value pair, but how do I cater for the quoted values?

I tried

my @records = split(/[\w"] [a-z]);

which comes very close to what I need, except that it slurps the first and
last character of each field pair.

Of course, I'm always open to other ways to achieve the result.  Utimately,
I want to have all the fields in a hash.




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

Date: Thu, 18 Oct 2001 00:08:30 GMT
From: garry@ifr.zvolve.net (Garry Williams)
Subject: Re: Splitting on value pairs
Message-Id: <slrn9ss7bs.l0g.garry@zfw.zvolve.net>

On Thu, 18 Oct 2001 09:37:23 +1000, Tintin <tintin@snowy.calculus> wrote:
> I'm trying to parse a WELF (Webtrends Extended Log Format) file.
> 
> Each record is on a single line terminated by CRLF, and each field is a
> simple id/value pair.  Each field is separated by whitespace, but if there
> is whitespace in the value, it is enclosed in quotes.  For example:
> 
> id=firewall time="2001-10-14 12:01:05" fw=199.9.9.9 src=199.9.9.9
> 
> Obviously, I could do a simple split (if all values had no whitespace) to
> get each value pair, but how do I cater for the quoted values?

Assumptions: 

The value immediately follows the `='.  

The sequence `="' cannot occur except as the start of a quoted value.  

The log record has been read into $line.  

    [ untested ]

    my $first;
    my @records;
    for ( split " ", $line ) {
	if ( /="/ ) {
	    $first = $_;
	}
	elsif ( $first ) {
	    push @records, $first . $_;
	    $first = "";
	}
	else {
	    push @records, $_ unless /="/;
	}
    }

> I tried
> 
> my @records = split(/[\w"] [a-z]);

That's a syntax error.  

[snip]

-- 
Garry Williams


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

Date: Thu, 18 Oct 2001 00:53:59 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: Splitting on value pairs
Message-Id: <vr9sstkp9rl3vb5mc86e6u2rhcmsgtv3ia@4ax.com>

Tintin wrote:

>id=firewall time="2001-10-14 12:01:05" fw=199.9.9.9 src=199.9.9.9
>
>Obviously, I could do a simple split (if all values had no whitespace) to
>get each value pair, but how do I cater for the quoted values?

Assuming there can be no nested quotes (or you'll have to patch for that
yourself), you can turn this inside out:

	@data = /((?:[^" ]|"[^"]*")+)/g;

-- 
	Bart.


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

Date: Wed, 17 Oct 2001 23:37:40 GMT
From: garry@ifr.zvolve.net (Garry Williams)
Subject: Re: Using a remote file with a Perl script
Message-Id: <slrn9ss5i3.l0g.garry@zfw.zvolve.net>

[ post re-ordered -- again ]

[ Please don't top post ]

On Wed, 17 Oct 2001 22:53:51 +0100, Alan Fleming <alan@scotlpuk.com>
wrote:

> "Garry Williams" <garry@ifr.zvolve.net> wrote in message
> news:slrn9srtph.kr9.garry@zfw.zvolve.net...
>> On Wed, 17 Oct 2001 21:43:23 +0100, Alan Fleming <alan@scotlpuk.com>
>> wrote:

[snip]

>> > Here's the code. All my programs are CGI, so the error messages
>> > are in HTML.  There are no error codes
>>
>> Oh, yes there are error codes.  You chose not to print them, but
>> they are there.

[snip]

> I added the $! to my code, to give the error reason. Then, I created
> an ascii text file filled with text, at the location:
> \\adminpc\mydocs\test.txt
> 
> When I ran a test script to read this file into an array, then
> display that array, I get the following message:
> 
> Sorry, but the file \\adminpc\mydocs\test.txt does not appear to
> exist - try a different file name.
> Reason: No such file or directory
> 
> It's a windows 2000 box, and I have set the mydocs share to be
> accessible by 'system', 'network', and 'everyone', still no luck. Is
> this a windows permissions problem, or is my CGI code at fault?

Then it's an OS issue.  Not a Perl issue.  

I don't have a clue what to do about accessing the remote file.  You
may want to try another news group that discusses such issues.
Probably something with the word `Windows' in it.  

But now you *know*, because you printed the error code.  

-- 
Garry Williams


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

Date: 17 Oct 2001 17:16:30 GMT
From: Juha Laiho <Juha.Laiho@iki.fi>
Subject: Re: Writing and reading encrypted string (password)
Message-Id: <9qkede$iqt$1@ichaos.ichaos-int>

Lars Oeschey <oeschey@media-saturn.com> said:
>On Tue, 16 Oct 2001 09:46:16 -0500, trammell@haqq.hypersloth.invalid
>(John J. Trammell) wrote:
>
>>You could obfuscate it with MIME::Base64.
>
>hm, that could work indeed. Though I wan't to stay away from Modules
>not included with Activestate Perl a bit, since I don't know on how
>much machines the program will be later, and everywhere would have to
>be the module installed then (on NT with ppm and proxy settings that
>is a bit work)

So, the goal is to just prevent anyone (mostly, an administrator)
accidentally seeing the passwords.

Perhaps writing your own version of Caesar encryption (i.e. some
Rot13 variant) would fit your needs? Just shift the characters some
known amount of positions. Then when you need the cleartext password,
do the shift back.

If you want to obfuscate more, you might add two characters in the
beginning (or to the end) of the password field:
- one that has the true length of the user-entered password (f.ex.
  a=1, b=2, ..., z=26
- one that tells the number of positions this particular password
  was shifted when obfuscating

Then write out the obfuscated password as a 28-character string, adding
random characters from end of the user-entered password until the field
is full.

Shouldn't be too hard to write. And doesn't add any security, either,
but might make the life of an administrator a little bit more comfortable.
-- 
Wolf  a.k.a.  Juha Laiho     Espoo, Finland
(GC 3.0) GIT d- s+: a C++ UH++++$ UL++++$ P++@ L+++ E(-) W+$@ N++ !K w !O
         !M V PS(+) PE Y+ PGP(+) t- 5 !X R !tv b+ !DI D G e+ h--- r+++ y+++
"...cancel my subscription to the resurrection!" (Jim Morrison)


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

Date: Wed, 17 Oct 2001 22:42:38 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: Writing and reading encrypted string (password)
Message-Id: <5v1sst4p018s30a33a2cbfud28d5oql1l1@4ax.com>

Logan Shaw wrote:

>But you have to store the key somewhere so that you can decrypt the
>passwords.  If they can get the .ini file, they can get the key too,
>right?

I had an idea for a cute solution for that today.

Perl code is plain source. So wherever or however you store the key, it
is possible for a programmer to edit the source, and print out the key
and/or password just before the script uses it for its real purpose.

But what if the key is a digest  (MD::Digest, a CRC or something like
that) of the script itself? Once the hacker edits the source to get at
the key, the decryption would no longer work. The only solution would be
for the user to reenter his password, and for the script to encrypt it
using the new key. This will have to be done every time the script is
edited.

One the hacker finds this out, he can always use an external script to
get at this digest value, so the concept is not fullproof. But it's
sufficient for the level of security that is wanted here, I would think.

-- 
	Bart.


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

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


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