[9202] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 2820 Volume: 8

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Jun 5 18:07:33 1998

Date: Fri, 5 Jun 98 15:00:29 -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, 5 Jun 1998     Volume: 8 Number: 2820

Today's topics:
        Clearing arrays and hashes (David Thornley)
        CODE: Win32 Registry search & replace (Andy Lester)
    Re: comp.lang.perl.(n|q) another option? (Michael J Gebis)
    Re: comp.lang.perl.(n|q) another option? (Andy Lester)
    Re: decimal arithmetic <tchrist@mox.perl.com>
    Re: decimal arithmetic (Ken Fox)
    Re: decimal arithmetic (Tom Rokicki)
        Directing functions from the command prompt dimitoglou@acm.org
    Re: Directing functions from the command prompt <jdporter@min.net>
    Re: Directing functions from the command prompt (Mark Maurer)
    Re: Foreach Efficiency <p-fein@uchicago.edu>
    Re: Foreach Efficiency (Mark-Jason Dominus)
    Re: How do I prevent a socket from closing? (Mark-Jason Dominus)
    Re: How do I test MacPerl CGI scrips using my local Bro (Kevin Reid)
        How to access MS SQLSever on NT using Perl ??? <lsnelle@max.state.ia.us>
    Re: Negative values from Win32::GetTickCount? (Tye McQueen)
    Re: Not even an RFD (yet)... comp.lang.perl.(newbie|que birgitt@my-dejanews.com
    Re: perl equivalent to C's local static var? <tchrist@mox.perl.com>
    Re: perl equivalent to C's local static var? <jdporter@min.net>
        perlTk Perl Debugger (Andrew E Page)
    Re: regexp: Validating UPC Code (Sitaram Chamarty)
    Re: regexp: Validating UPC Code (Ilya Zakharevich)
        Removing a character from a string <mhabib@microsoft.com>
    Re: Removing a character from a string (Ed Weinberg)
        script for DBF file? <gregq@saol.com>
        Digest Administrivia (Last modified: 8 Mar 97) (Perl-Users-Digest Admin)

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

Date: Fri, 05 Jun 1998 21:20:48 GMT
From: thornley@visi.com (David Thornley)
Subject: Clearing arrays and hashes
Message-Id: <QiZd1.1099$On1.4306643@ptah.visi.com>

I have a problem with a Perl program I'm writing.  I have looked at the
FAQ, the provided documentation, the camel book, the black leopard
book, and some of the other documentation on the web.  I still don't
know how to do what I want to do.

I'm reading a file, which contains attribute name/value pairs.  Some of
the attribute names are built in as small integers, some are free-form
strings.  Whenever I get an attribute with name 0, I'm on a new object.
(It's a bit more complicated that this, but the details don't matter
- if you're curious, it's Autocad's DXF format.)

What I want is a collection of arrays, each having one entry per
object.  One array will include object names; that's easy.  One
array will contain references to arrays of the built-in attributes,
one will contain references to hashes of the free-form attributes,
and one will contain references to arrays of the names of the free-
form attributes.  (This is specifically to keep track of the order
these attributes are in in the file.)

My approach has been to incrementally build up two arrays and a hash,
as previously specified, and push references to these, or copies of
these, onto the appropriate arrays.  This is similar to many of the
examples in perldsc and the like, but there are two important
differences.

First, I'm building these up incrementally, and am not just assigning
them in one swell foop.  Second, I'm not creating new structures
every time through a loop, but rather I want to do so in a data-driven
approach.

The approach I thought of is to clear out the values in the arrays
and hash whenever I encounter a new object, but that doesn't seem
to be working for the hash in particular.  I can't use "my", as far
as I see, since I'd have to use it in a block referred to in an "if"
statement, limiting the scope of those variables to that block.
I tried using "undef", but I got complaints about undefined arrays
(besides, I'm using "use strict" as well as "-w", and "use strict"
requires every variable to be specified in a "my" statement or
some other package-designating thing).

This is a copy of the latest version of Code That Doesn't Work:

while (defined($line1 = <INFILE>) && defined($line2 = <INFILE>)) {
  chomp($line1); chomp($line2);
  if ($line1 == 0) {
    if ($entity != 0) {
      push(@charac, [@characteristics]);
      push(@attribute, {%attvalues});
      push(@attname, [@attnamelist]);
      if ($entity == 5) {
        print "$line2:\n@characteristics\n@attnamelist\n";
      }
    }
    @characteristics = ();
    %attvalues = ();
    @attnamelist = ();
    push(@name, $line2);
    $entity++;
    if ($entity == 5) {
      print "$line2:\n@characteristics\n@attnamelist\n";
    }
  } elsif ($line1 < 100) {
    $characteristics[$line1] = $line2;
    if ($entity < 10) {
      print"$line1 $line2\n";
    }
  } else {
    $line3 = <INFILE> || die "Ill-formed file, play the pipes lowly\n";
    $line4 = <INFILE> || die "Ill-formed file, bang the drum slowly\n";
    chomp($line3); chomp($line4);
    $attvalues{$line2} = $line4;
    push(@attnamelist, $line1);
    if ($entity < 10) {
      print"$line1 $line2 $line3 $line4\n";
    }
  }
}

Thanks.

David H. Thornley                        | These opinions are mine.  I
david@thornley.net                       | do give them freely to those
http://www.thornley.net/~thornley/david/ | who run too slowly.       O-

--
David H. Thornley                        | These opinions are mine.  I
david@thornley.net                       | do give them freely to those
http://www.thornley.net/~thornley/david/ | who run too slowly.       O-


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

Date: 5 Jun 1998 21:23:50 GMT
From: petdance@maxx.mc.net (Andy Lester)
Subject: CODE: Win32 Registry search & replace
Message-Id: <6l9nl6$a1j$1@supernews.com>

The following is pretty specific to my problem, but I figure some novice
might see it and learn SOMETHING.  It's gotta beat the Nth "How do I set
up Perl on IIS" question.

Please note that the following makes menion of Microsoft products.
Repeatedly.  If you can't handle that, please leave now.

Here at work we've had the MS Office apps sitting on a network drive, and
we've used 'em across the network.  Performance sucked.  Now I want it
local.  Bummer: Installing it local doesn't change all the paths in the
registry; they still point at the K: drive.  

How to do a search & replace on the old paths to the new ones?  I could
export the entire registry, search & replace w/a tool, and reimport it,
but that's yucky.

So I wrote a little Perl program, natch.  Used _Learning Perl On Win32
Systems_ by Schwartz, Olson & Christiansen as the jumping point.  It
recursively walks the registry tree looking for naughty paths, and updates
'em when it finds one.  The code follows:

#!perl -Tw

use strict;
use Win32::Registry;

my $search = "K:\\MSOFFICE\\OFFICE\\";
my $replace = "C:\\Program Files\\Microsoft Office\\Office\\";

&ProcessKey( "SOFTWARE\\Microsoft\\Office\\8.0" );

sub ProcessKey($) {
	my $keystr = shift;

	my $curr;
	$main::HKEY_LOCAL_MACHINE->Open( $keystr, $curr ) ||
		die "Opening [$keystr]: $!";

	my %vals;
	$curr->GetValues( \%vals );
	for my $i ( keys %vals ) {
		my $key = $vals{ $i };
		next unless $$key[1] eq REG_SZ;

		my $valname = $$key[0];
		my $valdata = $$key[2];
		next unless $valdata =~ s/^\Q$search\E/$replace/io;
		$curr->SetValue( $valname, REG_SZ, $valdata );
		print "$keystr\n";
		print "  $valname -> $valdata\n";
		}

	my @keys;
	$curr->GetKeys( \@keys );
	for my $i ( @keys ) {
		ProcessKey( "$keystr\\$i" );
		}
	}

Now wasn't that more fun than arguing over the GPL?

xoxo,
Andy

--
--
Andy Lester:        <andy@petdance.com>       http://tezcat.com/~andy/
Chicago Shows List: <shows@ChicagoMusic.com>  http://ChicagoMusic.com/



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

Date: 5 Jun 1998 19:55:30 GMT
From: gebis@albrecht.ecn.purdue.edu (Michael J Gebis)
Subject: Re: comp.lang.perl.(n|q) another option?
Message-Id: <6l9ifi$fcv@mozo.cc.purdue.edu>

due@murray.fordham.edu (Allan M. Due) writes:

}Although loath to admit it, I come from that 
}often despised Windoze background, as do many offenders, so I might be 
}able to provide some instruction in a framework they are familiar with.
}	Let me know if there is any interest, or if you think the idea is 
}without merit tell me know and I will stop thinking about it.

