[13807] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 1217 Volume: 9

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Oct 29 00:21:24 1999

Date: Thu, 28 Oct 1999 21:21:05 -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: <941170865-v9-i1217@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Thu, 28 Oct 1999     Volume: 9 Number: 1217

Today's topics:
    Re: perlguts question (Mitchell Morris)
        Q: Capture HTML tags. (Park, Jong-Pork\)
    Re: Q: digit-wise number comparisons ? <bivey@teamdev.com>
    Re: Q: digit-wise number comparisons ? <bivey@teamdev.com>
    Re: Q: Hashes of Hashes of Hashes <sjohns17@uic.edu>
    Re: Q: Hashes of Hashes of Hashes <bexxx@hasiland.com>
    Re: Q: Hashes of Hashes of Hashes <partha@urbana.css.mot.com>
    Re: Q: Hashes of Hashes of Hashes (Clinton Pierce)
    Re: Q: Hashes of Hashes of Hashes (Craig Berry)
    Re: Recursive file/folder indexing <gellyfish@gellyfish.com>
    Re: regex match with empty string <ltl@rgsun40.viasystems.com>
    Re: regex match with empty string (Sam Holden)
    Re: Regular Expression <aqumsieh@matrox.com>
    Re: Review request!  Does this module seem useful/corre (Abigail)
    Re: Scripts that invoke one another via Location: and/o (Ben Blish)
    Re: Scripts that invoke one another via Location: and/o (Ben Blish)
    Re: Scripts that invoke one another via Location: and/o <lr@hpl.hp.com>
        shtml / perl problem newsmf@bigfoot.com
        slow txt processing problem (Mike Collins)
    Re: sysread / syswrite ? <gellyfish@gellyfish.com>
    Re: System Requirement (Abigail)
        THNX!!!!!!!!!!!!!!! <duthler@tebenet.nl>
    Re: Why can't I get this uniq/perl thing right? <dchristensen@california.com>
    Re: Why can't I get this uniq/perl thing right? <lr@hpl.hp.com>
    Re: Why can't I get this uniq/perl thing right? (Tad McClellan)
    Re: Why can't I get this uniq/perl thing right? (Tad McClellan)
        Win NT / Ms SQL & Perl dragnovich@my-deja.com
    Re: Win NT / Ms SQL & Perl <cassell@mail.cor.epa.gov>
        Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)

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

Date: 28 Oct 1999 19:16:51 GMT
From: mgm@unpkhswm04.bscc.bls.com (Mitchell Morris)
Subject: Re: perlguts question
Message-Id: <slrn81h892.gjq.mgm@unpkhswm04.bscc.bls.com>

In article <38187FB3.9BD37607@ife.ee.ethz.ch>, Alex Rhomberg wrote:
[snip]
>
>I can now give a representation of a struct in Perl and automatically
>create a C++ function that converts this struct to a Hashref
>(recursively if must be)
>
>Is there an easy way to check if the reference count of such a data
>structure is correct?
>
>- Alex

The reference count is available as sv_refcnt, so you can always peek under
the covers yourself (cf sv.h). I don't imagine, though, that you'll find it
as useful as you might want ... the reference counts will be correct if your
algorithm is correct, and if your algorithm is incorrect the reference counts
will be unpredictable. Consequently, even if the numbers are "right" you're
not necessarily any more sure of correct functionality that you are after a
code walkthrough. On the other hand, Perl is notorious for doing what you
meant in most cases and this is still true even when viewed from the
extender/embedder's point of view.

As an example, here is an untested-but-cut-n-pasted subroutine to return a
reference to a hash of lists (references, of course):

XS(xs_func)
{
  if(items != 1)
    croak("-1 karma for dissing the programmer");
  SP -= items;

  char* arg = (char*)SvPV(ST(0), PL_na);

  HV* hv = newHV();

  AV* av = newAV();
  vector<nvpair_t> v = sooper_seekrit_function(arg);
  vector<nvpair_t>::iterator i;
  for(i = v.begin(); i < v.end(); i++)
    av_push(av, newSVpv(i->c_str(), 0));
  hv_store(hv, "sooper_seekrit", 14, newRV_noinc((SV*)av), 0);

  av = newAV();
  v = another_seekrit_function(arg);
  for(i = v.begin(); i < v.end(); i++)
    av_push(av, newSVpv(i->c_str(), 0));
  hv_store(hv, "another_seekrit", 15, newRV_noinc((SV*)av), 0);

  XPUSHs(sv_2mortal(newRV_noinc((SV*)hv)));
  PUTBACK;
}

The thing to notice here is that every newRV() call is the "noinc" kind.  The
other thing to notice is that av_push() doesn't increment the reference count
of the item you give it, so you don't have to dork with the counts at all.
Funny how it works out, isn't it? The ownership of things (mostly) passes
around as you'd like it, even if you're not really sure yet how ownership
ought to be passing.



If you're having odd memory artifacts and suspect your subroutines are the
culprit, my suggestion is to single-step through the subroutines with a
debugger and display the reference counts immediately before and after each
av_*() and hv_*() call.  It's slow and tedious, but you will have a much
better idea of what you're doing to yourself afterwards. Once you get the
feel of it, you can read Perl's source code to determine where ownership
passes much more quickly.


-- 
Mitchell Morris

Randal can write one-liners again.  Everyone is happy, and peace spreads
over the whole Earth.
	-- Larry Wall


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

Date: Fri, 29 Oct 1999 06:56:32 +0900
From: "นฺมพบน \(Park, Jong-Pork\)" <okpolis@okclub.com>
Subject: Q: Capture HTML tags.
Message-Id: <fRPAf#YI$GA.257@news.thrunet.com>

Hello.

I tried this.

$file = "<A href="http...">Link site name1</A> or next <A href...>Link2</A>";
$file .= "and <A href...>Link3</A>";

$regexp = '<A.*?)>(.*?)<\/A>';

foreach $tmp ($file =~ /$regexp/is) {
print "$tmp\n";
}

