[9815] in Perl-Users-Digest
Perl-Users Digest, Issue: 3408 Volume: 8
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Aug 10 17:07:19 1998
Date: Mon, 10 Aug 98 14:00:33 -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 Mon, 10 Aug 1998 Volume: 8 Number: 3408
Today's topics:
Re: ActiveState 5.005: Where are the threads? (Jan Dubois)
Re: APPEND TO DBM? HELP! (Mark W. Schumann)
CGI scripts <webmaster@sunshinevalley.com>
Embedding Perl in ActiveState 5.005 version (ISAPI) <kevin@today.com>
Re: file modification <david@kasey.umkc.edu>
having trouble with printing array to html <rosso@rsn.hp.com>
Re: os/2, modules, filenames (Ilya Zakharevich)
Re: os/2, modules, filenames <dummy@bloodgate.com>
Re: perl extensions in ActivePerl 5.005 under WindowsNT (Jan Dubois)
perl scripts tries to locate specific file, getting fil djetz@my-dejanews.com
Re: posting to external script within perl (Grinch)
Re: Regex problem (Larry Rosler)
Re: Self-printing code (brian d foy)
Re: Self-printing code (brian d foy)
socket: read on close filehandle ??? <byteshifter@shifted-bytes.de>
Re: strings (Craig Berry)
Re: Test Results - Asking a question (Craig Berry)
Re: variable indirection [off topic - parens] (Nem W Schlecht)
Re: variable indirection [off topic - parens] <jdporter@min.net>
Re: variable interpolation (Mark-Jason Dominus)
Re: variable interpolation <tchrist@mox.perl.com>
Re: What is the purpose of Perl <tchrist@mox.perl.com>
Re: What is the purpose of Perl <jdporter@min.net>
what is this stuff? (Anthony Reeves)
Special: Digest Administrivia (Last modified: 12 Mar 98 (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Mon, 10 Aug 1998 21:43:45 +0200
From: jan.dubois@ibm.net (Jan Dubois)
Subject: Re: ActiveState 5.005: Where are the threads?
Message-Id: <35d34402.4162655@news2.ibm.net>
[mailed & posted]
Michael Schilli <mschilli@blaxxun.com> wrote:
>unfortunately, the only binary 5.005 distribution for Win32
>(ActiveState) doesn't support the new threads features. Anyone knows of
>a binary distribution that includes them?
Michael,
ActivePerl uses the PERL_OBJECT build option, which is (currently)
incompatible with the USETHREADS option, so you will probably not see a
version of ActivePerl with threads. Their idea of multithreading is to
create multiple threads and embed a CPerl object in each of them.
You can compile Perl yourself with threading support. I've read that the
freely available mingw port of gcc should now be useable to create Perl
binaries on win32.
-Jan
------------------------------
Date: 10 Aug 1998 15:24:42 -0400
From: catfood@apk.net (Mark W. Schumann)
Subject: Re: APPEND TO DBM? HELP!
Message-Id: <6qnhdq$om4@junior.apk.net>
[copy emailed to author and posted]
In article <35c70e6e.22971856@news.syd.enternet.com.au>,
<c.clark@student.unsw.edu.au> wrote:
>I am desperately trying to append data to an existing DBM file,
>however so far have been unable.
Can you post a really, really short example of what you've tried?
>I know of the O_APPEND thing and how it is somehow linked to the "tie"
>function. I am new at PERL and all I need is a nice simple example
>and I am set. Can anyone provide me with one? Just a snippet of code
>that demonstrates appending certain fields to a DBM file.
I'll give you a hint that helped me:
use strict;
If that doesn't show you the problem immediately, and I think it will,
come on back with your example.
>I have looked in the FAQ (I'm sure everyone says that, but it's true)
>and heaps of places on the Web, but I can't find a nice piece of
>example code.
Nah, it's the people who don't even mention the FAQ that we worry
about.
------------------------------
Date: 10 Aug 98 19:08:21 GMT
From: "webmaster" <webmaster@sunshinevalley.com>
Subject: CGI scripts
Message-Id: <01bdc4a2$c2081ea0$8493c6d0@bbwolf>
We are looking for Cgi scripts to to place on our website for free
download.
any and all scripts can be mailed to:
scripts@sunshinevalley.com
Please give a small write up on the script.
All authors will be given credit for there scripts!
http://www.sunshinevalley.com
------------------------------
Date: Mon, 10 Aug 1998 12:26:24 -0700
From: Kevin Williams <kevin@today.com>
Subject: Embedding Perl in ActiveState 5.005 version (ISAPI)
Message-Id: <35CF4960.47E0E33F@today.com>
Is there a way to embed the ISAPI version of Perl (PerlIS.dll) into my
c++ application?
I have been unabled to find any documentation (current that is) on how
to embed it.
I am using BC++ on an NT 4.0 platform. I basically need to do some
preprocessing (that I can only do in C++) before I call my perl scripts.
Thanks,
Kevin
------------------------------
Date: Mon, 10 Aug 1998 15:06:21 -0500
From: David Nicol <david@kasey.umkc.edu>
To: jdporter@min.net
Subject: Re: file modification
Message-Id: <35CF52BD.53949CE3@kasey.umkc.edu>
John Porter wrote:
> Although humans have an easy time thinking of a text file as
> being a sequence of lines ... computers usually see the
> text file as a sequence of bytes. In general, there's no
> direct way for Perl to ... insert text into a file....
>
> The general solution is to create a temporary copy of the
> text file with the changes you want, then copy that over the
> original.
>
> PLEASE NOTE that this is true, regardless of the programming
> language. It will not be any easier (and will probably end up
> being harder) in C.
That is to say, the restriction is in the file system rather than
the language. Designing a file system that supports inserts into the
middle (or beginning) is not hard. In fact both FAT and i-nodes are
supposed to support this functionality according to CS textbooks.
C doesn't provide, at least though fopen(), an interface for doing
insertion. Direct manipulation of i-node tables, and support for
incompletely filled nodes, is called for. This is rightfully taboo,
as fiddling directly with one's file system is all kinds of dangerous.
What can be done, without sacrificing cross-platform compatability
or endangering file system integrity, is implement your own file system
layer on top of the file system you have already.
Instead of using a single sequential file to hold all your data and
rewriting all 300M of it when you want to add a record at the beginning,
use a directory, or a tree of directories even, with thousands of
files in them, none of them greater than the largest file size you
want to have to write out to support a change. This would be system-
dependent and related to the I-node size or block size on the file
system
being used as the base material.
You will need to overload all the read and write mechanisms
to support the normal operations on your new file system, or restrict
operations on the new file system to ones made through the access
functions
you provide.
But now instead of needing to write out the entire file to insert text
in the middle (or at the beginning) you only need to rewrite the
affected portion.
Check every once in a while (daily, or after every 2000 inserts)
to make split any files that have grown over some threshold size into
two (or twenty) smaller parts (possibly in their own subdirectory with
the
same name as the old file)
The problem with this approach is that you no longer have a standard
file, so all reads and writes to it have to go through your tools
instead of the standard ones.
One advantage is that you can use flock() for finer grained locking
than otherwise, because there are now fewer records per file.
You can keep your data both randomly accessable and sorted this way,
without loading your file full of dummy blank fixed-length records.
AFAIK there is no RFC, ISO standard, or CPAN module having
implemented such a system already.
Please correct me if I am wrong,
> wilgro@my-dejanews.com wrote:
> >
> > I am looking for a program that will take a text file and add a line to it
> > at the beginning without needing to pull the whole file in, modify it and
> > then save it again. I think this is what C does.
>
> Nope. Sorry.
>
> > It takes too many resources if the file is very large.
> > Does anyone know if this is true for C.
>
> Yep. The language is irrelevant.
______________________________________________________________________
David Nicol 816.235.1187 UMKC Network Operations david@news.umkc.edu
"A Kodak moment carved in wood" -- Iris Heckman
------------------------------
Date: Mon, 10 Aug 1998 15:17:29 -0500
From: Sara Rosso <rosso@rsn.hp.com>
Subject: having trouble with printing array to html
Message-Id: <35CF5559.5723@rsn.hp.com>
I am trying to convert text submitted by a form into a bulleted list.
Since the number of bullets will vary from submission to submission, I
decided the easiest way would be to use a textarea, and separate the
list items by a semi-colon.
The input should go from:
number one; number two; number 3; this is item number four
to(for practical purposes, I will use a o as a bullet):
o number one
o number two
o number three
o this is item number four
This is the html referencing the textarea:
<textarea name="deliverables" wrap=virtual cols=55 rows=8></textarea>
This is the perl I have - no errors appear when compiled:
open(pdstemp, ">/itsrc/apache/htdocs/projects/temp/$pid.html");
print pdstemp "<ul>\n";
@delivarray = split(/;/, $deliverables);
foreach $line (@delivarray) {
print pdstemp "<li>$line\n";
}
print pdstemp "</ul>\n";
close pdstemp;
When I go to view the file online, other html is there that I reference
earlier in the perl, but there is no list. (This list is part of a
larger on-the-fly generated html document.)
Please give me any insight you have on this matter. Is there an easier
way to do this?
Thanks in advance.
Sara Rosso
------------------------------
Date: 10 Aug 1998 18:58:08 GMT
From: ilya@math.ohio-state.edu (Ilya Zakharevich)
Subject: Re: os/2, modules, filenames
Message-Id: <6qnfs0$1r4$1@mathserv.mps.ohio-state.edu>
[A complimentary Cc of this posting was sent to Tels
<dummy@bloodgate.com>],
who wrote in article <35CF3B2F.5810@bloodgate.com>:
> Hi,
>
> is there a newer (than 5.002) port for OS/2?
Yes.
> hobbes.mnsu.edu has only
> 5.002, and the CPAN dir is empty!
No.
> if not, what do i need o get it ported
Nothing.
> and where do i get the source code to do this?
Where all other get it.
Ilya
------------------------------
Date: Mon, 10 Aug 1998 21:17:58 +0100
From: "Tels - \"DONT REPLY TO THIS ADDRESS!\"" <dummy@bloodgate.com>
Subject: Re: os/2, modules, filenames
Message-Id: <35CF5576.3A07@bloodgate.com>
Ilya Zakharevich wrote:
> [A complimentary Cc of this posting was sent to Tels
> <dummy@bloodgate.com>],
sig sayd:
!! DONT reply to dummy@bloodgate.com !!
I have adjusted my slightly, read it again.
> who wrote in article <35CF3B2F.5810@bloodgate.com>:
> > Hi,
> > is there a newer (than 5.002) port for OS/2?
> Yes.
> > hobbes.mnsu.edu has only
> > 5.002, and the CPAN dir is empty!
> No.
the os/2 dir was empty a couple of days ago. my post got delayed because
my news server is broken and i had to use another. i didnt bother to
check cpan again. mea culpa.
> > if not, what do i need o get it ported
> Nothing.
I need nothing to get it ported? it will port itself magically? [thats
sarcasm]
> > and where do i get the source code to do this?
> Where all other get it.
*sight* how usefull that remark.....
Regards,
Tels
--
!! DONT reply to dummy@bloodgate.com !!
If you post, dont email me.
If you must email me,
dont use dummy@bloodgate.com,
read my webpages to find out how to mail me.
If you must email AND post, then make a notice
of this fact in your post/mail.
Thank you!
Design & Coding: http://bloodgate.com/
------------------------------
Date: Mon, 10 Aug 1998 21:43:44 +0200
From: jan.dubois@ibm.net (Jan Dubois)
Subject: Re: perl extensions in ActivePerl 5.005 under WindowsNT 4.0SP3
Message-Id: <35d041ae.3566508@news2.ibm.net>
[mailed & posted]
"Peter W.L. Wassenaar" <pnp@worldonline.nl> wrote:
>I'm trying to master the use of perl extensions (ActiveState's perl 5.005)
>by keying in example1
>of the perl-doc `perlxstut', but it refuses to compile with MicroSoft Visual
>C++ 4.2 (WindowsNT 4.0 SP3).
>
> h2xs -A -n Mytest
> cd mytest
> <<editing mytest.xs conform example1>>
> perl Makefile.pl
> nmake # gives the following error
> D:\Perl\5.005\lib\MSWin32-x86-object\CORE\perl.h
> (1232) : error C2644: basis 'CPerlObj' for pointer to
>member has not been defined.
Peter,
ActivePerl is compiled with the PERL_OBJECT option to accommodate
ActiveState addon products like PerlScript, PerlEx etc. This requires C++
which is not compatible with MSC++ 4.2 anymore. I tried unsuccessfully to
fix this, but 4.2 unfortunately doesn't grok the required predeclarations
for the CPerl object, you have to define it, which you can't, because some
required types are not yet defined; a circular reference.
You have to update to MSC++ 5.0 to compile Perl 5.005 with PERL_OBJECT
enabled, but standard build still compiles with 4.2, so you can recompile
from the sources if you don't use the other ActiveState gadgets. Then you
can also compile the extensions with 4.2.
-Jan
------------------------------
Date: Mon, 10 Aug 1998 19:07:42 GMT
From: djetz@my-dejanews.com
Subject: perl scripts tries to locate specific file, getting file not found
Message-Id: <6qngdt$c5p$1@nnrp1.dejanews.com>
Plese help!!
I have perl 5.003 installed on an NT Server box. I have a perl script that
is suppose to perform an oracle export, then find the .dmp and .log files and
copy them to another location. In the following piece of code, the 'if'
expression returns failure and returns the 'File not found', but only when it
runs as a scheduled batch job from at. It runs successfully from the console
(dos prompt) and my files get copied.
if (defined($schema_log_file = <$exports_dir$user_log_file>)) {
($name, $path, $suffix) = fileparse($schema_log_file, '\.log');
$new_schema_log_file = $exports_dir . $name . $today . $suffix;
print "...Copying $schema_log_file to $new_schema_log_file.\n";
copy($schema_log_file, $new_schema_log_file) || warn "cannot copy log: $! ";
} elsif {
print "File not found.\n";
}
I've checked file permisions, ownership, user rights ...what else can I try?
I'm new to both Perl and NT so any suggestions would be welcome.
Please reply to djetz@sierrasys.com
Thanks in advance,
D Jetz
-----== Posted via Deja News, The Leader in Internet Discussion ==-----
http://www.dejanews.com/rg_mkgrp.xp Create Your Own Free Member Forum
------------------------------
Date: Mon, 10 Aug 1998 20:51:46 GMT
From: spam@whoville.com (Grinch)
Subject: Re: posting to external script within perl
Message-Id: <35d15cf8.256259504@news.shore.net>
On Sun, 9 Aug 1998 22:35:47 -0700, "Dan Bassett" <dan@bns.com> wrote:
>I am trying to find the correct module that will allow me to
>post form input from a script on my server to a script
>located on another server and then read back the results
>of the external script...
>
The LWP module is best for this. The docs for it include examples.
HTH!
-grinch
------------------------------
Date: Mon, 10 Aug 1998 12:05:00 -0700
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: Regex problem
Message-Id: <MPG.1038e43663e7847098975d@nntp.hpl.hp.com>
[Posted to comp.lang.perl.misc and a copy mailed.]
In article <35CF2478.740F613B@hfstud.uio.no> on Mon, 10 Aug 1998 18:48:56
+0200, Lars Erik Kolden <l.e.kolden@hfstud.uio.no> says...
> Larry Rosler wrote:
...
> > As your matches span multiple lines, you do not want to read one line at
> > a time. Use this to get all the input into one string:
> >
> > { local $/; $file = <BODY> }
>
> I guess these are only ordinary statements, and that this is done in the
> while block of the script? (That it is right to match the regex in a while
> loop as I've done).
There is no loop around this 'read' as it reads the whole file into one
string. Whether you then want to loop over the string using various
regexes is up to you.
> ... I know, >> is wrong for substitution, but
> should I use +>? I've seen +>> aswell, but with the same explanation of what
> it does.
'+>' wipes out the file before reading it or writing to it. That is
unlikely to be useful. '+>>' allows you to read the file, but forces all
writes to the end of the file. The mode you may want is '+<'.
But first perhaps you want to look at this FAQ (perlfaq5): "How do I
change one line in a file/delete a line in a file/insert a line in the
middle of a file/append to the beginning of a file?"
--
Larry Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com
------------------------------
Date: Mon, 10 Aug 1998 15:20:08 -0400
From: comdog@computerdog.com (brian d foy)
Subject: Re: Self-printing code
Message-Id: <comdog-ya02408000R1008981520080001@news.panix.com>
Keywords: from just another new york perl hacker
In article <6qnf2p$99i$1@nnrp1.dejanews.com>, Robin Houston <robin.houston@guardian.co.uk> posted:
>Randal Schwartz <merlyn@stonehenge.com> wrote:
>
>> Well, there's the old standby:
>> seek DATA,0,0;print<DATA>__END__
>
>Oh, but that's cheating :-)
>It reads its own source
i suppose Randal could have a useless use of cat...
--
brian d foy <comdog@computerdog.com>
CGI Meta FAQ <URL:http://computerdog.com/CGI_MetaFAQ.html>
Comprehensive Perl Archive Network (CPAN) <URL:http://www.perl.com>
Perl Conference Quiz Show <URL:http://tpj.com/tpj/quiz-show>
------------------------------
Date: Mon, 10 Aug 1998 15:23:16 -0400
From: comdog@computerdog.com (brian d foy)
Subject: Re: Self-printing code
Message-Id: <comdog-ya02408000R1008981523160001@news.panix.com>
Keywords: from just another new york perl hacker
In article <6qnf2p$99i$1@nnrp1.dejanews.com>, Robin Houston <robin.houston@guardian.co.uk> posted:
>Randal Schwartz <merlyn@stonehenge.com> wrote:
>
>> Well, there's the old standby:
>> seek DATA,0,0;print<DATA>__END__
>
>Oh, but that's cheating :-)
>It reads its own source
okay, let's see if i can trigger Randal's Cat Detector(tm)
#!/usr/bin/perl
system '/bin/cat', $0;
__END__
but that isn't interesting. how about a program to post it's own
source to alt.sources or whatever ;)
--
brian d foy <comdog@computerdog.com>
CGI Meta FAQ <URL:http://computerdog.com/CGI_MetaFAQ.html>
Comprehensive Perl Archive Network (CPAN) <URL:http://www.perl.com>
Perl Conference Quiz Show <URL:http://tpj.com/tpj/quiz-show>
------------------------------
Date: Mon, 10 Aug 1998 21:21:39 +0200
From: Michael Agbaglo <byteshifter@shifted-bytes.de>
Subject: socket: read on close filehandle ???
Message-Id: <35CF4843.155EFE19@shifted-bytes.de>
This is a multi-part message in MIME format.
--------------6212C57626F51740D94A619D
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
Read on closed filehandle <S> at ./x line 8.
ooops ... !
--------------6212C57626F51740D94A619D
Content-Type: text/plain; charset=us-ascii;
name="x"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
filename="x"
#!/usr/bin/perl -w
require 5.002;
use IO::Socket;
$S = IO::Socket::INET->new('localhost:25') or die "can't connect to socket";
print while(<S>);
close $S or die "close $!";
exit;
--------------6212C57626F51740D94A619D--
------------------------------
Date: 10 Aug 1998 20:10:17 GMT
From: cberry@cinenet.net (Craig Berry)
Subject: Re: strings
Message-Id: <6qnk39$508$1@marina.cinenet.net>
Mark-Jason Dominus (mjd@op.net) wrote:
: In article <6qkuer$q49$2@marina.cinenet.net>,
: Craig Berry <cberry@cinenet.net> wrote:
: > Seems a silly way to have implemented things,
:
: It seems to me that it's exactly the same as this:
:
: while (<DATA>) {
: print $_+1, "\n";
: }
:
: __DATA__
: 077
:
: ... which prints `78', and not `0100'.
:
: Code and data aren't the same thing.
I guess my time in the Lisp world made me question that assumption. :)
Seriously, I think it's a reasonable goal that, where possible, code and
data *should* use the same formats and conventions. And, indeed, I've
often wished that 077 and 0xCA in input data would parse as octal and hex
respectively.
: Anyway, the underscores weren't allowed in literal constants until
: recently, but changing the way string-to-number conversions are
: performed in data would have broken many programs.
That's the stronger argument, of course, though it's sad how every
language and OS become gradually encumbered by the weight of past
practice. Then again, I suppose that's (one reason) why new languages and
OSs appear from time to time.
---------------------------------------------------------------------
| Craig Berry - cberry@cinenet.net
--*-- Home Page: http://www.cinenet.net/users/cberry/home.html
| Member of The HTML Writers Guild: http://www.hwg.org/
"Every man and every woman is a star."
------------------------------
Date: 10 Aug 1998 20:12:52 GMT
From: cberry@cinenet.net (Craig Berry)
Subject: Re: Test Results - Asking a question
Message-Id: <6qnk84$508$2@marina.cinenet.net>
John Porter (jdporter@min.net) wrote:
: Ronald J Kimball wrote:
: > So, if you've looked for an answer in the manual and the FAQ,
: > be sure to mention it when you ask your question!
:
: I *would* gripe about giving away this secret to the unwashed
: masses; after all, you only *claimed* to have read the docs;
: you didn't give any evidence that you actually *had*.
At least until some postulated future time when most people claim to have
read the docs, that claim will make a valid pre-filter for good intent.
---------------------------------------------------------------------
| Craig Berry - cberry@cinenet.net
--*-- Home Page: http://www.cinenet.net/users/cberry/home.html
| Member of The HTML Writers Guild: http://www.hwg.org/
"Every man and every woman is a star."
------------------------------
Date: 10 Aug 1998 13:29:03 -0500
From: nem@abattoir.cc.ndsu.nodak.edu (Nem W Schlecht)
Subject: Re: variable indirection [off topic - parens]
Message-Id: <6qne5f$bsg@abattoir.cc.ndsu.nodak.edu>
[courtesy copy e-mailed to author(s)]
In comp.lang.perl.misc, John Porter <jdporter@min.net> wrote:
>Nem W Schlecht wrote:
>>
>> The above, non-paren statement, should be written as:
>> my($foo) = scalar @bar;
>
>"should be"???
>I'm not sure you're qualified to be pontificating.
Next time I try to express my personal opinions, I'll make sure to
explicitly classify them all as such so you don't think I'm trying to
re-write the perl manual or the 10 commandments, which I'm not trying to
do.
(ie. I think you're being a little harsh with me. I merely tried to have a
decent discussion on a certain topic. I do fully agree with you that I
should have used better grammar in making my statements, but at the same
time, I did not think that anybody would have taken my statements as an
authoritative source.)
>If you really think parens are so important and non-optional
>(stylistically speaking), then you should have at least said
> scalar( @bar )
You are correct, sir. I rarely use the scalar() call, and when I do it is
usually with localtime(), where I do skip the parens.
my($foo) = scalar(@bar);
>But worse than that, you are promoting a style of
>assignment like this:
> ( $x ) = $y;
>Which is certainly in a class with
> @z = $y;
Not at all. When calling my(), a *function*, I think you should put your
arguments in parens, just like you have to when you call your own function
that you've written or like you always have to when you program in C. I'm
not promoting putting parens around *all* of your variables. Ack!
(Note: I am also not promoting C over perl!)
>If you would write
> $foo = scalar( @bar );
>then you would also write
> my $foo = scalar( @bar );
>because the semantics are identical -- except for the
>effect of 'my' on the scope of $foo, obviously.
I agree, that in perl, the semantics of the above are identical. Again, my
view is not from a variable perspective, but from a function calling
perspective.
--
Nem W Schlecht nem@plains.nodak.edu
NDUS UNIX SysAdmin http://www.nodak.edu/~nem/
"Perl did the magic. I just waved the wand."
------------------------------
Date: Mon, 10 Aug 1998 15:18:44 -0400
From: John Porter <jdporter@min.net>
Subject: Re: variable indirection [off topic - parens]
Message-Id: <35CF4794.415F@min.net>
Nem W Schlecht wrote:
>
> Next time I try to express my personal opinions, I'll make sure to
Sorry. One should always mentally preprocess each message with
s/,/, IMHO,/g
which I forgot to do.
> I rarely use the scalar() call, and when I do it is
> usually with localtime(), where I do skip the parens.
> >But worse than that, you are promoting a style of
> >assignment like this:
> > ( $x ) = $y;
> >Which is certainly in a class with
> > @z = $y;
>
> Not at all. When calling my(), a *function*,...
No. 'my' is no more a "function" than 'scalar', and you yourself
admit that calling 'scalar' without parens is acceptable, and
even preferable sometimes. You can cut 'my' the same slack.
> ...I think you should put your
> arguments in parens, just like you have to when you call your own function
> that you've written or like you always have to when you program in C.
As long as you still have the aesthetics of a C programmer, you'll
continue to do this, I guess. Parens are required in C, not in
Perl. Don't code Perl as though they are required. Omit parens when
they are better omitted. And, all other things being equal,
follow the semantics of Perl.
( $x ) = $y;
is Bad.*
So
my( $x ) = $y;
is Equally Bad. The "function"-ness of 'my' is utterly
subordinate to the semantics of list/scalar assignment.
btw, parens aren't always necessary on user-defined subs.
That's one of the effects of using prototypes.
sub foo($$) { print join(',',@_),"\n" }
foo 'bar', 42;
hand,
John Porter
*When I say 'Bad', I don't mean that it won't run as expected.
------------------------------
Date: 10 Aug 1998 15:39:21 -0400
From: mjd@op.net (Mark-Jason Dominus)
Subject: Re: variable interpolation
Message-Id: <6qni99$odp$1@monet.op.net>
Keywords: perl cgi variable
In article <6qn6od$83e$2@engnews2.Eng.Sun.COM>,
Brian Day <bday@cbr.eng.sun.com> wrote:
>Does anyone know if there is a way to have a variable name
>interpolated inside another variable name ? i.e.:
>
>tally(sandwich);
>tally(drink);
>
>print "$sandwich_count";
>print "$drink_count";
That is almost always a bad move. It is much better to do it like this:
print "$count{sandwich}";
print "$count{drink}";
sub tally {
$count{$_[0]}++;
}
The first on the long list of benefits is that you can get a list of
the items you counted by doing
@items = keys %count;
You can also automate access to the counts much more easily than if
you did it your way:
foreach $item (keys %count) {
print "\u$item: $count{$item}\n";
}
# Prints something like this:
# Drink: 4
# Sandwich: 2
# Ice cream: 5
# Loose Meat: 11
You may also want to see my article at
http://www.plover.com/~mjd/perl/varvarname.html
for an anecdote about how this is a bad move.
------------------------------
Date: 10 Aug 1998 20:50:05 GMT
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: Re: variable interpolation
Message-Id: <6qnmdt$5ip$1@csnews.cs.colorado.edu>
Keywords: perl cgi variable
[courtesy cc of this posting sent to cited author via email]
In comp.lang.perl.misc, bday@cbr.eng.sun.com writes:
:Does anyone know if there is a way to have a variable name interpolated inside
:another variable name ? i.e.:
While symbolic references are possible, they suffer the following
disadvantages:
* They do not work under the use strict pragma
* They only work on global variables. Yup, read that one again.
* They are not true references and consequently are not reference
counted or garbage collected.
The frequency with which this question is asked bespeaks an underlying
misunderstanding of the hash data structure in Perl, which was designed
for this very thing. Please see my posting on "variable indirection"
from last Friday about this.
In short: what you're wanting to do is not best solved in Perl the
way you want to do it. See the following posting for why it's
stupid.
--tom
Date: 10 Jun 1998 21:17:20 -0400
>From: mjd@op.net (Mark-Jason Dominus)
Subject: Why it's stupid to `use a variable as a variable name'
Organization: Plover Systems
Newsgroups: comp.lang.perl.misc,comp.programming
Article: 147110 of comp.lang.perl.misc
Summary: Name conflicts
Keywords: erasable mantissa mock wristwatch
X-Motto: Now Available in Thrilling `PloverVision!'
X-Subliminal-Catchphrase: ``Growling Fungus''
People show up in comp.lang.perl.misc all the time asking how to use
the contents of a variable as the name of another variable. For
example, they have $foo = 'snonk', and then they want to operate on
the value of $snonk.
That's very easy to do in Perl, so they usually get some people to
tell them to do it. And they usually get some people asking them why
they didn't use a hash instead. Sometimes I'm one of the people who
says to use a hash instead, and sometimes I'm one of the people who
answers the question that was asked, even though I think they should
be using a hash instead.
Anyway, a couple of weeks ago one of my clients called up with some
program that was producing wrong reports. They needed it to be fixed
by the following day. The program was going to read a database with
records like these:
this red something
that green something else
other red more
this blue still more
and build a report of how many records had each value in each
position.
It turned out that the clods who had written this program had done
something like this:
while (<RECORDS>) {
chomp;
@values = split /\t/, $_;
foreach $v (@values) {
$$v++;
}
}
print <<EOM;
Question 1:
$this users said `this'. $that users said `that'.
Question 2:
$red users said their favorite color was red.
... (and so on ) ...
EOM
Of course, the actual code was much longer and much more obfuscated.
Anyway, to make a long story short, the problem turned out to be that
there was a certain response, let's say `foo', (actually, it was
`digoxin'---go figure) which was a valid response for two totally
unrelated questions, say #7a and #11. So anyone answering `foo' to
question 7a would be counted as having answered `foo' to question 11
as well, and vice versa. At the end of the analysis, the $foo
variable contained the *sum* of all the users who answered `foo' to
either question 7a or to question 11. Then the reports used this sum
in two places, and that's why the reports were inaccurate.
This shoddy logic was so pervasive in the program that I couldn't find
an easy way to fix it. If the original programmers had used a series
of hashes instead of stuffing everything into a bunch of global
variables, it would never have happened, or at worst it would have
been easy to fix. I ended up doing a major overhaul on the program to
solve the problem. The main loop turned into something more like:
while (<RECORDS>) {
chomp;
@values = split /\t/, $_;
for ($i=1; $i <= $NUMQUESTIONS; $i++)
my $v = shift @values;
$count[$i]{$v}++
}
}
Of course, the actual code was much longer and much more obfuscated,
although it was nither as long nor as obfuscated as when I got to work
on it.
I shudder to think what would have happened to this program if one of
the responses had been named `i' or `v' or `3' or some such. One can
even imagine that that happened once upon a time, and the reponse was
to change the name instead of taking the warning.
Anyway, deriving the name of the variable from an input value turned
out to be a very stupid decision in this case, and one which cost my
client a couple of thousand dollars.
When people come into comp.lang.perl.misc asking how to do something
stupid, I'm never quite sure what to do. I can just answer the
question as asked, figuring that it's not my problem to tell people
that they're being stupid. That's in my self-interest, because it
takes less time to answer the question that way, and because someone
might someday pay me to clean up after their stupidity, as happened in
this instance. But if I do that, people might jump on me for being a
smart aleck, which has happened at times. (``Come on, help the poor
guy out; if you know what he really need why don't you just give it to
him?'')
On the other hand, I could try to answer on a different level, present
a better solution, and maybe slap a little education on `em. That's
nice when it works, but if it doesn't it's really sad to see your hard
work and good advice ignored. Also, people tend to jump on you for
not answering the question. (``Who are you to be telling this guy
what he should be doing? Just answer the question.'')
I guess there's room for both kinds of answer. Or maybe there isn't
room for either kind.
Whatever. I seem to have gone off on a tangent. The real root of the
problem code is: It's fragile. You're mingling unlike things when you
do this. And of two of those unlike things happen to have the same
name, they'll collide and you'll get the wrong answer. So you end up
having a whole long list of names which you have to be careful not to
reuse, and if you screw up, you get a very bizarre error. This is
precisely the problem that namespaces were invented to solve, and
that's just what a hash is: A portable namespace.
The main point of this article was to present a real example of a case
where using a variable as a variable name was a really stupid thing to do.
Since most of the people who post about that in comp.lang.perl.misc seem
to be trying to do the same stupid thing in the same stupid way, I thought
I'd mention it, and maybe raise the general awareness of this problem.
--
"The road to hell is paved with melting snowballs."
--Larry Wall in <1992Jul2.222039.26476@netlabs.com>
------------------------------
Date: 10 Aug 1998 19:27:38 GMT
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: Re: What is the purpose of Perl
Message-Id: <6qnhja$24q$1@csnews.cs.colorado.edu>
[courtesy cc of this posting sent to cited author via email]
In comp.lang.perl.misc,
fl_aggie@thepentagon.com (I R A Aggie) writes:
:+ It has mapped the universe and created an exact duplicate.
:%universe_2 = %universe;
Goodness, wouldn't it be easier to just fork? No data copying. :-)
--tom
--
X-Windows: There's got to be a better way.
--Jamie Zawinski
------------------------------
Date: Mon, 10 Aug 1998 16:53:48 -0400
From: John Porter <jdporter@min.net>
Subject: Re: What is the purpose of Perl
Message-Id: <35CF5DDC.6DF4@min.net>
Tom Christiansen wrote:
>
> fl_aggie@thepentagon.com (I R A Aggie) writes:
> :+ It has mapped the universe and created an exact duplicate.
> :%universe_2 = %universe;
>
> Goodness, wouldn't it be easier to just fork? No data copying. :-)
Yeah, that more accurately reflects what really happens, too
(according to many-universes theories, at least).
--
John Porter
------------------------------
Date: Mon, 10 Aug 1998 20:41:43 GMT
From: areeves1@csc.com (Anthony Reeves)
Subject: what is this stuff?
Message-Id: <35cf5a13.9334992@news.es.hac.com>
Hi, I'm reading a file that is produced by a different process.
when I read the file, its got these weird chacters I cannot figure out
how to get rid of..
here is the line that is read and displayed during a debug session:
X line
line = "Time\cIAmt\cIJob\cJ"
the \cI \cJ
I want to remove, I thought they might be something like a control
char. so I tryed \033I
did not work, try \eI
did not work..
any ideas ? Anyone seen this?
------------------------------
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 3408
**************************************