I've never seen it suggested yet, but my brain just thunk "What about
comp.lang.perl.win32?"  I've had reservations about posting this, as
my brain has been known to leap before it looked, but my brain keeps
insisting that I at least pass the though along.

This is, of course, contrary to the platform-independant, free-love
attitude that perl is about, but then again, it seems that whole era seems
to be dead anyway.

-- 
Mike Gebis  gebis@ecn.purdue.edu  mgebis@eternal.net


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

Date: 5 Jun 1998 21:35:16 GMT
From: petdance@maxx.mc.net (Andy Lester)
Subject: Re: comp.lang.perl.(n|q) another option?
Message-Id: <6l9oak$a1j$2@supernews.com>

: 	As a newcomer to Perl and one who has valued my experiences on 
: c.l.p.m I have been trying to think of ways I can give something back to 
: the Perl community.  One idea I have played with is creating a web site 
: dedicated to the Perl Newbie that would be a clearing house of all of the 
: excellent FAQs and guides to appropriate newsgroup behavior that newbies 
: are frequently directed to in this newsgroup.  As an alternative to 

Why do you think they'd read your site any more than they (don't) read the
existing resources?  Could you possibly have a better site than
www.perl.com? 

The answer does not lie with creating Yet More Resources.  The resources
that exist now don't get used as it is.

xoxo,
Andy



--
--
Andy Lester:        <andy@petdance.com>       http://tezcat.com/~andy/
Chicago Shows List: <shows@ChicagoMusic.com>  http://ChicagoMusic.com/



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