I hope this print result, "Link site name1\nLink2\nLink3".
BUT it work "Link site name1</A> or next <A ...>Link2</A> and\nLink3";





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

Date: 27 Oct 1999 17:13:22 GMT
From: "William" <bivey@teamdev.com>
Subject: Re: Q: digit-wise number comparisons ?
Message-Id: <01bf209e$ce7292c0$3527e1ce@bill.jump.net>

Larry Rosler <lr@hpl.hp.com> wrote in article
<MPG.1280c924b6656a6098a13f@nntp.hpl.hp.com>...
[...] 
> But I didn't think to use tr/// to count the bytes, which is a great 
> performance improvement.

It's the simple stuff that goes first :-)

Had someone asked me how to count characters I'd have said,
"Why, tr/// of course!" But when it came to typing, I guess
I had a bout of Perl coding aphasia... -Wm



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

Date: 27 Oct 1999 17:16:37 GMT
From: "William" <bivey@teamdev.com>
Subject: Re: Q: digit-wise number comparisons ?
Message-Id: <01bf209f$416525e0$3527e1ce@bill.jump.net>

M.J.T. Guy <mjtg@cus.cam.ac.uk> wrote in article
<7v7aac$ftc$1@pegasus.csx.cam.ac.uk>...
> Ooops.   Cut and paste cockup.    I should have written "xor on
_strings_"
> instead of "xor".   And the correct version of the program (which I had
> tested) is
> 
>           print "\$a and \$b sufficiently different\n"
>                       if ((my $x="$a"^"$b") =~ tr/\0//) < 5;

Much nicer. Passed my test with flying colors (and printing out
the results of the xor produces some very interesting formatting
effects :-) -Wm



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

Date: Thu, 28 Oct 1999 14:22:32 -0500
From: Seth David Johnson <sjohns17@uic.edu>
Subject: Re: Q: Hashes of Hashes of Hashes
Message-Id: <Pine.A41.4.10.9910281418300.116522-100000@tigger.cc.uic.edu>

On Thu, 28 Oct 1999, Ralf Beckers wrote:

> Hi,
> 
> dummy question:
> how can I access (read/write) hashes of hashes of hashes?
> 
> In the docs I only found "hashes of hashes" ...

You do it the same way, only "up" one level :-)

    my %hash = (foo => { bar => { baz => 'yikes!' } } );

then...

    $hash{'foo'}{'bar'}{'baz'}

should get you:

    'yikes!'

-Seth
 www.pdamusic.com



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

Date: Thu, 28 Oct 1999 21:47:07 +0200
From: Ralf Beckers <bexxx@hasiland.com>
Subject: Re: Q: Hashes of Hashes of Hashes
Message-Id: <3818A83B.7A4F8104@hasiland.com>

Hi Seth,

Seth David Johnson wrote:
> > how can I access (read/write) hashes of hashes of hashes?
> You do it the same way, only "up" one level :-)
>     my %hash = (foo => { bar => { baz => 'yikes!' } } );

Thanks a lot, that works ;-)

bexxx


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

Date: Thu, 28 Oct 1999 14:42:03 -0500
From: Parthasarathi Ramanujam <partha@urbana.css.mot.com>
Subject: Re: Q: Hashes of Hashes of Hashes
Message-Id: <3818A70B.8B4BE9D5@urbana.css.mot.com>

Well, the same way as for "hashes of hashes".......
To make it simpler, try making a temporary intermediate variable which
will hold the "hashes of hashes" and then use the same as mentioned in
the documentation.

HTH
-Partha

Ralf Beckers wrote:

> Hi,
>
> dummy question:
> how can I access (read/write) hashes of hashes of hashes?
>
> In the docs I only found "hashes of hashes" ...
>
> Thanks in advance,
> Ralf Beckers



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

Date: Thu, 28 Oct 1999 19:23:38 GMT
From: cpierce1@ford.com (Clinton Pierce)
Subject: Re: Q: Hashes of Hashes of Hashes
Message-Id: <3819a2a2.1997144762@news.ford.com>

On Thu, 28 Oct 1999 19:55:21 +0200, Ralf Beckers <bexxx@hasiland.com>
wrote:
>dummy question:

Actually, it is.

>how can I access (read/write) hashes of hashes of hashes?
>
>In the docs I only found "hashes of hashes" ...

Have you no imagination?

-- 
   Clinton A. Pierce       "If you rush a Miracle Man, you
 clintp@geeksalad.org       get rotten Miracles."  -- Miracle Max,
http://www.geeksalad.org                       The Princess Bride


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

Date: Thu, 28 Oct 1999 21:41:50 GMT
From: cberry@cinenet.net (Craig Berry)
Subject: Re: Q: Hashes of Hashes of Hashes
Message-Id: <s1hgounfr0877@corp.supernews.com>

Ralf Beckers (bexxx@hasiland.com) wrote:
: dummy question:
: how can I access (read/write) hashes of hashes of hashes?
: 
: In the docs I only found "hashes of hashes" ...

The same syntax and semantics apply, one level deeper.  Remember that even
though we often say things like "hashes of hashes" or "arrays of arrays",
really all levels after the first should have "references to" prepended;
it's just left out for brevity.

So:

#!/usr/bin/perl -w
# hohoh - demo of hashes of hashes of hashes
# Craig Berry (19991028)

use strict;

my %hohoh = (
  a => {
    1 => {
      xx => 'foo',
      yy => 'bar'
    },
    2 => {
      zz => 'quux'
    }
  },
  b => {
    3 => {
      ww => 'baz'
    }
  }
);

print "$hohoh{b}{3}{ww}, $hohoh{a}{1}{yy}\n";

-- 
   |   Craig Berry - cberry@cinenet.net
 --*--  http://www.cinenet.net/users/cberry/home.html
   |   "They do not preach that their God will rouse them
      a little before the nuts work loose." - Kipling


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

Date: 28 Oct 1999 20:52:26 -0000
From: Jonathan Stowe <gellyfish@gellyfish.com>
Subject: Re: Recursive file/folder indexing
Message-Id: <7vad2a$10l$1@gellyfish.btinternet.com>

