[10544] in Perl-Users-Digest
Perl-Users Digest, Issue: 4136 Volume: 8
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Nov 2 22:08:48 1998
Date: Mon, 2 Nov 98 19:00:18 -0800
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Mon, 2 Nov 1998 Volume: 8 Number: 4136
Today's topics:
ANNOUNCE: Bit::Vector 5.6 <sb@sdm.de>
Re: general questions about perl from newbie <jhempe@crossroute.com>
HELP! I need a perl enviroment for Win 95 <cornuts@mrfoda.com>
Re: help: counting (Andre L.)
Inserting into Access with win32:odbc (John Lee)
Re: Interesting challenge: Reformatting text to 80 cha (Martien Verbruggen)
Re: Java's import * feature in Perl <zenin@bawdycaste.org>
Re: New posters to comp.lang.perl.misc (Martien Verbruggen)
Re: Not to start a language war but.. <zenin@bawdycaste.org>
Re: Not to start a language war but.. <zenin@bawdycaste.org>
OLE Publication <chad@anlon.com>
Re: Problem with writing to a log file (Tad McClellan)
Re: Problem with writing to a log file (Brand Hilton)
Re: Reference Safety (Dave Lorand)
replicating `more` <m.v.wilson@erols.com>
Re: Shell built-in commands in a perl script? <r28629@email.sps.mot.com>
Turning on/off "use diagnostics;" junsc@sysic.hei.co.kr
Turning on/off "use diagnostics;" junsc@sysic.hei.co.kr
Re: What is the "correct" location of perl under Solari <mgregory@asc.sps.mot.com>
who can gelp me???????? <P.Poelman@cable.a2000.nl>
Re: who can gelp me???????? (Martien Verbruggen)
Special: Digest Administrivia (Last modified: 12 Mar 98 (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 2 Nov 1998 23:08:19 GMT
From: Steffen Beyer <sb@sdm.de>
Subject: ANNOUNCE: Bit::Vector 5.6
Message-Id: <71le13$pns$1@bsdti6.sdm.de>
I am pleased to announce version 5.6 of the "Bit::Vector" module:
The package is available for download either from my web site at
http://www.engelschall.com/u/sb/download/
or from any CPAN (= "Comprehensive Perl Archive Network") mirror server:
(allow a few days for propagation if necessary)
http://www.perl.com/CPAN/authors/id/STBEY/
The package consists of a C library (designed for maximum efficiency)
which is the core of a Perl module (designed for maximum ease of use).
The C library is specifically designed so that it can be used stand-alone,
without Perl.
What does it do:
----------------
This module is useful for a large range of different tasks:
- For example for implementing sets and performing set operations
(like union, difference, intersection, complement, check for subset
relationship etc.),
- as a basis for many efficient algorithms, for instance the
"Sieve of Erathostenes" (for calculating prime numbers),
(The complexities of the methods in this module are usually either
O(1) or O(n/b), where "b" is the number of bits in a machine word
on your system.)
- for shift registers of arbitrary length (for example for cyclic
redundancy checksums),
- to calculate "look-ahead", "first" and "follow" character sets
for parsers and compiler-compilers,
- for graph algorithms,
- for efficient storage and retrieval of status information,
- for performing text synthesis ruled by boolean expressions,
- for "big integer" arithmetic with arbitrarily large integers,
- for manipulations of chunks of bits of arbitrary size,
- for bitwise processing of audio CD wave files,
- to convert formats of data files,
and more.
What's new in version 5.6:
--------------------------
The leading zeros in the output of "to_Hex()" have been suppressed.
BEWARE:
It is unlikely, but this may actually break existing applications!
Additionally, a warning produced by some compilers on line 2067 of
"BitVector.c" has been fixed.
Legal issues:
-------------
Copyright (c) 1995, 1996, 1997, 1998 by Steffen Beyer.
All rights reserved.
This package is free software; you can redistribute it and/or
modify it under the same terms as Perl itself, i.e., under the
terms of the "Artistic License" or the "GNU General Public License".
The C library at the core of this Perl module can additionally
be redistributed and/or modified under the terms of the
"GNU Library General Public License".
Prerequisites:
--------------
Perl version 5.000 or higher, and an ANSI C compiler (!)
^^^^^^
Author's note:
--------------
If you have any questions, suggestions or need any assistance, please
let me know!
I would in fact be glad to receive any kind of feedback from you!
I hope you will find this module beneficial.
Yours,
--
Steffen Beyer <sb@engelschall.com> http://www.engelschall.com/u/sb/
"There is enough for the need of everyone in this world,
but not for the greed of everyone." - Mahatma Gandhi
------------------------------
Date: Mon, 02 Nov 1998 16:54:49 -0800
From: "John A. Hempe" <jhempe@crossroute.com>
Subject: Re: general questions about perl from newbie
Message-Id: <363E5458.B89A6E99@crossroute.com>
>From The Perl Journal, Spring 1998:
"The same Perl program can run on Unix, Windows, NT, Macs, DOS, OS/2, VMS,
and AmigaOS". Well, that's sorta true. . .although usually you get some OS
specific problems. I use Perl for Win32 on Windows NT myself, with Emacs
for NT as an editor.
Perl is technically a compiler, not an interpreter. "Specifically, it's a
'load-and-go' compiler."
--"Guts: Basic Anatomy", ibid.
I doubt it uses byte-code, like Java, although I am not a compiler expert
and know little about byte code versus machine instructions or whatever
other kind of "code".
--John Hempe
Software Engineer
Extricity Software, Inc.
"Vegard Kesa" wrote:
> Is perl a script language only?
> In what environments do you code perl? Can you use a regular texteditor?
>
> Thanks,
> Vegard
------------------------------
Date: Mon, 02 Nov 1998 17:56:49 -0800
From: Cornuts <cornuts@mrfoda.com>
Subject: HELP! I need a perl enviroment for Win 95
Message-Id: <363E62E1.FD0@mrfoda.com>
Does anyone know where I can download software to program in perl
besides CPAN and Active state. I have searched around and found those
two sites as the only ones who actually distribute perl software
(enviroments) I have downloaded from both of those sites and found
"uncleanable" viruses in each. I would download the source code and
compile it myself, but all I have is Turbo C++ 3.0 which is not a
supported "C" compiler to compile the perl enviroment (Borland C++ 5.0
and beyond). Can someone help me? I would love to get started
programming in perl, and it would be nice to check my code locally
instead of doing guess work and uploading cgi's to my ISP server to find
that they don't work. Any help would be appreciated. Please respond to
cornuts@mrfoda.com if you have the chance. Thanks.
CORNUTS.
------------------------------
Date: Mon, 02 Nov 1998 22:24:35 -0500
From: alecler@cam.org (Andre L.)
Subject: Re: help: counting
Message-Id: <alecler-0211982224350001@dialup-134.hip.cam.org>
Why, reset the counter whenever the line begins with '|REC HEAD|'.
Example:
while (<DATA>) {
/^\|REC HEAD\|/ and $counter=0;
$counter++;
print "$counter -- $_";
}
__DATA__
|REC HEAD|016967|19980628|709|021447|097|19980628|MERCER FREIGHT
|REC ITEMS|1|2|2|EACH|500.00|1|1000.00|PRODUCT DESCRIPTION|ADDITIONAL COMMENTS
|REC HEAD|016968|19980629|709|020148|098|19980629|MERCER FREIGHT
|REC ITEMS|1|1|1|EACH|1500.00|1|1500.00|PRODUCT DESCRIPTION|ADDITIONAL COMMENTS
|REC ITEMS|2|4|4|EACH|250.00|2|1000.00|PRODUCT DESCRIPTION|ADDITIONAL COMMENTS
|REC HEAD|016969|19980630|709|020349|099|19980630|MERCER FREIGHT
|REC ITEMS|1|1|1|EACH|2000.00|2|2000.00|PRODUCT DESCRIPTION|ADDITIONAL COMMENTS
-------------------------------------------------------------------
Output:
1 -- |REC HEAD|016967|19980628|709|021447|097|19980628|MERCER FREIGHT
2 -- |REC ITEMS|1|2|2|EACH|500.00|1|1000.00|PRODUCT DESCRIPTION|ADDITIONAL
COMMENTS
1 -- |REC HEAD|016968|19980629|709|020148|098|19980629|MERCER FREIGHT
2 -- |REC ITEMS|1|1|1|EACH|1500.00|1|1500.00|PRODUCT
DESCRIPTION|ADDITIONAL COMMENTS
3 -- |REC ITEMS|2|4|4|EACH|250.00|2|1000.00|PRODUCT DESCRIPTION|ADDITIONAL
COMMENTS
1 -- |REC HEAD|016969|19980630|709|020349|099|19980630|MERCER FREIGHT
2 -- |REC ITEMS|1|1|1|EACH|2000.00|2|2000.00|PRODUCT
DESCRIPTION|ADDITIONAL COMMENTS
HTH,
Andre
==============================
In article <363E40D5.600@idiom.com>, marx@idiom.com wrote:
> I have a data file that consists of record headers and record items.
> For every record head there may be one or more record items associated
> with it. The record items are directly below its associated record
> head. I need to count each record header and its coresponding record
> items and as soon as a new record head appears the counter should reset.
------------------------------
Date: Tue, 03 Nov 1998 01:59:54 GMT
From: jglee@us.ibm.com (John Lee)
Subject: Inserting into Access with win32:odbc
Message-Id: <363e62ba.1762536@news-s01.ny.us.ibm.net>
I have been trying to insert into an MS Access database with the
following test program...
use Win32::ODBC;
$Data = new Win32::ODBC("foobar");
$Data->Run ("INSERT INTO Table1 (A,b) VALUES (please, work)");
$Data->Close();
The Run command spits out the following...
Excecuting connection 1
sql statement: "INSERT INTO Table1 (A,b) VALUES (please, work)"
Error: "-3010[Microsoft][ODBC Microsoft Access 97 Driver] Too few
parameters. Expected 2.10"
--------------------
Does anyone know how to make inserts work with Access??
------------------------------
Date: Tue, 03 Nov 1998 01:39:41 GMT
From: mgjv@comdyn.com.au (Martien Verbruggen)
Subject: Re: Interesting challenge: Reformatting text to 80 chars.
Message-Id: <x9t%1.61$NU5.235281@nsw.nnrp.telstra.net>
In article <363D681C.80564F43@curtco.com>,
Trevor Hilaiel <trevorh@curtco.com> writes:
> Hello,
>
> I use vim-5.3 and was trying to figure out how to reformat my text
> to 80 characters after performing a bunch of edits. basically
> breaking lines longer than 80 and combining lines shorter than
> 80.. I'm sure there's a built in option that would allow me to do
> this without any external filter, but I figured
Yes there is an internal option (:help gq). I actually used it to
reformat the above stuff.
For external options: fmt (if you're not on a unix box, you can get
precompiled binaries from many places, or sources if you want them.
For a perl solution: Text::Wrap
Martien
--
Martien Verbruggen |
Webmaster www.tradingpost.com.au | "In a world without fences,
Commercial Dynamics Pty. Ltd. | who needs Gates?"
NSW, Australia |
------------------------------
Date: 03 Nov 1998 02:41:34 GMT
From: Zenin <zenin@bawdycaste.org>
Subject: Re: Java's import * feature in Perl
Message-Id: <910060943.491086@thrush.omix.com>
[posted & mailed]
mlehmann@prismnet.com wrote:
: I have a set of classes that implement database transactions. The parent
: class handles the generic methods of performing transactions. The child
: classes handle the specific transactions, along with any non-generic methods.
Yep, smells like a basic OO job. :-)
: There are many of these subclasses, but I don't want my API users to have to
: write a "use" statement for every transaction object that they instantiate.
Nore would I.
: To handle this initially, I place all of the sub classes in one file.
Ack! :-)
: But this file is now approaching 10,000 lines when I include POD in it.
Yep. You can split it up into different files and simply have the
parent call the use:
## Parent
use Parent::Child1;
use Parent::Child2;
etc...
## User code
use Parent;
my $obj = Parent::Child1->new();
This however, also gets ugly fast as the parent needs to know and
load all the child classes at once. Blagh...
Thank goodness there are other ways, as you've already found. :-)
: This
: seems terribly wasteful of time during the loading phase if the API user just
: wants one or two transaction objects.
Hmm, if they want one or two of these objects then "use
Parent::Object_One;" isn't asking too much. However, read on.
: What I would like is something similar to Java's import * feature which
: allows a coder to use a class that is part of a hierarchy. That way only the
: top of the hierarchy is listed in the API users code.
Perl's package space and structure is for readability and
organization, and implies no class structure what so ever. That is,
Foo may be a subclass of Bar, but Bar::Foo might not be.
: For now, I am defining a class which I will call Transaction::Message.
: Inside that class I export a function called create_message. create_message
: looks like this:
>snip<
: This is what I call an "object factory" function. It is a function exported
: into the callers name space which autoloads the class, then calls the classes
: constructor.
This is very similar to the way Tk works. When the user has code
that looks like this:
use Tk;
my $MainWindow = MainWindow->new();
my $button = $MainWindow->Button ();
The call to Button() dynamically loads Tk::Button at run time, much
like your "object factory" method. -Although the user is free to
call use Tk::Button themselfs and so move all load time to startup
so that there is no run time lag on the first call to Button().
: What is a better way to do this?
There are different ways, but if they are better or not is up to
you. I would suggest however, wrapping that require in an eval {}
block and checking $@. This way you can catch a load error such as
the class not existing (require is fatal on error by default).
: Is this a good way?
It's a way. Again, if it is good or not is up to you. Welcome to
Perl. :-)
: What is a good way to return an error message when an object is not
: constructed? Is setting $! a bad thing to do?
Only set $! if you've got a valid errno to set it to, which is
rare. -$! is highly magical. Setting $@ is much more highly
advised for such conditions. It allows user code to be writen
like this:
my $obj = Foo::Object->new()
or die; ## $@ thrown by default, with stack trace
Or you can do:
my $obj = Foo::Object->new()
or die "I could not create a new Foo::Object: $@, stopped";
Or you can have the constructor throw an exception:
my $obj;
eval { ## "try" block
$obj = Foo::Object->new(); ## Calls die("message") if it fails
};
if ($@) { ## "catch" block
die "I could not create a new Foo::Object: $@, stopped";
}
Or, in perl 5.005 and higher you can throw (aka die()) an actual
object instead of just a string:
package MyException;
sub new {
my $class = shift;
bless { @_ }, $class;
}
package Foo::Object;
sub new {
createNewFooObject()
or die MyException->new (
text => "Sorry about that",
errno => $!,
);
}
package main;
my $obj;
eval {
$obj = Foo::Object->new();
};
if ($@) {
## Catch all exceptions
if (ref $@ eq 'MyException') {
## Handle MyException
## Non fatal so we'll just warn()
warn "Foo::Object error: $@->{text}, errno: $@->{errno}, ignored";
}
else {
## Unknown exception, rethrow it (someone above us might know more
## about it)
die;
}
}
Also see the Exceptions (in alpha stages I think) at CPAN.
--
-Zenin (zenin@archive.rhps.org) From The Blue Camel we learn:
BSD: A psychoactive drug, popular in the 80s, probably developed at UC
Berkeley or thereabouts. Similar in many ways to the prescription-only
medication called "System V", but infinitely more useful. (Or, at least,
more fun.) The full chemical name is "Berkeley Standard Distribution".
------------------------------
Date: Tue, 03 Nov 1998 01:44:01 GMT
From: mgjv@comdyn.com.au (Martien Verbruggen)
Subject: Re: New posters to comp.lang.perl.misc
Message-Id: <Bdt%1.63$NU5.235281@nsw.nnrp.telstra.net>
In article <363dff09.0@news.greatbasin.net>,
"Dan O'Connor" <dan@ferrarinet.reno.nv.us> writes:
> You people here spend half your time telling people that their posts aren't
> related to Perl.
> Well, Mr. Bacon, high keeper of the CLPM statistics, your message contains
> nothing about Perl in it either. My mother always told me, spam is as spam
> does.
If you read the message, you might have noticed that it doesn't
anywhere make a judgement about the content or nature of the posts or
posters.
I don't like your tone. I don't like the fact that you included that
whole message just to add those few lines. I don't like that you call
a message that is about this group unrelated to this group. I think
you should figure out what spam means. I think I have read enough of
your messages.
*plonk*
Martien
--
Martien Verbruggen |
Webmaster www.tradingpost.com.au | "In a world without fences,
Commercial Dynamics Pty. Ltd. | who needs Gates?"
NSW, Australia |
------------------------------
Date: 3 Nov 98 01:49:32 GMT
From: Zenin <zenin@bawdycaste.org>
Subject: Re: Not to start a language war but..
Message-Id: <910058128.384125@thrush.omix.com>
Jason Orendorff <jorendorff@ixl.com> wrote:
: > if (not open ARTICAL,"<$filename") {
: > warn "Can't open artical file $filename because $!";
: > next;
: > }
:
: Equivalent Python code:
:
: try:
: article = open(filename, 'r')
: except IOError, oops:
: sys.stderr.write("Can't open article file %s because %s" %
: (filename, oops.strerror))
: continue
Incorrect, this is not the same at all.
The perl warn() can be cought by the caller with a WARN
handler (eg, $SIG{'__WARN__'} = sub { handler_code }). This
is highly useful for redirecting and reformatting code warnings
to a more usable place then simply stderr. The CGI::Carp module
uses this feature to add time stamps and other pretty formating
to all warnings and exceptions that get written to the server's
error logs as well as (on programmer's request) reformating errors
for proper display to the browser (great for CGI debugging). This
feature can even catch syntax errors and redirect/format them.
Tk::Error is another fine example of this power in real world
practice.
--
-Zenin (zenin@archive.rhps.org) From The Blue Camel we learn:
BSD: A psychoactive drug, popular in the 80s, probably developed at UC
Berkeley or thereabouts. Similar in many ways to the prescription-only
medication called "System V", but infinitely more useful. (Or, at least,
more fun.) The full chemical name is "Berkeley Standard Distribution".
------------------------------
Date: 3 Nov 98 02:03:31 GMT
From: Zenin <zenin@bawdycaste.org>
Subject: Re: Not to start a language war but..
Message-Id: <910058967.588083@thrush.omix.com>
Michael P. Reilly <arcege@shore.net> wrote:
: In comp.lang.python Sam Holden <sholden@pgrad.cs.usyd.edu.au> wrote:
: : On Mon, 02 Nov 1998 17:24:17 -0800, Jason Orendorff <jorendorff@ixl.com> wrote:
>snip<
: : Except of course that warn does not have to output to stderr...
: : $SIG{__WARN__} can do whatever it likes with it (useful in things such
: : as CGI (though you should just use CGI.pm)).
: : This leaves the caller free to handle the warning however it wants.
: : So the equivelant python is...?
:
: import sys, cStringIO
: real_stderr = sys.stderr
: sys.stderr = cStringIO.StringIO() # can be any object that mimics a
: # file object (with a write method)
: Then the internal commands that write to stderr will be redirected to
: this new object. The "real_stderr" is to revert back, if necessary.
: This is better for CGI script, because you can do:
: sys.stderr = sys.stdout
This is still not equivalent at all.
You're just mucking with the global sys.stderr, which then affects
all calls to stderr. This would be the same as dup()ing and
re-open()ing STDERR in perl with a tied filehandle class, and just
as simple. -Same with C or shell for that matter.
It is however, still nothing close to a $SIG{__WARN__} handler for
warn(). A warn() (and die() for that matter (ie $SIG{__DIE__})
handler is very much like a normal OO exception handler (eg, a Java
catch{} or Python except block), with the *extra* ability to
*return* from the exception handler to the location where warn() or
die() was called. This is why it is handled by a %SIG handler, as
it is an asynchronous and arbitrary handler with the same
functionality, form, and power of a sigaction() handler.
So we ask again, the equivalent Python code would be what, exactly?
--
-Zenin (zenin@archive.rhps.org) From The Blue Camel we learn:
BSD: A psychoactive drug, popular in the 80s, probably developed at UC
Berkeley or thereabouts. Similar in many ways to the prescription-only
medication called "System V", but infinitely more useful. (Or, at least,
more fun.) The full chemical name is "Berkeley Standard Distribution".
------------------------------
Date: Mon, 02 Nov 1998 20:35:17 -0600
From: Chad Moston <chad@anlon.com>
Subject: OLE Publication
Message-Id: <363E6BE5.8941BE46@anlon.com>
Anybody know of some good documents that contain
definitions of OLE objects?
------------------------------
Date: Mon, 2 Nov 1998 19:51:43 -0600
From: tadmc@flash.net (Tad McClellan)
Subject: Re: Problem with writing to a log file
Message-Id: <fjnl17.m15.ln@flash.net>
Matt McHugh (m0317@ix.netcom.com) wrote:
: I'm very new to perl and I just finished writing one of my first perl
: scripts but I'm having difficulty sending any of the errors to a log file.
^^^^^^^^^^
What errors?
Do you mean the STDERR from ping?
You are sending all of ping's output to the bit bucket with
shell redirection. You wouldn't be doing that it you _wanted_
the output, so what do you want to output and where do you
want to put it?
: I thought my syntax was correct, but nothing ever gets written and there are
: errors.
Get written where?
Get written what?
;-)
: Basically it checks the return value of ping and if there isn't a
: response from the host it records that error in a file which gets opened in
: the beginning of the script.
: Does anyone have any ideas?
: Here's the script:
: #!/usr/local/bin/perl -w
: open (NOTFOUND, ">>/usr/mmchugh/notfound") ||
: die "/usr/mmchugh/notfound is not found";
You never output anything to the NOTFOUND filehandle.
Maybe you want to do that?
print NOTFOUND "here is some stuff to go in the 'notfound' file\n";
: open (AIPHOSTS, "/usr/scripts/perl/hosts1") ||
: die "/usr/mmchugh/hosts not found ";
: while (<AIPHOSTS>) {
: if (/(^[^;\$\s]+)/) {
: $ret = system ("/usr/sbin/ping $1 5 > /dev/null 2>&1") ;
^^^^^^^^^^^^^^^^
that says to discard all of ping's output. Is that what you want?
: if ($ret) { print "$1 not found\n"; }
^^^^^
That print goes to the STDOUT filehandle.
Is that where you want it to go?
: }
: }
--
Tad McClellan SGML Consulting
tadmc@metronet.com Perl programming
Fort Worth, Texas
------------------------------
Date: 3 Nov 1998 00:59:50 GMT
From: bhilton@tsg.adc.com (Brand Hilton)
Subject: Re: Problem with writing to a log file
Message-Id: <71lki6$bh110@mercury.adc.com>
In article <71lf8d$pus@dfw-ixnews3.ix.netcom.com>,
Matt McHugh <m0317@ix.netcom.com> wrote:
>Hello all,
>
>I'm very new to perl and I just finished writing one of my first perl
>scripts but I'm having difficulty sending any of the errors to a log file.
>I thought my syntax was correct, but nothing ever gets written and there are
>errors. Basically it checks the return value of ping and if there isn't a
>response from the host it records that error in a file which gets opened in
>the beginning of the script.
>
>Does anyone have any ideas?
>
>
>Thanks
>
>Here's the script:
>
>#!/usr/local/bin/perl -w
>
>open (NOTFOUND, ">>/usr/mmchugh/notfound") ||
> die "/usr/mmchugh/notfound is not found";
>open (AIPHOSTS, "/usr/scripts/perl/hosts1") ||
> die "/usr/mmchugh/hosts not found ";
+2 brownie points for checking the return from open :-)
>while (<AIPHOSTS>) {
>
> if (/(^[^;\$\s]+)/) {
> $ret = system ("/usr/sbin/ping $1 5 > /dev/null 2>&1") ;
> if ($ret) { print "$1 not found\n"; }
I think you want NOTFOUND here ^ (with no comma after it).
if ($ret) { print NOTFOUND "$1 not found\n"; }
> }
>}
--
_____
|/// | Brand Hilton bhilton@adc.com
| ADC| ADC Telecommunications, ATM Transport Division
|_____| Richardson, Texas
------------------------------
Date: Tue, 3 Nov 1998 00:22:41 GMT
From: davel@spc.uchicago.edu (Dave Lorand)
Subject: Re: Reference Safety
Message-Id: <davel-0211981822410001@honeybee.spc.uchicago.edu>
In article <363DF59F.BEC2C46B@atrieva.com>, "Jerome O'Neil"
<jeromeo@atrieva.com> wrote:
> I have been working with large hashes, and am concerned about scoping
> issues when passing their references arround. If one sub returns a hash
> reference for use in another sub, at what point does the reference fall
> out of scope? Or am I just being paranoid?
Well, references don't have scope, because they act more like pointers
than like variable names. If you've programmed in C, or some other
language with pointers, that sentence will tell you a lot. Otherwise, it
won't help much.
(In case you don't know about pointers ...) The deal is that a reference
to a hash points to the actual location in memory of some hash (named or
not), in some magical way (I've never looked at the Perl internals). It
doesn't point to %foo, it points to the hash itself.
So, the only time you need to worry about a hash reference becoming
invalid is if the entire hash is undef'd. But I don't know if that's even
possible. You can undef a named hash ("undef %foo"), so that %foo then
contains nothing. But can you undef an anonymous hash? "undef
%$rh_foo"? What would this do? I suspect it wouldn't make sense, but I
should let someone else speak to it.
> Example: What situation would cause the reference returned by
> getahashref() to go away?
>
> #/usr/local/bin/perl -w
> use strict;
> useahashref();
>
> sub getahashref(){
> my(%hash) = (
> # This hash is really big!
> );
>
> return \%hash;
> }
>
> sub useahashref(){
> my($ref) = getahashref();
> foreach(keys($%ref)){
> # Were doing some cool stuff here.
> }
> }
In a situation like this, your referenced hashes last forever. Each time
you run getahashref() you generate a new one, and each time getahashref()
goes out of scope the name %hash stops being bound to that particular
hash. You can always delete keys from them, though. (Maybe you can undef
them, but I kind of doubt it. Anyway, you could take a vow not to do that
in this particular project; it's an easy vow to keep because you can
always seach for the word "undef" in your code to see if you've used it
that way.)
I hope this helps.
Regards,
Dave
____________________________________________________________
| Dave Lorand | davel@spc.uchicago.edu |
| Programmer/Analyst | 773-702-3792 |
| Social Science Research Computing | 773-702-0793 (dept.) |
| University of Chicago | 773-702-2101 (fax) |
+-----------------------------------+------------------------+
------------------------------
Date: Tue, 03 Nov 1998 02:26:26 +0000
From: WMWilson <m.v.wilson@erols.com>
Subject: replicating `more`
Message-Id: <363E69D2.4C7B5992@erols.com>
Anyone know where I can find out about replicating the more (or pg)
command?....Preferrably something simple.
------------------------------
Date: Mon, 02 Nov 1998 18:31:21 -0600
From: Tk Soh <r28629@email.sps.mot.com>
To: Jonathan Stowe <gellyfish@btinternet.com>
Subject: Re: Shell built-in commands in a perl script?
Message-Id: <363E4ED9.30525CEC@email.sps.mot.com>
[posted to comp.lang.perl.misc and copy emailed]
Jonathan Stowe wrote:
>
> You would need to do :
>
> system("/usr/bin/bash -c 'source <file>'")
>
> but I cant see any real purpose because the environment will disappear as
> soon as the shell exits - you will probably want to examine the FAQ about
> altering the environment in the way that your use of 'source' would
> suggest.
On the matter of efficiency:
perldoc -f exec:
...
If there is only one scalar argument or an array with one element in it,
the argument is checked for shell metacharacters and if there are any,
the entire argument is passed to the system's command shell for parsing
If there are no shell metacharacters in the argument, it is split into
words and passed directly to C<execvp()>, which is more efficient.
...
system("ls") seems much faster than system("csh -c 'ls'"). how does this
fit into the text above?
Does "system's command shell" refer only to /usr/bin/sh?
-tk
------------------------------
Date: Tue, 03 Nov 1998 01:42:07 GMT
From: junsc@sysic.hei.co.kr
Subject: Turning on/off "use diagnostics;"
Message-Id: <71ln1f$d5m$1@nnrp1.dejanews.com>
Hi, All
I want to turn on/off "use diagnostics;" by giving the option, i.e. "-debug"
as follows. ############################### #!/usr/local/perl/script -w
$debug = 0; foreach $argv (@ARGV){ if($argv =~ /^-debug$/) { $debug = 1; }
else { } }
if($debug) {
use diagnostics;
}
###############################
But it seems that "use" isn't affected by the above branch scheme.
Is there any way to accomplish this compiling diagnostics option.
Thanks in advance.
Sungchun
-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/ Search, Read, Discuss, or Start Your Own
------------------------------
Date: Tue, 03 Nov 1998 01:41:53 GMT
From: junsc@sysic.hei.co.kr
Subject: Turning on/off "use diagnostics;"
Message-Id: <71ln11$d5h$1@nnrp1.dejanews.com>
Hi, All
I want to turn on/off "use diagnostics;" by giving the option, i.e. "-debug"
as follows. ############################### #!/usr/local/perl/script $debug =
0; foreach $argv (@ARGV){ if($argv =~ /^-debug$/) { $debug = 1; } else { }
}
if($debug) {
use diagnostics;
}
###############################
But it seems that "use" isn't affected by the above branch scheme.
Is there any way to accomplish this compiling diagnostics option.
Thanks in advance.
Sungchun
-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/ Search, Read, Discuss, or Start Your Own
------------------------------
Date: 03 Nov 1998 11:02:56 +1030
From: Martin Gregory <mgregory@asc.sps.mot.com>
Subject: Re: What is the "correct" location of perl under Solaris?
Message-Id: <r84sshzkcn.fsf@asc.sps.mot.com>
Tk Soh <r28629@email.sps.mot.com> writes:
> I wonder why we couldn't just let the #! look for Perl by just PATH variable.
>
> -tk
We do. We use this at the top of perl scripts...
eval 'exec perl -w -S $0 ${1+"$@"}' # Use the -*- perl -*- on our path
if 0;
.. no more #! problems...
Martin.
------------------------------
Date: Tue, 3 Nov 1998 02:50:25 +0100
From: "P. Poelman" <P.Poelman@cable.a2000.nl>
Subject: who can gelp me????????
Message-Id: <71lnis$q43$1@newton.a2000.nl>
I'm looking for a version of rpcbind on a Silicon Graphics machine,
with irix 6.3, who knows were i can get it??????????
------------------------------
Date: Tue, 03 Nov 1998 02:07:29 GMT
From: mgjv@comdyn.com.au (Martien Verbruggen)
Subject: Re: who can gelp me????????
Message-Id: <Bzt%1.69$NU5.265136@nsw.nnrp.telstra.net>
In article <71lnis$q43$1@newton.a2000.nl>,
"P. Poelman" <P.Poelman@cable.a2000.nl> writes:
> I'm looking for a version of rpcbind on a Silicon Graphics machine,
> with irix 6.3, who knows were i can get it??????????
And your perl question is?
Maybe you should ask this in a group that talks about SGI machines
and/or the Irix OS.
Martien
--
Martien Verbruggen |
Webmaster www.tradingpost.com.au | "In a world without fences,
Commercial Dynamics Pty. Ltd. | who needs Gates?"
NSW, Australia |
------------------------------
Date: 12 Jul 98 21:33:47 GMT (Last modified)
From: Perl-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Special: Digest Administrivia (Last modified: 12 Mar 98)
Message-Id: <null>
Administrivia:
Special notice: in a few days, the new group comp.lang.perl.moderated
should be formed. I would rather not support two different groups, and I
know of no other plans to create a digested moderated group. This leaves
me with two options: 1) keep on with this group 2) change to the
moderated one.
If you have opinions on this, send them to
perl-users-request@ruby.oce.orst.edu.
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 4136
**************************************