Date: 5 Jun 1998 19:48:58 GMT
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: Re: decimal arithmetic
Message-Id: <6l9i3a$ke7$3@csnews.cs.colorado.edu>

 [courtesy cc of this posting sent to cited author via email]

In comp.lang.perl.misc, 
    dgwilson@gte.net (Douglas Wilson) writes:
:Not on my system. Is it supposed to come with 5.003?

No, it comes with perl 5.004.

:I did try:
:http://cpan.perl.org/doc/FAQs/FAQ/html/perlfaq4.html

Those are wrong. Old.  Stupid.  And before you bitch at me
about fixing them, read this:


--tom

Being continually ragged on for not updating the CPAN html doc versions of
our documentation, I am faced once again with the onerous and odious task
of producing an HTML tree (and also postscript documents from pod2man)
of the more than two hundred random pods scattered about the nethermost
reaches of the current 5.004 perl src tree.

I'm not going to start down this path until we have devised a long-term
solution.  I'm looking for concrete, useful suggestions and serious help.

Furthermore, I hereby propose in all seriousness that no further release
of Perl be made until such time as this insane situation should be
soundly and suitably fixed.

What insane situation?  Read on...

Here's what must be done:

    0) No file containing pod information may be omitted from the
       final tree.  *All* pods in the source directory must be reachable
       from the top level with useful index pages, and they must link
       to each other correctly.  This is the overriding criterion.

    1) The standard pods in pod/*.pod must be converted, and some
       of these broken up into pieces at either the =item granularity
       or the =head granularity.  For example, perlfunc must be
       broken up.  But only the bottom part of it, not the top.
       And perlfunc/index.html is a problem.  (See podset#1 below)
       But the broken up pages should also have non broken up versions.

    2) The ext and lib pods need to be covered, and they all need proper
       per-directory useful index pages as well.  This would likely be
       just one directory. (See podset#2).

    3) The utilities pods must be converted.  These are podset#3.

    4) The alien ports pods must be converted.  These are podset#4.

    5) The joe-random scattered-all-over-creation pods must be converted.
       These are podset#5.

    6) Some contingency for site_perl must be provided for.

    7) Whatever I didn't think of yet.

This is an increasingly difficult task.  We must develop some rhyme,
reason, and sanity here.  pod2html works just on a single page basis,
and even installhtml, originally designed for this purpose, cannot begin
to deal with the madness we have wrought.

HELP!

--tom


PODSET #1:

    pod/perl.pod pod/perlapio.pod pod/perlbook.pod pod/perlbot.pod
    pod/perlcall.pod pod/perldata.pod pod/perldebug.pod pod/perldelta.pod
    pod/perldiag.pod pod/perldsc.pod pod/perlembed.pod pod/perlfaq.pod
    pod/perlfaq1.pod pod/perlfaq2.pod pod/perlfaq3.pod pod/perlfaq4.pod
    pod/perlfaq5.pod pod/perlfaq6.pod pod/perlfaq7.pod pod/perlfaq8.pod
    pod/perlfaq9.pod pod/perlform.pod pod/perlfunc.pod pod/perlguts.pod
    pod/perlipc.pod pod/perllocale.pod pod/perllol.pod pod/perlmod.pod
    pod/perlmodlib.pod pod/perlobj.pod pod/perlop.pod pod/perlpod.pod
    pod/perlre.pod pod/perlref.pod pod/perlrun.pod pod/perlsec.pod
    pod/perlstyle.pod pod/perlsub.pod pod/perlsyn.pod pod/perltie.pod
    pod/perltoc.pod pod/perltoot.pod pod/perltrap.pod pod/perlvar.pod
    pod/perlxs.pod pod/perlxstut.pod pod/pod2html pod/pod2html.PL
    pod/pod2man pod/pod2man.PL pod/splitpod

PODSET #2:

    ext/DB_File/DB_File.pm ext/DynaLoader/DynaLoader.pm ext/Fcntl/Fcntl.pm
    ext/GDBM_File/GDBM_File.pm ext/IO/IO.pm ext/IO/lib/IO/File.pm
    ext/IO/lib/IO/Handle.pm ext/IO/lib/IO/Pipe.pm ext/IO/lib/IO/Seekable.pm
    ext/IO/lib/IO/Select.pm ext/IO/lib/IO/Socket.pm ext/NDBM_File/NDBM_File.pm
    ext/ODBM_File/ODBM_File.pm ext/Opcode/Opcode.pm ext/Opcode/Safe.pm
    ext/Opcode/ops.pm ext/POSIX/POSIX.pod ext/SDBM_File/SDBM_File.pm
    ext/Socket/Socket.pm lib/AnyDBM_File.pm lib/AutoLoader.pm lib/AutoSplit.pm
    lib/Benchmark.pm lib/Bundle/CPAN.pm lib/CGI/Apache.pm lib/CGI/Carp.pm
    lib/CGI/Fast.pm lib/CGI/Push.pm lib/CGI/Switch.pm lib/CGI.pm
    lib/CPAN/FirstTime.pm lib/CPAN/Nox.pm lib/CPAN.pm lib/Carp.pm
    lib/Class/Struct.pm lib/Config.pm lib/Cwd.pm lib/DB_File.pm
    lib/Devel/SelfStubber.pm lib/DirHandle.pm lib/DynaLoader.pm
    lib/English.pm lib/Env.pm lib/Exporter.pm lib/ExtUtils/Command.pm
    lib/ExtUtils/Embed.pm lib/ExtUtils/Install.pm lib/ExtUtils/Liblist.pm
    lib/ExtUtils/MM_OS2.pm lib/ExtUtils/MM_Unix.pm lib/ExtUtils/MM_VMS.pm
    lib/ExtUtils/MM_Win32.pm lib/ExtUtils/MakeMaker.pm
    lib/ExtUtils/Manifest.pm lib/ExtUtils/Mkbootstrap.pm
    lib/ExtUtils/Mksymlists.pm lib/ExtUtils/testlib.pm lib/ExtUtils/xsubpp
    lib/Fcntl.pm lib/File/Basename.pm lib/File/CheckTree.pm
    lib/File/Compare.pm lib/File/Copy.pm lib/File/DosGlob.pm
    lib/File/Find.pm lib/File/Path.pm lib/File/stat.pm lib/FileCache.pm
    lib/FileHandle.pm lib/FindBin.pm lib/GDBM_File.pm lib/Getopt/Long.pm
    lib/Getopt/Std.pm lib/I18N/Collate.pm lib/IO/File.pm lib/IO/Handle.pm
    lib/IO/Pipe.pm lib/IO/Seekable.pm lib/IO/Select.pm lib/IO/Socket.pm
    lib/IO.pm lib/IPC/Open2.pm lib/IPC/Open3.pm lib/Math/BigFloat.pm
    lib/Math/BigInt.pm lib/Math/Complex.pm lib/Math/Trig.pm lib/NDBM_File.pm
    lib/Net/Ping.pm lib/Net/hostent.pm lib/Net/netent.pm lib/Net/protoent.pm
    lib/Net/servent.pm lib/Opcode.pm lib/POSIX.pod lib/Pod/Html.pm
    lib/Pod/Text.pm lib/SDBM_File.pm lib/Safe.pm lib/Search/Dict.pm
    lib/SelectSaver.pm lib/SelfLoader.pm lib/Shell.pm lib/Socket.pm
    lib/Symbol.pm lib/Sys/Hostname.pm lib/Sys/Syslog.pm lib/Term/Cap.pm
    lib/Term/Complete.pm lib/Term/ReadLine.pm lib/Test/Harness.pm
    lib/Text/Abbrev.pm lib/Text/ParseWords.pm lib/Text/Soundex.pm
    lib/Text/Tabs.pm lib/Text/Wrap.pm lib/Tie/Hash.pm lib/Tie/RefHash.pm
    lib/Tie/Scalar.pm lib/Tie/SubstrHash.pm lib/Time/Local.pm
    lib/Time/gmtime.pm lib/Time/localtime.pm lib/Time/tm.pm lib/UNIVERSAL.pm
    lib/User/grent.pm lib/User/pwent.pm lib/autouse.pm lib/base.pm lib/blib.pm
    lib/constant.pm lib/diagnostics.pm lib/integer.pm lib/less.pm lib/lib.pm
    lib/locale.pm lib/ops.pm lib/overload.pm lib/sigtrap.pm lib/strict.pm
    lib/subs.pm lib/vars.pm

PODSET #3:
    utils/c2ph.PL utils/h2ph.PL utils/h2xs.PL utils/perlbug.PL
    utils/perldoc.PL utils/pl2pm.PL

PODSET #4:
    os2/OS2/ExtAttr/ExtAttr.pm os2/OS2/PrfDB/PrfDB.pm
    os2/OS2/Process/Process.pm os2/OS2/REXX/REXX.pm plan9/perlplan9.pod
    vms/ext/DCLsym/DCLsym.pm vms/ext/Filespec.pm vms/ext/Stdio/Stdio.pm
    vms/ext/XSSymSet.pm vms/ext/vmsish.pm vms/perlvms.pod win32/bin/pl2bat.pl
    win32/bin/runperl.pl x2p/a2p.pod x2p/s2p.PL

PODSET #5:
    INSTALL Porting/pumpkin.pod README.amiga README.os2 README.win32 configpm
    emacs/cperl-mode.el installhtml makeaperl makeaperl.SH minimod.pl
    t/op/runlevel.t
-- 
MAGIC*  xmg_magic;  /* linked list of magicalness */
    --Larry Wall, from sv.h in the v5.0 perl distribution


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