On Wed, 27 Oct 1999 19:10:51 -0400 Scott Edward Skinner wrote:
> I'm looking for a simple example of a Perl script that takes a folder path
> as an argument and iterates through every nested file and folder in that
> path, all the way down.
> 
> I don't need a complete program, just the minimum necessary to illustrate
> the basic recursive concepts.
> 

Of course you will really want to use the module File::Find in real life
but just for shits and giggles - here is something I knocked up when
someone asked about creating a directory tree - this outputs nested HTML
lists showing the directory structure and the files - the reason *I* 
didnt use File::Find was that it seemed too difficult to recursively
process the tree structure into an array as seemed natural - of course
you will almost certainly run out of memory in a deep tree with lots
of files and has *ahem* undefined behaviour in the face of symbolic links
and all those other nasty things that File::Find shields you from ...


#!/usr/bin/perl -w

use strict;

my $input_dir = $ARGV[0] || '.' ;

MAIN:
{
   my @tree;
   dirwalk ($input_dir,\@tree);
   print "<OL>\n";
   printtree(\@tree);
   print "</OL>\n";
}

sub dirwalk 
{
   my ($dir,$tree) = @_ ;

   push @{$tree},($dir =~ m#([^/]+$)#);

   opendir DIR, $dir || die "Couldnt open $dir - $!\n";
   my @entries = grep !/^\.{1,2}$/, readdir(DIR);
   closedir (DIR);

    foreach my $item (@entries) 
      {
        my $fullpath = "$dir/$item";

        if ( -d $fullpath ) 
          {
            dirwalk ( $fullpath,\@{$tree->[@{$tree}]});
          } 
        else 
          {
            push @{$tree},$item;
          }
      }
}

sub printtree
{
  my $tree = shift;

  print "<LI>",shift @{$tree},"/\n";
  print "<OL>\n";
  foreach my $item ( @{$tree} )
   {
     if (ref $item eq "ARRAY" )
       {
        printtree($item);
       }
     else
       {
         print "<LI>\n";
         print $item,"\n";
       }
   }
  print "</OL>";
}

Have fun ...

/J\
-- 
Jonathan Stowe <jns@gellyfish.com>
<http://www.gellyfish.com>
Hastings: <URL:http://dmoz.org/Regional/UK/England/East_Sussex/Hastings>


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

Date: 29 Oct 1999 02:35:22 GMT
From: lt lindley <ltl@rgsun40.viasystems.com>
Subject: Re: regex match with empty string
Message-Id: <7vb15a$kt$1@rguxd.viasystems.com>

Oh darn.  I'm quoting somebody in here with ":>>" but I lost
the attribution.    Xah is ":>"

Xah Lee <xah@best.com> wrote:
:>>     If the PATTERN evaluates to a null string, the last
:>>     successfully executed regular expression is used instead.

:>But what happens if there is no regex call before? as in

:>#!/usr/local/bin/perl -w
:>use strict;
:>if ('some' =~ m//) {print 'match'} else {print 'no'}

:>the delightfully detailed and accurace and precise perl
:>documentations didn't say?

So why would you make an assumption about what it does and build
a program around that assumption?

:>You have to understand that the above test code matches yet
:>the one posted before doesn't. It's a giant mystery to perhaps all except
:>a few implementors.

Yeah.  So?

:><rant>
:>fucking, fuck, all fucked, fucking stupid Perl.

Gratuitous.  The last time you were here you were more
funny.  Please watch some Chris Rock shows and figure out
how to make your profanity funny.

:>In other languages, one looks up docs and moves on.

Obviously you did not look up this behavior in the docs because
the doc never says what it would do.

:>In Perl, testing is in practice a necessacity, because
:> fucking perl docs are so poor a quality that the best it
:>can do is give one a guide of things. Poor quality docs is
:>just a side effect. The source problem is Perl and it's
:>following culture. Precision and docs are discouraged.
:>Mumble jumble magic or TIMTOWTDI (on the level of stupid
:>sugar syntax) or whatnot shit are encouraged and loved by all here.
:></rant>

TomC doesn't play here any more.  Attacking the docs will not
get you the response you would like.

Your assesment of Perl and its culture does not follow my own 
observations.  How do you arrive at a conclusion that "precision
and docs are discouraged?"

You are allowed to eliminate most of the TIMTOWTDI magic if you so
choose.  The culture of this newsgroup is to drive towards the best
way to do it.  Thus the constant harping on "use strict; invoke with
-w; check system return codes; 'correct' quoting..."

:>> In the specific case below, I don't honestly see the point.  Maybe if we
:>> had some idea of what you were trying to accomplish, we'd have better
:>> suggestions.  Are you maybe putting a variable inbetween the //, which
:>> sometimes evaulates to the empty string?

:>...yes, but I'm not really interested in getting a solution
:>to whatever I was doing. I have plenty know-how to do what I want.
:>Suffice it to say that a bug in my program traced down to that, and fucking
:>wasted my time. I am interested in why perl hehaved the way it did, in
:>precise terms.
:>(god help us if Larry or Tom couldn't answer that.)

You write a program that depends on regular expressions provided
from an external source and then bitch about it when one of them
doesn't work the way you "hoped" it would?  Or did you even consider
this case when you wrote it?  I suspect that you didn't even think
about this case until it came up.  If the program had been written
in any other language and your input data presented a case that you
had not designed the program to handle, what would you expect it to
do?

:>Thanks for the pointer to the perlop. (I've read a million perl
:>literatures... (and I CAN prove it to you) but you know how it is.)

:>Who wrote Find::File? It's such a crap in quite a few perspectives.

I can't argue with this.  Twice in the past I've just copied the code
from File::Find and modified it to suit my immediate needs since I
couldn't seem to make it do what I wanted in the raw.  Rewriting the
module to improve it is not so easy though.  

:>To the other guy who was *plonking* me: Don't be a moron, I'm not
:>interested in perl sugar syntax timtowtdies. Does not perl's freedom also
:>allow
:>people to not use whatever shortcut it has? I'll put a fucking m in //
:>anytime!
:>and if next time you can make a sound criticism on someone's code at the
:>algorithm level, that would perhaps decreases perl community's stupidity
:>a little bit on the whole.

You can't have it both ways.  You made statements that were not well
supported with logical argument and now you complain that someone
else attacks you without making sound criticism of your algorithm?
Pot, Kettle, Black.

:>Finally, to those unix weenies: Flame me, please do. I love it. Go ahead and
:>post a message about how you plonked me or killfiled me or how I'm a fucking
:>troll or how you've send me to /dev/nul. I love it. I'll be waiting to read
:>those messages and thank you.

There are kernels of truth in what you write.  But you have been
boorish in this thread.  Please try to be more entertaining.


-- 
// Lee.Lindley   /// I used to think that being right was everything.
// @bigfoot.com  ///  Then I matured into the realization that getting
////////////////////   along was more important.  Except on usenet.


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

Date: 29 Oct 1999 03:50:04 GMT
From: sholden@pgrad.cs.usyd.edu.au (Sam Holden)
Subject: Re: regex match with empty string
Message-Id: <slrn81i6bb.hj0.sholden@pgrad.cs.usyd.edu.au>

On 29 Oct 1999 02:35:22 GMT, lt lindley <ltl@rgsun40.viasystems.com> wrote:
>Oh darn.  I'm quoting somebody in here with ":>>" but I lost
>the attribution.    Xah is ":>"
>
>Xah Lee <xah@best.com> wrote:
>
>:>To the other guy who was *plonking* me: Don't be a moron, I'm not
>:>interested in perl sugar syntax timtowtdies. Does not perl's freedom also
>:>allow
>:>people to not use whatever shortcut it has? I'll put a fucking m in //
>:>anytime!
>:>and if next time you can make a sound criticism on someone's code at the
>:>algorithm level, that would perhaps decreases perl community's stupidity
>:>a little bit on the whole.

I'm glad I plonked you I admit...

I didn't say you had to not use $_ =~ m/ ... 

I said you could leave out the $_ =~ part.

I said you could also leave out the m.

I said that because I thought that you might not know, since you had
obviously not read the documentation. 

I can't see how I was being a moron. I mentioned something that might have
saved you some line noise since I though you didn't know about it.

There was no point commenting on the algorithm, I answered the question
you had asked. In answering I actually read the whole message and didn't like
your attitude to things so I wasn't going to go out of way to talk about
your algorithm. All I did was post what I has written instead of writing some
more.

>
>You can't have it both ways.  You made statements that were not well
>supported with logical argument and now you complain that someone
>else attacks you without making sound criticism of your algorithm?
>Pot, Kettle, Black.

I didn't attack, I said read the docs. I said you don't have to use some of
the verbosity. I then read a line of text that I didn't like at all at the
time of the morning it was and without further ado hit 'post' and then
'plonk'. But then again it really doesn't matter.


>
>:>Finally, to those unix weenies: Flame me, please do. I love it. Go ahead and
>:>post a message about how you plonked me or killfiled me or how I'm a fucking
>:>troll or how you've send me to /dev/nul. I love it. I'll be waiting to read
>:>those messages and thank you.

That would be /dev/null ;)

-- 
Sam

The most exciting phrase to hear in science, the one that heralds new
discoveries, is not "Eureka!" (I found it!) but "That's funny ..."
	--Isaac Asimov 


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

Date: Thu, 28 Oct 1999 18:17:56 -0400
From: Ala Qumsieh <aqumsieh@matrox.com>
Subject: Re: Regular Expression
Message-Id: <x3yhfjb86zw.fsf@tigre.matrox.com>


Apisilp Trunganont <b39ast@ku.ac.th> writes:

> $a = "[b]abc[/b] [b]def[/b]";
> 
> And I want to change the value of this variable to "<b>abc</b>
> <b>def</b>".
> I try to use this regexp.
> 
> $a =~ s/\[b\](.*)\[\/b\]/<b>$1<\/b>/g;
> 
> But it doesn't work. When I print this variable, it shows.
> 
> <b>abc[/b] [b]def</b>
> 
> How can I solve this problem?

Matches are greedy in Perl. In your example, the '.*' actually matches
'abc[/b] [b]def' and not 'abc' and then 'def' as you expected. You
should ask Perl to match as little as possible:

	$a =~ s/\[b\](.*?)\[\/b\]/<b>$1<\/b>/g;

Also, if all you want to do is change [s to <s and ]s to >s, you can
use tr///:

	$a =~ tr/[]/<>/;

HTH,
--Ala



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

Date: 28 Oct 1999 18:13:16 -0500
From: abigail@delanet.com (Abigail)
Subject: Re: Review request!  Does this module seem useful/correct?
Message-Id: <slrn81hm3e.66b.abigail@alexandra.delanet.com>

Clinton Pierce (clintp@geeksalad.org) wrote on MMCCXLVII September
MCMXCIII in <URL:news:3816387d.347839304@news.roalok1.mi.home.com>:
'' On Tue, 26 Oct 1999 16:30:54 -0400, Ala Qumsieh <aqumsieh@matrox.com>
'' wrote:
'' >cpierce1@ford.com (Clinton Pierce) writes:
'' >
'' >> =head1 BUGS
'' >> If the function called returns a list, and you use a scalar to receive
'' >> them, only the first value is put into the scalar.  Presumably, since you
'' >> know what the API for this function is anyway, use the right type: an
'' >> array or a scalar.
'' >
'' >So what happens if the called function uses wantarray() ?
'' 
'' It loses.  :-)  That is a valid criticism, I suppose.  And I should
'' document it.
'' 
'' That's why this is under the "bugs" section.  Without adding
'' additional parameters to the catchit() call, there's no way to
'' indicate that you'd like the target function called in an array or
'' scalar context.  The purpose of this class is itself a hack to get
'' around someone else's broken API.


You could of course give catchall an extra argument, that determines
the context in which the function called should be called. 'true' for
list context, 'false but defined' for scalar context, and undefined for
void context.



Abigail
-- 
perl -e '* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
         / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / 
         % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % %;
         BEGIN {% % = ($ _ = " " => print "Just Another Perl Hacker\n")}'


  -----------== Posted via Newsfeeds.Com, Uncensored Usenet News ==----------
   http://www.newsfeeds.com       The Largest Usenet Servers in the World!
------== Over 73,000 Newsgroups - Including  Dedicated  Binaries Servers ==-----


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

Date: Thu, 28 Oct 1999 21:19:13 GMT
From: bblishA@TblackbeltDO.Tcom (Ben Blish)
Subject: Re: Scripts that invoke one another via Location: and/or URI: - environment persistence?
Message-Id: <3818b682.156317366@news.montanavision.net>

On 28 Oct 1999 03:46:58 -0500, abigail@delanet.com (Abigail) wrote:

>Logfiles are, of course, always available. You just made a mistake by
>using a service that doesn't give you want you want.

No, Abigail, I didn't "make a mistake". I picked an inexpensive
service that gave me exactly what I wanted. If I need count
data, I can *make* it just fine, because CGI is available to me
in the inexpensive package. Other services cost more; I like
to spend my money for things I actually DO need. ICOM's choice to
make logging an extra-cost option conversely got them to provide
very, very inexpensive hosting, hosting which happens to suit my
needs exactly. However, if you'd like to pony up the money for a
more comprehensive service provider, or the funds to support a local
server here on site, I'll send you the address to mail the money
to. If not, then your general opinions on counters are not
applicable here. Nor were they applicable when you sent that
very rude and ignorant reply with the random numbers to the person
who asked for help previously. When you do something like that, you
look like someone whose preconceptions have overcome their ability to
reason. If you're looking to score points by following the (vastly
mistaken) rant in the Perldocs, you've failed. Your position is silly
and unsupportable. And there you have it.