Date: 5 Jun 1998 21:00:27 GMT
From: kfox@pt0204.pto.ford.com (Ken Fox)
Subject: Re: decimal arithmetic
Message-Id: <6l9m9b$2806@eccws1.dearborn.ford.com>

Tom Christiansen <tchrist@mox.perl.com> writes:
> I sometimes think we should add a warning for == on non-integers
> that says something like "Please attend a numerical analysis course."

Yes!  That makes a lot of sense.  The other thing that could be done
is to default '==' to (abs(a-b) < error).  That would be really nice.
Of course this means there would be another magical Perl variable to
worry about...

- Ken

-- 
Ken Fox (kfox@ford.com)                  | My opinions or statements do
                                         | not represent those of, nor are
Ford Motor Company, Powertrain           | endorsed by, Ford Motor Company.
Analytical Powertrain Methods Department |
Software Development Section             | "Is this some sort of trick
                                         |  question or what?" -- Calvin


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

Date: 5 Jun 1998 14:25:16 -0700
From: rokicki@cello.hpl.hp.com (Tom Rokicki)
Subject: Re: decimal arithmetic
Message-Id: <6l9nns$hna@cello.hpl.hp.com>

> Tom Christiansen <tchrist@mox.perl.com> writes:
> > I sometimes think we should add a warning for == on non-integers
> > that says something like "Please attend a numerical analysis course."

> Yes!  That makes a lot of sense.  The other thing that could be done
> is to default '==' to (abs(a-b) < error).  That would be really nice.

For those of us running on 32-bit machines with IEEE math, we often
use doubles as higher-precision ints (some 53 bits or so).  So long
as you restrict the operations you perform, this works great.  And
for these, == and ++ and etc. are all well-defined.

So I presume Tom C. was joking . . .

-tom


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

Date: Fri, 05 Jun 1998 20:00:05 GMT
From: dimitoglou@acm.org
Subject: Directing functions from the command prompt
Message-Id: <6l9io5$m05$1@nnrp1.dejanews.com>

Dear Perl-ers,

I have a question (may be trivial for experts).

I have a routine that has three functions. two ofthem are performance
intensive and I would like the option to run them from a command switch.

Something like:
	% ./parse.pl -E  # for the exhastive method
	% ./parse.pl -Q  # for the quick way

etc

Is there a construct that can help me do this?

I will summarize.

Thanks
George
NASS GSFC, Greenbelt, MD

-----== Posted via Deja News, The Leader in Internet Discussion ==-----
http://www.dejanews.com/   Now offering spam-free web-based newsreading


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

Date: Fri, 05 Jun 1998 20:15:59 GMT
From: John Porter <jdporter@min.net>
Subject: Re: Directing functions from the command prompt
Message-Id: <3578539D.7938@min.net>

dimitoglou@acm.org wrote:
> 
> ... a command switch.
> Something like:
>         % ./parse.pl -E  # for the exhastive method
>         % ./parse.pl -Q  # for the quick way
> Is there a construct that can help me do this?
> I will summarize.

I'll do it for you:  Getopt::Long and Getopt::Std.

John Porter


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

Date: 5 Jun 1998 17:15:48 -0400
From: mwmaurer@mtu.edu (Mark Maurer)
Subject: Re: Directing functions from the command prompt
Message-Id: <6l9n64$rfv$1@pace1.cts.mtu.edu>

John Porter (jdporter@min.net) wrote:
: dimitoglou@acm.org wrote:
: > 
: > ... a command switch.
: > Something like:
: >         % ./parse.pl -E  # for the exhastive method
: >         % ./parse.pl -Q  # for the quick way
: > Is there a construct that can help me do this?
: > I will summarize.
: 
: I'll do it for you:  Getopt::Long and Getopt::Std.

And if it is something as simple as above, just read the values from @ARGV...
-- 
Mark Maurer  markm@dct.com                      mwmaurer@mtu.edu
Programmer,  Digital Magic Interactive          http://www.dminteractive.com
Senior,      Michigan Technological University  Houghton, MI
-- Views do not represent those of my employer or school


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

Date: Fri, 5 Jun 1998 20:19:55 GMT
From: Peter A Fein <p-fein@uchicago.edu>
Subject: Re: Foreach Efficiency
Message-Id: <877m2vsis4.fsf@bj2-64.rh.uchicago.edu>

John Porter <jdporter@min.net> writes:

> Peter A Fein wrote:
> > 
> > John Porter <jdporter@min.net> writes:
> > > In that case, why are you bothering with usenet at all?
> > 
> > Posting takes a few seconds tops.  
> 
> Nothing against you personally, Peter; but it's this attitude
> which has made clpm the cat-poop-filled place it is.

I may take a few seconds to post, but it's because I take several
minutes to think & read beforehand.  I agree that a large portion of
the messages are junk - that's why I try to make my posts well
researched and thought out.  I apologize if this particular one didn't
meet your standards.

-- 
Peter Fein                                                         773-834-6206
1005 E. 60th St.                                              Chicago, IL 60637
p-fein@uchicago.edu                                   http://pfein.home.ml.org/


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

Date: 5 Jun 1998 17:26:35 -0400
From: mjd@op.net (Mark-Jason Dominus)
Subject: Re: Foreach Efficiency
Message-Id: <6l9nqb$sbv$1@monet.op.net>
Keywords: delete melodious shoulder Skopje

In article <MPG.fe0c700c77ad7e59896a1@hplntx.hpl.hp.com>,
Larry Rosler <lr@hpl.hp.com> wrote:
>What would make you think the sort (the generation of the list value 
>that the foreach loop iterates over) would be done more than once?