>'' It may even be more convenient, or inspiring, to look at the page in
>'' particular with the counter on it as one contemplates more effort for
>'' that page's content.
>
>Well, if a counter is signicificant to the content, I would leave the
>page immediately - screaming.

Annoying no one but yourself. Nice way to live. :-)

>This page has been visited 12319871298743216509217409218472640214 times
>since 10 seconds ago!

You know, I'm not at all sure where you get this strange idea that
counters are so unreliable, other than parroting whoever made the
irrational statement in the Perldocs. Accurate depictions of specific
visitors, no. But they absolutely do provide a relative means to see
what the interest in a particular page is. On EBay (just as a for
instance), counters on my auctions run at one level if the auction is
vanilla, and they run much faster if I put a group of keywords at the
top of the auction. In addition, with the keywords, the auctions uniformly
do better in terms of bids. And, it makes perfect sense that
this would be so. The inescapable conclusions are that the counters
are responding in a manner that is indeed representative of the
visitors to the auction page, and that putting the counters there
serves as solid verification of the idea that putting keywords in
the auctions is a good idea - hence, a useful and powerful marketing
tool. One could (and should) intuit this in reverse - that adding
good keywords should make the page hits go up. Since the process does
indeed work this way, and is verified, we now know that we can
change the keywords, watch the counters, and in this way "tune"
the auction for best response. All of this is positive, real-world
proof that your entire "counters = useless" position is bunk. :-)
But it's only one example. Your whole position is groundless, and
you'll look a lot less silly if you abandon it. :-)