I'm not sure what would make someone think of that, but that exact
thought occurs to me quite often.  I dismiss it, of cuorse, but it's
easy for me to imagine someone with a little less experience who
didn't dismiss it.

We've all heard horror stories about C programs with

	for ($i=0; $i < strlen(s); $i++) {
	  # do something with s[i]
	}

and I think that's where this worry comes from.

Not a bad thing to worry about.  Certainly more sensible than a lot of
the bizarro worries that people in this group sometimes have.


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

Date: 5 Jun 1998 16:59:39 -0400
From: mjd@op.net (Mark-Jason Dominus)
Subject: Re: How do I prevent a socket from closing?
Message-Id: <6l9m7r$s21$1@monet.op.net>
Keywords: bootlegging brad Rooseveltian stumble


In article <3577AFA3.8E68C6D7@rogers.wave.ca>,
Shaun Jackman  <sjackman@rogers.wave.ca> wrote:
>read as much information that comes in
>display it to the screen
>get one line of input from the user
>send that to the socket
>loop back to the start

You need to think about this a little more.  Talking on a socket is
just like talking on the telephone.  Suppose I told you to do this:

	1. Listen to everything that the person on the other end has to say.
	2. Write it down.
	3. Make a reply.
	4. Start over.

Well, there's something wrong there: The only way to be sure that the
person on the other end has finished talking is to wait for them to
hang up.  If they haven't hung up yet, they might start talking again;
you don't know.  But if you wait until they hang up, then step 4
doesn't make any sense.

>the best I could come up with was
>read one line from the socket
>display one line
>get one line of input from the user
>send that to the socket
>loop back to the start

That makes more sense.

>Get all the data from the remote-host, not just one line, 

This probably isn't what you want.  But you can get all the
information from the socket by doing this:

	@lines = <S>;

But that is like waiting for the person on the other end to hang up
the phone.  It really does get *all* the information, and the only way
it can be sure to do that is to write everything down until the
connection is closed.

>and How to stop the socket from closing on an empty line, 

You don't want to say `closing' here.  If the socket is `closed' it's
like the phone was hung up; you can't talk on it any more.

When you do

	$line = <S>;

it waits for a complete line to come in, and then puts it into
$line. This waiting is called `blocking', not `closing'.  The socket
is still open; you're just waiting for data to come in.

Usually the way to do what you want is to use the `select' function.
`select' will tell you whether or not there is data in the socket that can
be read immediately.  If not, then you don't read the socket; you do
something else instead.  If there is data, you read it with the `read'
function.

If the line is long, it might not all have arrived over the network by
the time you do the `read'.  So you need to be prepared to save the
partial line until you receive the rest of it.  That is why you use
`read' instead of `<S>': read will just give you back whetever there
is, even if there is only one character there; <S> will wait until an
entire line has arrived and then giove you the line all at once.

The code would look something like this:

    # WARNING 1: I didn't test this
    while (1) {
	# Try to read from the network.
	if (select(...)) { # data is ready to be read
	  read(S, $part_line, 4096);
	  $line .= $part_line;
	  if ($line =~ /\n/) { # Complete line
	    @lines = ($line =~ /(.*\n?)/g);
            unless ($lines[-1] =~ /\n/) { 
	      # last line is still incomplete; save it for later
	      $line = pop @lines;
	    }
	    foreach $l (@lines) {
	      process($l);
	    }
	  }
	}

	# talk to the user now
    }	
    # WARNING 2: I only got three hours of sleep last night

`select' is tricky; be sure to see the manual for an example of how to
use it.  There are two totally unrelated `select' functions; you want
the one that gets four arguments, not one argument.

A better approach to this is to build a function which gets a line
from the network, which returns undef if a complete line isn't ready
yet, and which transparently handles the details of assembling partial
lines.  Then you could just use

	while (1) {
	  $line = get_line(S);
	  process($line) if defined $line;
	  # talk to the user now
	}