Take care!

--Ben



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

Date: Thu, 28 Oct 1999 21:37:42 GMT
From: bblishA@TblackbeltDO.Tcom (Ben Blish)
Subject: Re: Scripts that invoke one another via Location: and/or URI: - environment persistence?
Message-Id: <3818bdfb.158230886@news.montanavision.net>

On 28 Oct 1999 10:56:30 +0100, Jonathan Stowe <gellyfish@gellyfish.com> wrote:

>This is not mentioned in the Perl documentation because it has nothing to
>do with Perl.

I rather think that trying to find out how Perl's environment
is set by reading docs not on Perl wouldn't get me very far. :)

This is an interaction between the language and the transport
and the host.

I described it earlier as being in a netherland between CGI and
Perl, and I still think that's reasonably accurate. In any case,
the statement it has "nothing to do with Perl" is *quite* inaccurate.

These things get into Perl somehow, and they in fact do so by inhabiting
Perl's environment handling, or STDIN, as it turns out. My question
was specific to Perl's environment in the two cases, and how Perl,
specifically, could in turn set that environment in a similar
manner "on the way out" so that another Perl script would see
those variables as if they had come from a form.. In any case,
I do have my Perl-specific answers, and I have solved the problems,
despite the majority of response posts which had little to do
with the issues I raised. There are some people out there with
an interest in other than pontificating about where the boundaries
of questions lie, fortunately. The one thing I admit little
interest in is geeky arguments like these.

>  The CGI specification describes the mechanisms by which
>parameters are to be passed to a program *whatever language it might be
>written in*

My question was about how they appear to the program, not
how they were passed to it. There is a huge difference.
Then, I was interested in how to get them out in the
same fashion. Using Perl. There, got it now? :-)

> - if you are so overcome with false hubris that you must 
>reinvent the wheel

Hubris? I'm interested in understanding the mechanism. Hardly
hubris, false or otherwise. I've found, over many years of
programming, that the most effective strategy is to understand
as much as you can about any situation you'll be working with.
In any case, this isn't for you to judge, or at least, if you
do, I'll ignore your opinion, and quite justifiedly so. :-)

Using cookbooks and other people's libraries is not the best way to
accomplish basic learning. Perhaps it would help you understand if
I explain that this isn't just about "getting from point a to
point b", _it's_ _about_ _learning_. I love to learn. If you think
that's hubris... I think you might need a visit back to the
OED. :-)

> and ignore the variety of modules that make working
>with this specification simple then I would suggest that you start reading
>that specification:
>
>   <http://hoohoo.ncsa.uiuc.edu/cgi>
>
>And while you are at it you had better look at the CGI FAQ too:
>
>    <http://www.webthing.com/tutorials/cgifaq.html>

Thanks for the pointers. Hope you've learned something here today, also.

Take care,

--Ben




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

Date: Thu, 28 Oct 1999 14:51:11 -0700
From: Larry Rosler <lr@hpl.hp.com>
Subject: Re: Scripts that invoke one another via Location: and/or URI: - environment persistence?
Message-Id: <MPG.12826527ba0fb15598a155@nntp.hpl.hp.com>

In article <3818b682.156317366@news.montanavision.net> on Thu, 28 Oct 
1999 21:19:13 GMT, Ben Blish <bblishA@TblackbeltDO.Tcom> says...
> On 28 Oct 1999 03:46:58 -0500, abigail@delanet.com (Abigail) wrote:
> 
> >Logfiles are, of course, always available. You just made a mistake by
> >using a service that doesn't give you want you want.

 ...

No, logfiles are *not* always available.  Here at HP Labs, despite my 
warm relationship with the webmaster, NO WAY would he allow me access to 
the server logs, which are viewed as proprietary.

When the need arose, I set up a sophisticated webcounting system that 
now has several hundred satisfied users.  It uses various techniques to 
deal with proxying and caches -- the things that folklore here says make 
counters useless.

> ... All of this is positive, real-world
> proof that your entire "counters = useless" position is bunk. :-)
> But it's only one example. Your whole position is groundless, and
> you'll look a lot less silly if you abandon it. :-)

Right on!  I would have commented on this prejudice long sooner, but it 
is really off-topic for a Perl newsgroup.  And it still is.

-- 
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com


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

Date: Thu, 28 Oct 1999 22:06:11 GMT
From: newsmf@bigfoot.com
Subject: shtml / perl problem
Message-Id: <7vahcg$i15$1@nnrp1.deja.com>

Hi -

I've shtml-enabled a directory called "/exampledir"

test.shtml in that directory calls the script test.pl using
<!--#include virtual = "/cgi-bin/test.pl" -->

However, I get
[an error occurred while processing this directive]