But the insides of the `get_line' function would look the way I showed
up above.

>Please respond by e-mail as well if possible,

Sorry, not possible.  Private consulting you pay for.



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

Date: Fri, 5 Jun 1998 16:16:11 -0400
From: kpreid@ibm.net (Kevin Reid)
Subject: Re: How do I test MacPerl CGI scrips using my local Browser.
Message-Id: <1da55t3.z4q8541nvv01sN@slip166-72-108-250.ny.us.ibm.net>

<david.clark@snet.net> wrote:

> I have just started learning Perl and I have found the MacPerl to be a
> great tool.  Im very much interested in CGI scripts but I want to test
> them Using my Netscape or Explorer browsers to see them work.  How do I
> set them up to do this?  When I try to call a script localy from HTML
> doc with a post or other type of connection, I get a "Document has no
> DATA" warning. I hope Im not just missing somthing very obvious

In order to use CGI scripts, you need a web server. I use Apple's
Personal Web Sharing for this purpose.

If your Internet connection is over PPP, then you may want to create a
special "local" configuration to avoid having it connect whenever you
start the web server. If you want details, I will post instructions for
how to do this.

-- 
  Kevin Reid.      |         Macintosh.
   "I'm me."       |      Think different.


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

Date: 5 Jun 1998 21:01:26 GMT
From: "Lowelll Sneller" <lsnelle@max.state.ia.us>
Subject: How to access MS SQLSever on NT using Perl ???
Message-Id: <01bd90c7$32495400$6ca5cea5@ITS.dgs.state.ia.us>

Can anyone point me to a source that discusses
using MS SQLServer on NT using Perl? 
my email is lowell.sneller@its.state.ia.us

Thanks


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

Date: 5 Jun 1998 15:50:56 -0500
From: tye@fohnix.metronet.com (Tye McQueen)
Subject: Re: Negative values from Win32::GetTickCount?
Message-Id: <6l9lng$gm3@fohnix.metronet.com>

"Chris Brown" <cbrown_<NoSpam>@erols.com> writes:
) When using Win32::GetTickCount on a NT machine that has been up for 32 days
) I receive a negative value.  This negative value is basically trash when
) determining how long a machine has been running.

To quote some random documentation:

    The elapsed time is stored as a DWORD value. Therefore, the
    time will wrap around to zero if Windows is run continuously
    for 49.7 days. 

) This module works fine for machines running 15 days (haven't nailed down the
) exact point the tick count switches to negative).

So the point where it goes negative is right about 24.85 days [49.7/2
or (2**31)/1000/60/60/24].  You can get to the full 49.7 days via:

    $tick= unpack("L",pack("l",Win32::GetTickCount()));

To get past 49.7 days, you need to use (to further quote random
documentation):

    Windows NT: To obtain the time elapsed since the computer was
    started, look up the System Up Time counter in the performance
    data in the registry key HKEY_PERFORMANCE_DATA. The value
    returned is an 8 byte value. 

The negative thing is because Perl `IV' values can't hold all
`DWORD' values so the more costly `NV' should be used to represent
`DWORD' values.  I guess I should make this change in my modules.

Perhaps sv_setiv() and related macros should deal with this more
intelligently?  Or do we need something like sv_setuiv()?

#define sv_setuiv(sv,val)	\
    (IV)val < 0 ? sv_setnv(sv,(double)val) : sv_setiv(sv,(IV)val)
-- 
Tye McQueen    Nothing is obvious unless you are overlooking something
         http://www.metronet.com/~tye/ (scripts, links, nothing fancy)


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

Date: Fri, 05 Jun 1998 20:22:08 GMT
From: birgitt@my-dejanews.com
Subject: Re: Not even an RFD (yet)... comp.lang.perl.(newbie|questions)
Message-Id: <6l9k1g$no5$1@nnrp1.dejanews.com>

In article <86soljsrlr.fsf@scooter.cis.ohio-state.edu>,
  Matt Curtin <cmcurtin@interhack.net> wrote:
>
> Hi all,
>
> I'm getting concerned about the quality of clpm, and also the sorts of
> answers that potentially new Perl programmers are getting.  I think
> that the real problem is that with all that's going on in clpm, there
> just isn't time to give the sort of attention to new people that new
> people need.  If we could move some of the less technical,
> hand-holding, newbie-oriented sort of traffic to a new group, I think
> we might be able to solve two problems:

[snip]

If you search a little bit in c.l.p.m about this subject during the
last eight to twelve weeks, you will find that this subject has been
discussed endlessly. Why don't you read this first ? Plenty of
thoughts and comments out there already...

Birgitt Funk


-----== Posted via Deja News, The Leader in Internet Discussion ==-----
http://www.dejanews.com/   Now offering spam-free web-based newsreading


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

Date: 5 Jun 1998 20:40:49 GMT
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: Re: perl equivalent to C's local static var?
Message-Id: <6l9l4h$q2r$1@csnews.cs.colorado.edu>

 [courtesy cc of this posting sent to cited author via email]

In comp.lang.perl.misc, 
    jdporter@min.net writes:
:Therefore it is prudent to amend it to read as follows:
:{
:  my $a; 
:  BEGIN { $a=0 }
:  sub f { ++$a }
:}

Interesting.  Usually one sees that as:

    BEGIN {
	my $a = 0;
	sub f { ++$a }
    }

For some reason I like what you wrote, but I can't pin down why.

--tom
-- 
Ask Ken.  He hates Everything.


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

Date: Fri, 05 Jun 1998 21:13:24 GMT
From: John Porter <jdporter@min.net>
Subject: Re: perl equivalent to C's local static var?
Message-Id: <35786112.71C7@min.net>

Tom Christiansen wrote:
> jdporter@min.net writes:
> :{
> :  my $a;
> :  BEGIN { $a=0 }
> :  sub f { ++$a }
> :}
> 
> Interesting.  Usually one sees that as:
> 
>     BEGIN {
>         my $a = 0;
>         sub f { ++$a }
>     }
> 
> For some reason I like what you wrote, but I can't pin down why.

(It was Larry Rosler's idea...)

Well, I like it because it's more comfortable to my C/asm-molded
brain.  I.e. for a very bad reason indeed :-)

Because we know that, in C, static data gets initialized by the
compiler at load time (i.e. by the program loader per instructions
from the compiler).  Whereas functions don't get "initialized";
they're simply there.

Or maybe it's some kind of aversion to polluting the BEGIN space...

John Porter


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

Date: Fri, 5 Jun 1998 19:57:09 GMT
From: aep@world.std.com (Andrew E Page)
Subject: perlTk Perl Debugger
Message-Id: <Eu3Gr9.LHx@world.std.com>


   I'm experimenting with writing a debugger for perl with a GUI
interface built in perlTk.  You can find it at:

http://world.std.com/~aep/ptkdb

<a href ="http://world.std.com/~aep/ptkdb">ptkdb</a>

  If you're interested have a look and give it a try.  It 
requires Tk800.500 but there are links on the page to 
help you find it, if you do not already have it.  



-- 
Andrew E. Page   (Warrior Poet) |   Decision and Effort The Archer and Arrow
Mac Consultant                  |     The difference between what we are
Macintosh and DSP Technology    |           and what we want to be.


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

Date: 5 Jun 98 18:25:04 GMT
From: sitaram@diac.com (Sitaram Chamarty)
Subject: Re: regexp: Validating UPC Code
Message-Id: <slrn6nghoo.q5.sitaram@ltusitaram.diac.com>

On 5 Jun 1998 01:20:10 GMT, Ilya Zakharevich <ilya@math.ohio-state.edu> wrote:

>Since I'm reconsidering my involvement with Perl core hacking, I do
>not know when this is going to improve.

May one ask why?  Inquiring minds want to know.

(OTOH, if this is a topic that has been hashed out already, a
simple dejanews reference or something similar would be fine.  I
dont want to get blamed for re-kindling old "flames" :-)


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

Date: 5 Jun 1998 21:21:05 GMT
From: ilya@math.ohio-state.edu (Ilya Zakharevich)
Subject: Re: regexp: Validating UPC Code
Message-Id: <6l9ng1$fdp$1@mathserv.mps.ohio-state.edu>

[A complimentary Cc of this posting was sent to Sitaram Chamarty
<sitaram@diac.com>],
who wrote in article <slrn6nghoo.q5.sitaram@ltusitaram.diac.com>:
> On 5 Jun 1998 01:20:10 GMT, Ilya Zakharevich <ilya@math.ohio-state.edu> wrote:
> 
> >Since I'm reconsidering my involvement with Perl core hacking, I do
> >not know when this is going to improve.
> 
> May one ask why?  Inquiring minds want to know.

Due to an (unavoidable?) mixture of different causes, the atmosphere
on p5p became untolerable for my nerves (I know, it may be just my
problem ;-).  All the parties involved have best intentions, but all
this sums up to my productivity suffering enormously with each
additional patch I release which is not included into the core.

Yesterday, in preparation to shutting down my involvement, I released
to CPAN a zip with 24 patches of mine which did not make it into
recent releases.  Patches do not fix themselves, each of them requires
an active support when conficts arise.  I do not have any more time.

Heroic work of Tim with 5.004_05-tobe compensated many shortcomings of
the current "development" (actually "win32 + oneperl + threading")
branch, but still 24 is too much (without _05-tobe it could easily be
50 patches to support).

Ilya


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

Date: Fri, 5 Jun 1998 12:24:00 -0700
From: "Martine Habib" <mhabib@microsoft.com>
Subject: Removing a character from a string
Message-Id: <6l9gn9$79e$1@news.artemis.com>

If I have a string $string = "this&that";
I want to remove the ampersand, and end up with $string = "thisthat";

How can I do this in perl ?
Thanks for any help,

Martine




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

Date: Fri, 05 Jun 1998 20:54:52 GMT
From: edw@detel.com (Ed Weinberg)
Subject: Re: Removing a character from a string
Message-Id: <35885a52.208572781@news.javanet.com>

On Fri, 5 Jun 1998 12:24:00 -0700, "Martine Habib"
<mhabib@microsoft.com> wrote:

>If I have a string $string = "this&that";
>I want to remove the ampersand, and end up with $string = "thisthat";
>
>How can I do this in perl ?
>Thanks for any help,

this will substitute "" for  the first "&" from anywhere in that
string:
$string =~ s/&//;

  --  Ed Weinberg,
      Detel, Inc., An Internet Presence Provider
      edw@detel.com
      www.detel.com/
      www.serverking.com
      www.q5.com/  <-- find someone to CoolTalk or chat with here



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

Date: 5 Jun 1998 20:05:05 GMT
From: "Greg" <gregq@saol.com>
Subject: script for DBF file?
Message-Id: <01bd90bd$7334c9e0$066219c4@horaceo.saol.com>

HI,

Does anyone know where I can get a script for reading information from a
DBF file and then 
putting it on a website.

Any help would be much appreciated.

Regards
Greg Quinn
gregq@saol.com



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

Date: 8 Mar 97 21:33:47 GMT (Last modified)
From: Perl-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 8 Mar 97)
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.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 2820
**************************************

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