If I run test.pl directly via www.mydomain.com/cgi-bin/test.pl it
executes all right (i.e. doing the redirect it's supposed to do).

How do I get test.pl to work when it is invoked through the shtml page
at www.mydomain.com/emampledir/test.shtml ?

Thanks a lot for helping.

Cheers,

Marc.

Here's test.pl:

#!/usr/bin/perl -w
# test.pl

$url = "http://www.perl.com/CPAN/";
        print "Location: $url\n\n";
        exit;



Sent via Deja.com http://www.deja.com/
Before you buy.


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

Date: Fri, 29 Oct 1999 03:29:32 GMT
From: mike@w3z.com (Mike Collins)
Subject: slow txt processing problem
Message-Id: <38190ffe.25958616@news.hardlink.com>

The script shown below checks about 50 fields against 2800 lines in
another table to change cryptic codes into user friendly definitions.
A couple of other subs check additional tables making substitutions.
Processing 60 records (delim txt) allows enough time to brew a pot of
coffee before it finishes.

#!c:\perl\bin\perl.exe
use Text::ParseWords;

open (TESTTXT, "./dat_in/vehicles.txt") || die $!;
@list = <TESTTXT>;
close TESTTXT;

open (CODES, ">./dat_out/codetxt.txt") || die $!;
for $entry (@list) {
	$entry =~ s/\\/XXA/g;

# <snip> several additional fields like the above

	@fields = quotewords(",",0,$entry);
	print CODES "$fields[0]", '|';
	print CODES "$fields[1]", '|';
	$fields[2] =~ s/-//;
	print CODES "$fields[2]", '|';
	if ($fields[4]){$code = $fields[4];decode();}

# decode() is 2800 lines long

	$f5txt = $fields[5];
	$f5txt =~ s/(\w+)/\u\L$1/g;
	print CODES "$f5txt", '|'

# <snip> several additional fields like the above

	#options
	if ($fields[30]){$code = $fields[30];getopt();
	print CODES '|';}else{print CODES '|';}

# <snip> several additional fields like the above

}

sub decode {
	open (CARPART, "./dat_in/carparts.txt") || die $!;
	while (<CARPART>){
		chomp;
		s/\\/XXA/g; # \
		s/\[/XXB/g; # [

# <snip> several additional fields like the above

		@parts = &quotewords(',', 0, $_);
		if ($parts[0] =~ /$code/){
			$parttxt = $parts[2];
			$parttxt =~ s/(\w+)/\u\L$1/g;
			print CODES "$parttxt", '|';
			last;
		}
		else{next;}
	}
	close CARPART;
}

sub getopt {
	open (GETOPT, "./dat_in/options.txt") || die $!;
	while (<GETOPT>){
		chomp;
		s/\\/XXA/g; # \

# <snip> additional fields like the above

		@opt = &quotewords(',', 0, $_);
		if ($opt[0] =~ /$code/){
			$opttxt = $opt[1];
			$opttxt =~ s/(\w+)/\u\L$1/g;
			print CODES "$opttxt";
			last;
		}
		else{next;}
	}
	close GETOPT;
}
close CODES;


--
Get high!! with WEBPOSITION
http://w3z.com ***** ZD Net
FREE Download. Do it now!!!


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

Date: 27 Oct 1999 20:54:39 -0000
From: Jonathan Stowe <gellyfish@gellyfish.com>
Subject: Re: sysread / syswrite ?
Message-Id: <7v7oqf$jqg$1@gellyfish.btinternet.com>

On Wed, 27 Oct 1999 19:58:32 GMT fred wrote:
> 1. What are they?

They are I/O functions that bypass STDIO.

perldoc -f sysread
perldoc -f syswrite

> 2. Are they Un*x-specific?

Not necessarily

> 3. Are there alternatives for them in Perl for Win95?
> 

I'm not sure that they don't work there.

/J\
-- 
Jonathan Stowe <jns@gellyfish.com>
<http://www.gellyfish.com>
Hastings: <URL:http://dmoz.org/Regional/UK/England/East_Sussex/Hastings>


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

Date: 28 Oct 1999 18:18:22 -0500
From: abigail@delanet.com (Abigail)
Subject: Re: System Requirement
Message-Id: <slrn81hmd1.66b.abigail@alexandra.delanet.com>

Willie Lui (ltienheo@starnet.gov.sg) wrote on MMCCXL September MCMXCIII
in <URL:news:380bdae4.0@news.cyberway.com.sg>:
;; Hi,
;;     Does anyone know what is the system requirement for me to install perl
;; to an Unix system?


You need an ANSI C compiler.



Abigail
-- 
$_ = "\x3C\x3C\x45\x4F\x54"; s/<<EOT/<<EOT/e; print;
Just another Perl Hacker
EOT


  -----------== Posted via Newsfeeds.Com, Uncensored Usenet News ==----------
   http://www.newsfeeds.com       The Largest Usenet Servers in the World!
------== Over 73,000 Newsgroups - Including  Dedicated  Binaries Servers ==-----


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

Date: Thu, 28 Oct 1999 23:27:51 +0200
From: "jan smit" <duthler@tebenet.nl>
Subject: THNX!!!!!!!!!!!!!!!
Message-Id: <7vaf4i$8m9$1@porthos.nl.uu.net>

THNX!!!!!!!!!!!!

Larry Rosler <lr@hpl.hp.com> wrote in message
news:MPG.12823a078d58816698a151@nntp.hpl.hp.com...
> In article <7va455$1mt$1@porthos.nl.uu.net> on Thu, 28 Oct 1999 20:20:27
> +0200, jan smit <duthler@tebenet.nl> says...
> > id like to know how to convert a char to a decimal value ..
> > if id have a stringe like so : "hallo" ..
> > and id were to use regular expression to get the chat h .. then how
could i
> > get its decimal value?? .. like @ = 64 if i remember correctly ..
>
> perldoc -f ord
>
> --
> (Just Another Larry) Rosler
> Hewlett-Packard Laboratories
> http://www.hpl.hp.com/personal/Larry_Rosler/
> lr@hpl.hp.com




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

Date: Thu, 28 Oct 1999 15:30:42 -0700
From: "David Christensen" <dchristensen@california.com>
Subject: Re: Why can't I get this uniq/perl thing right?
Message-Id: <3818cafb$1_3@news5.newsfeeds.com>

comp.lang.perl.misc & Shon:

mr_geek <shon@mad.scientist.com> wrote:

> This is a sample line:
> <td>BLM03 | 2594 | Bloom, Lip Balms </td>


>I want this:
>BLM03
>PLY01


Data file (foo.html):

      1 <html><head><title>chud</title></head>
      2
      3 <body>
      4 blah blah blah
      5 <td>this shouldn't come through</td>
      6 <td>BLM03 | 2594 | Bloom, Lip Balms </td>
      7 <td>PLY01 | 1234 | Plywood, Quarter Inch </td>
      8 blah
      9
     10 </body></html>


Script:

      1 #! perl -w
      2 use strict;
      3
      4 my @bases;
      5
      6 while (<>) {
      7     push(@bases, $1) if /<td>\s*(.+?)\s*\|.*<\/td>/;
      8 }
      9
     10 foreach (@bases) {
     11     print $_, "\n";
     12 }


The crux move is the regex on line 7.  Note the '?' for minimalist
matching.


Sample run:

    ~/code/perl/foo$ foo chud.txt
    BLM03
    PLY01


--
David Christensen
dchristensen@california.com





  -----------== Posted via Newsfeeds.Com, Uncensored Usenet News ==----------
   http://www.newsfeeds.com       The Largest Usenet Servers in the World!
------== Over 73,000 Newsgroups - Including  Dedicated  Binaries Servers ==-----


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

Date: Thu, 28 Oct 1999 17:09:26 -0700
From: Larry Rosler <lr@hpl.hp.com>
Subject: Re: Why can't I get this uniq/perl thing right?
Message-Id: <MPG.1282859251cf95cf98a157@nntp.hpl.hp.com>

In article <3818cafb$1_3@news5.newsfeeds.com> on Thu, 28 Oct 1999 
15:30:42 -0700, David Christensen <dchristensen@california.com> says...
> mr_geek <shon@mad.scientist.com> wrote:
> 
> > This is a sample line:
> > <td>BLM03 | 2594 | Bloom, Lip Balms </td>
> 
> >I want this:
> >BLM03
> >PLY01

 ...

>       1 #! perl -w
>       2 use strict;
>       3
>       4 my @bases;
>       5
>       6 while (<>) {
>       7     push(@bases, $1) if /<td>\s*(.+?)\s*\|.*<\/td>/;
>       8 }
>       9
>      10 foreach (@bases) {
>      11     print $_, "\n";
>      12 }

You haven't dealt with the 'uniq' part of the problem.  Your data 
extraction is OK, but it should go into a hash, not an array.

  my %bases;

  /<td>\s*(.+?)\s*\|.*<\/td>/ and $bases{$1} = 1 while <>;

  print map "$_\n" => sort keys %bases;

-- 
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com


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

Date: Thu, 28 Oct 1999 16:36:39 -0400
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: Why can't I get this uniq/perl thing right?
Message-Id: <n4cav7.fdh.ln@magna.metronet.com>

mr_geek (shon@mad.scientist.com) wrote:

: Subject: Why can't I get this uniq/perl thing right?
                                ^^^^
                                ^^^^


   You should always, yes *always* enable warnings.

   If finds one mistake, and one _error_ in your program.


   Any time the problem statement says "unique" (or duplicate,
   or look-up) I expect to see a percent sign somewhere in
   the code. (use a hash).

   I don't see one there.


   And why are you doing it similar to what is shown in the
   Perl FAQ, part 4?


      perldoc -q uniq


      "How can I extract just the unique elements of an array?"


   You are expected to check the Perl FAQ *before* posting
   to the Perl newsgroup.


: I have an html file I read in (which is generated by a command)
:  This is a sample line:
:  <td>BLM03 | 2594 | Bloom, Lip Balms </td>

: open FILE, "command |";

   You should always, yes *always*, check the return value.

   open FILE, "command |" or die "could not fork";

   and see also Perl FAQ, part 8:

      "Why doesn't open() return an error when a pipe open fails?"


: while ($line = <FILE>) {
:   if ($line =~ /\|/) {            #match line with a | in them
:     $line =~ s/<td>//;            #strip off the <td> tags
:     $line =~ s/<\/td>//;          #same as above
:     $line =~ s/^\s+//;            #kill all the white space
:     $line =~ s/$\s+//;            #you get the idea
                 ^^
                 ^^

   Why are you trying to match the value of Perl's $\ special
   variable there? ( -w would have warned you about this).


:     @fields = (split /\|/, $line);
:     $base = @fields[0];           #getting BLM03 from the sample line
              ^

   That isn't doing what you think it is doing.

   -w would have warned you about this too!


:     $base =~ s/\s+//;             #no whitespace required
:     push(@bases,$base);           #putting $base into an array
:   }
:   @bases = sort(@bases);          #this SHOULD sort the array (doesn't)


   We can't try it 'cause we don't have sample data.

   (well we do, but it is _already_ unique because it is a single datum :-)


:   $prev = 'nonesuch';             #these SHOULD cut away duplicate lines
:   @bases = grep($_ ne $prev && ($prev = $_), @bases);
:   while (@bases) {
:     $base1 = pop(@bases);
:     $base1 =~ s/\s+//;
:     print "$base1\n";
:   }
: }
: close STREAM;
        ^^^^^^

   What is _that_ filehandle?

   Is this your real code?

   And with a pipe open, you should especially be checking the
   return value here too (but you know that now because you
   checked the FAQ about pipe opens above).


      close FILE or die "problem closing FILE";


: This is not working for me. I am getting this:
: BLM03
: BLM03
: BLM03
: PLY01
: PLY01
: BLM03
: PLY01


   I don't get that from the sample data you provided, so I can't help.

   Sorry.

   

: What can I do? 


   Do it like the FAQ suggests.


: I know TMTOWTDI. 


   Do you know F-A-Q ?


: If anyone can help me with this I would
: appreciate it. I know this is long and very specific, but I've been
: working on it for 36 hours (not consecutively)


   I'm not surprised that you are wasting a lot of time.

   That's what people who won't check the FAQ get. And they deserve it.

   So check the FAQ, and get on with it.


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


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

Date: Thu, 28 Oct 1999 16:56:23 -0400
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: Why can't I get this uniq/perl thing right?
Message-Id: <n9dav7.eih.ln@magna.metronet.com>

Tad McClellan (tadmc@metronet.com) wrote:
: mr_geek (shon@mad.scientist.com) wrote:

: : Subject: Why can't I get this uniq/perl thing right?
:                                 ^^^^
:                                 ^^^^


:    And why are you doing it similar to what is shown in the
             ^^^

   Uhhh, that, of course, was supposed to be "aren't".



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


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

Date: Thu, 28 Oct 1999 22:36:13 GMT
From: dragnovich@my-deja.com
Subject: Win NT / Ms SQL & Perl
Message-Id: <7vaj4t$jaf$1@nnrp1.deja.com>

Hello! I have been programming in perl since 1 year ago... now I have a
new proyect that have to use a new monster for me, it is called
DATABASE! =-) well I have a WinNT server, Active state perl for nt, and
Microsoft (=-P) SQL server...

Well HOW CAN I USE THAT! with perl ?? do you have some URLS where I can
find how to create a simple database with 4 rows lets say
login,name,email,comments and information of how to make a search, add
and modify the database???

If there are some examples it wil be GREAT!! =-)

Thanks!
------------------------
Juan Carlos Lopez
QDesigns President & CEO
http://www.qdesigns.com


Sent via Deja.com http://www.deja.com/
Before you buy.


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

Date: Thu, 28 Oct 1999 17:29:59 -0700
From: David Cassell <cassell@mail.cor.epa.gov>
Subject: Re: Win NT / Ms SQL & Perl
Message-Id: <3818EA87.F5C74D3C@mail.cor.epa.gov>

dragnovich@my-deja.com wrote:
> 
> Hello! I have been programming in perl since 1 year ago... now I have a
> new proyect that have to use a new monster for me, it is called
> DATABASE! =-) well I have a WinNT server, Active state perl for nt, and
> Microsoft (=-P) SQL server...
> 
> Well HOW CAN I USE THAT! with perl ?? do you have some URLS where I can
> find how to create a simple database with 4 rows lets say
> login,name,email,comments and information of how to make a search, add
> and modify the database???
> 
> If there are some examples it wil be GREAT!! =-)

Use the DBI module with the DBD::ODBC driver to get at MS SQL
Server.  I'm so glad you didn't say 'MS Access' instead!

Go to www.perl.com and use the Search facility.  Use a 
keyword like 'tutorial' or 'database' and you'll find
lots of Perl database tutorials to get you started.  Also,
the docs for DBI have swell examples too.

David
-- 
David Cassell, OAO                     cassell@mail.cor.epa.gov
Senior computing specialist
mathematical statistician


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

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


Administrivia:

The Perl-Users Digest is a retransmission of the USENET newsgroup
comp.lang.perl.misc.  For subscription or unsubscription requests, send
the single line:

	subscribe perl-users
or:
	unsubscribe perl-users

to almanac@ruby.oce.orst.edu.  

| NOTE: The mail to news gateway, and thus the ability to submit articles
| through this service to the newsgroup, has been removed. I do not have
| time to individually vet each article to make sure that someone isn't
| abusing the service, and I no longer have any desire to waste my time
| dealing with the campus admins when some fool complains to them about an
| article that has come through the gateway instead of complaining
| to the source.

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 V9 Issue 1217
**************************************


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