[10749] in Perl-Users-Digest
Perl-Users Digest, Issue: 4348 Volume: 8
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Dec 3 02:07:15 1998
Date: Wed, 2 Dec 98 23:00:15 -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 Wed, 2 Dec 1998 Volume: 8 Number: 4348
Today's topics:
Re: $! type variables <ajohnson@gatewest.net>
Re: Comparing lines from 2 different files? <ebohlman@netcom.com>
PC to Unix Problem oleynikl@geocities.com
Re: PC to Unix Problem (Martien Verbruggen)
Re: PC to Unix Problem <rick.delaney@shaw.wave.ca>
Re: Perl for old, outdated, ancient systems <snif@xs4all.no.spam.nl>
Perl Socket problems.. <davidjan@mtu.edu>
Re: Perl Socket problems.. (Martien Verbruggen)
Re: pos function - How do you manipulate it? (Martien Verbruggen)
Re: pos function - How do you manipulate it? <rick.delaney@shaw.wave.ca>
Re: Reading a text file & putting into variables <john_z@hotmail.com>
Re: Sorting VERY large files effeciently <Savage.Ron.RS@bhp.com.au>
Re: Sorting VERY large files effeciently <uri@sysarch.com>
Re: system() executes at unexpected time in SunOS4, Per (Mark-Jason Dominus)
TIESCALAR: Is this a bug? (Sean McAfee)
Re: When does CLOSE not FLUSH? <rra@stanford.edu>
Re: Why is "... @foo ..." occasionally a syntax error? (Mark Dominus)
Special: Digest Administrivia (Last modified: 12 Mar 98 (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Wed, 02 Dec 1998 21:57:22 -0600
From: Andrew Johnson <ajohnson@gatewest.net>
Subject: Re: $! type variables
Message-Id: <36660C22.1933157B@gatewest.net>
Gregory Snow wrote:
>
> I remember reading somewhere how to make variables like $!, that
> return different values in string context and numeric context. I've
> spent the last hour pouring through the docs and faq but have not
> found it (and DejaNews won't search for $! and other searches have
> been useless). Can anyone point me to the correct doc or post?
there is a 'builtin.pm' module somewhere on CPAN with
a dualvar() function that will do what you want, the
docs for this module describes the function thusly:
dualvar NUMERIC, STRING
Returns a new scalar variable which will act in a
similar way to the $! variable. The value of this new
variable will be the numerical value of NUMERIC in a
numeric context and the string value of STRING in a
string context.
$foo = dualvar 10, "Hello";
$num = $foo + 2; # 12
$str = $foo . " world"; # Hello world
hope it helps
regards
andrew
------------------------------
Date: Thu, 3 Dec 1998 05:02:42 GMT
From: Eric Bohlman <ebohlman@netcom.com>
Subject: Re: Comparing lines from 2 different files?
Message-Id: <ebohlmanF3DI0I.38J@netcom.com>
Bryce Pursley <hbpursle@duke-energy.com> wrote:
: I may have answered my own question. I added a "last;" statement at
: the end of the second loop after the match line and it appears to be
: doing what I want. I'll keep testing and I would still appreciate
: suggestions if you see something I'm doing that could be done better.
You've still got a major problem. If there are no lines in your second
file that match a line in your first file, you'll read all the way to the
end of the second file and when you get the next line from the first file,
you'll have nothing to match it against because you only move forward in
the second file. Unless you can guarantee that
1) every line in the first file matches at least one line in the second
file and
2) if line B comes after line A in the first file, then all the lines in
the second file that match line B come after all the lines that match
line A
you're going to have to "rewind" to the top of the second file each time
you read a new line from the first file. You might want to look up the
seek() function which will do that.
However, reading through, on average, half of the second file for every
line in the first file is one of those algorithms that "gets very slow
very fast." If each file had a thousand lines, you'd have to read, on
average, half a million lines from the second file.
Fortunately, Perl itself comes to your rescue with its hash facilities.
If you read the lines of the second file into a hash, with the keys being
the parts of the lines you want to match on and the values being the
parts of the lines you want to retrieve (they might be the whole lines),
then you can do your matching *very* quickly: read a line from the first
file, extract the part you want to match on, look it up in the hash and
process the value if it exists.
------------------------------
Date: Thu, 03 Dec 1998 02:55:41 GMT
From: oleynikl@geocities.com
Subject: PC to Unix Problem
Message-Id: <744ujd$t4u$1@nnrp1.dejanews.com>
I've been learning Perl 5.0 for 2 days now. I'm trying to use Perl to solve a
problem. Whenever I create an ascii file in a PC environment and upload it to
a UNIX account, what I get is newline characters appearing everywhere. (ie: I
get ^M in vi and <cr> in nedit).
I wrote this short Perl program hoping to rid the newline characters, but it
doesn't seem to work.
#!/usr/bin/perl -w
$^I = '.old'; # backup file
while(<>) {
s/^\s/ /g; # replace newlines,etc. with a single space
print; # write to file
}
Thank you for any suggestions.
William
-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/ Search, Read, Discuss, or Start Your Own
------------------------------
Date: Thu, 03 Dec 1998 03:28:25 GMT
From: mgjv@comdyn.com.au (Martien Verbruggen)
Subject: Re: PC to Unix Problem
Message-Id: <tzn92.90$Fw3.227@nsw.nnrp.telstra.net>
In article <744ujd$t4u$1@nnrp1.dejanews.com>,
oleynikl@geocities.com writes:
> I've been learning Perl 5.0 for 2 days now. I'm trying to use Perl
> to solve a problem. Whenever I create an ascii file in a PC
Noble, but unneccesary in this case.
> environment and upload it to a UNIX account, what I get is newline
> characters appearing everywhere. (ie: I get ^M in vi and <cr> in
> nedit).
Perl scripts are text files. Text files can be different on many
platforms Long ago, when someone came up with FTP, they recognised
this as a possible problem. That is why they made it possible for
people to transfer files in binary or ascii mode. The first just
copies byte by byte. The second translates the various text file
formats while copying.
That's what you need.
Somewhere in the faq there is some blurb about all this.
Martien
--
Martien Verbruggen |
Webmaster www.tradingpost.com.au | A Freudian slip is when you say one
Commercial Dynamics Pty. Ltd. | thing but mean your mother.
NSW, Australia |
------------------------------
Date: Thu, 03 Dec 1998 03:31:00 GMT
From: Rick Delaney <rick.delaney@shaw.wave.ca>
Subject: Re: PC to Unix Problem
Message-Id: <366607AB.66BC4635@shaw.wave.ca>
[posted & mailed]
oleynikl@geocities.com wrote:
>
> Whenever I create an ascii file in a PC environment and upload it to
> a UNIX account, what I get is newline characters appearing everywhere.
> (ie: I get ^M in vi and <cr> in nedit).
The undesirable characters are carriage returns. You want to keep the
newlines.
>
> I wrote this short Perl program hoping to rid the newline characters,
> but it doesn't seem to work.
>
> #!/usr/bin/perl -w
> $^I = '.old'; # backup file
> while(<>) {
> s/^\s/ /g; # replace newlines,etc. with a single space
Yikes, that replaces a single leading whitespace character with a single
space.
perldoc perlre
Here is one way to do it that doesn't use a regex:
tr/\r//d;
A better way would be to use FTP to upload your scripts. Set transfer
mode to ascii, not binary.
--
Rick Delaney
rick.delaney@shaw.wave.ca
------------------------------
Date: Thu, 3 Dec 1998 07:43:09 +0100
From: "Sander Jonkers" <snif@xs4all.no.spam.nl>
Subject: Re: Perl for old, outdated, ancient systems
Message-Id: <745bte$lt8$1@news.gns.getronics.nl>
Bart Lateur wrote in message <3665a8e2.2940684@news.skynet.be>...
<snip>
>To actually RUN Perl scripts, I'd advice you to get the PFE editor
>(free; <http://pfe.iquill.net/>).
I think that should be http://www.lancs.ac.uk/people/cpaap/pfe/
Sander
------------------------------
Date: 3 Dec 1998 04:31:10 GMT
From: David J. Anderson <davidjan@mtu.edu>
Subject: Perl Socket problems..
Message-Id: <74546e$6if$1@campus1.mtu.edu>
Ok. I haven't programmed perl in awhile, decided to see if I could get
sockets/networking stuff to work out, and so far it's been a disaster.
All I want is a "server" module to start on our computers, and it
would wait for input from a "client" module on another computer. The
client module would just open up the same port the server module would
open up & transmit the data. I basically got the program from a book I
have.. but can't even get it to work.
The server starts up fine, seems to work, but when I try to run the
client on the same computer or another (used -w option for more info
on errors), it says:
Attempting to reach foreign socket now
IO::Socket::INET: Bad peer address at client line 5
Socket could not be created. Reason: Bad file number
I've tried changing the peer address all I could, I guess I'm either
being dumb or there's a misprint in the book or Something *sigh*
Anyways, if anyone has any ideas, an e-mail would be great...
************
Here is the Client Code:
#!/usr/local/bin/perl
use IO::Socket;
print "Attempting to reach foreign socket now\n";
$sock = new IO::Socket::INET (PeerHost => 'colossus.csl',
PeerPort => 2169,
Proto => 'tcp',
);
die "Socket could not be created. Reason: $!\n" unless $sock;
print "Preparing to send data\n";
foreach (1 .. 10) {
print $sock "Msg $_: How are you? \n";
}
close ($sock);
*************
For the heck of it, here's the Server Code:
#!/usr/local/bin/perl
use IO::Socket;
print "Grabbing Socket Now...\n";
$sock = new IO::Socket::INET (LocalHost => 'colossus.csl.mtu.edu',
LocalPort => 2169,
Proto => 'tcp',
Listen => 5,
Reuse => 1
);
die "Socket could not be created. Reason: $!" unless $sock;
print "Preparing for sent data\n";
while ($new_sock = $sock->accept()) {
while (defined ($buff = <$new_sock>)) {
print $buff;
print "\n";
}
}
close ($sock);
--
\\\|///
\\ - - //
( @ @ )
+--------------------oOOo-(_)-oOOo----------------------+
| David J. Anderson @ Michigan Tech...I think %-} |
| Computer Science Major |
| Web page: http://www.csl.mtu.edu/~davidjan |
+----------------------------Oooo-----------------------+
oooO ( )
( ) ) /
\ ( (_/
\_)
------------------------------
Date: Thu, 03 Dec 1998 04:48:12 GMT
From: mgjv@comdyn.com.au (Martien Verbruggen)
Subject: Re: Perl Socket problems..
Message-Id: <gKo92.108$Fw3.227@nsw.nnrp.telstra.net>
In article <74546e$6if$1@campus1.mtu.edu>,
David J. Anderson <davidjan@mtu.edu> writes:
> $sock = new IO::Socket::INET (PeerHost => 'colossus.csl',
> PeerPort => 2169,
> Proto => 'tcp',
> );
Hmm.. My copy of the IO::Socket documentation doesn't mention a
PeerHost option. Did you mean PeerAddr?
# perldoc IO::Socket
[snip]
SUB-CLASSES
IO::Socket::INET
IO::Socket::INET provides a constructor to create an AF_INET
domain socket and some related methods. The constructor can
take the following options
PeerAddr Remote host address <hostname>[:<port>]
PeerPort Remote port or service <service>[(<no>)] | <no>
LocalAddr Local host bind address hostname[:port]
LocalPort Local host bind port <service>[(<no>)] | <no>
Proto Protocol name (or number) "tcp" | "udp" | ...
Type Socket type SOCK_STREAM | SOCK_DGRAM | ...
Listen Queue size for listen
Reuse Set SO_REUSEADDR before binding
Timeout Timeout value for various operations
Martien
--
Martien Verbruggen |
Webmaster www.tradingpost.com.au |
Commercial Dynamics Pty. Ltd. | What's another word for Thesaurus?
NSW, Australia |
------------------------------
Date: Thu, 03 Dec 1998 03:25:03 GMT
From: mgjv@comdyn.com.au (Martien Verbruggen)
Subject: Re: pos function - How do you manipulate it?
Message-Id: <jwn92.88$Fw3.227@nsw.nnrp.telstra.net>
In article <366af390.1149121379@news.infoave.net>,
hbpursle@duke-energy.com (Bryce Pursley) writes:
> Guys (and gals),
> Please tell me where else to look or how to do this.
>
> The perlfunc.htm says:
>
> "pos SCALAR
> Returns the offset of where the last m//g search left off for the
> variable in question. May be modified to change that offset. "
Your version of the documentation seems a bit out of date or something:
# perldoc -f pos
=item pos SCALAR
=item pos
Returns the offset of where the last C<m//g> search left off for the variable
is in question (C<$_> is used when the variable is not specified). May be
modified to change that offset. Such modification will also influence
the C<\G> zero-width assertion in regular expressions. See L<perlre> and
L<perlop>.
# perldoc perlop
[snip]
In scalar context, each execution of m//g finds the
next match, returning TRUE if it matches, and FALSE
if there is no further match. The position after
the last match can be read or set using the pos()
function; see the pos entry in the perlfunc manpage.
[snip]
(a little further some exampes on how to read this)
# perldoc perlre
[snip]
It is also useful when writing lex-like scanners, when you
have several patterns that you want to match against
consequent substrings of your string, see the previous
reference. The actual location where \G will match can also
be influenced by using pos() as an lvalue. See the pos
entry in the perlfunc manpage.
[snip]
Illustration:
> perl
$_ = "abcde";
while (m/./g)
{
print "$& - ", pos, "\n";
}
print "--\n";
while (m/./g)
{
print "$& - ", pos, "\n";
pos() += 2 if (pos == 2);
}
__END__
a - 1
b - 2
c - 3
d - 4
e - 5
--
a - 1
b - 2
e - 5
Martien
--
Martien Verbruggen |
Webmaster www.tradingpost.com.au | Begin at the beginning and go on till
Commercial Dynamics Pty. Ltd. | you come to the end; then stop.
NSW, Australia |
------------------------------
Date: Thu, 03 Dec 1998 03:41:13 GMT
From: Rick Delaney <rick.delaney@shaw.wave.ca>
Subject: Re: pos function - How do you manipulate it?
Message-Id: <36660A0D.C84D1067@shaw.wave.ca>
[posted & mailed]
Bryce Pursley wrote:
>
> Guys (and gals),
> Please tell me where else to look or how to do this.
>
> The perlfunc.htm says:
>
> "pos SCALAR
> Returns the offset of where the last m//g search left off for the
> variable in question. May be modified to change that offset. "
>
> But I can't figure out how to get it's value or set it's value or,
> more importantly right now, reset it to the top of the file.
^^^^^^^^
I think you're confusing pos()'s purpose. You can change the position
of the offset in the *string* you are matching.
#!/usr/local/bin/perl -w
$\ = "\n";
$_ = 'abcdeabcdabcdeabc';
m/bc/g;
print pos;
pos() = 2;
m/cd/g;
print pos;
__END__
3
4
--
Rick Delaney
rick.delaney@shaw.wave.ca
------------------------------
Date: Wed, 2 Dec 1998 23:07:31 -0500
From: "John Zeng" <john_z@hotmail.com>
Subject: Re: Reading a text file & putting into variables
Message-Id: <7452s3$6q6$1@ash.prod.itd.earthlink.net>
All i need is how do I set each e-mail address in a text file into a
variable in a Perl script..
TEXT FILE---->>>>
email@host.com; email@host.isp; addy@isp.net; webmaster@worldwideweb.www;
<<<<----end
those email addresses are in a seperate text file... h0w d0 i refer to each
of them in the script :::
for example (part of the script)....
open (LIST, "<$Listofppl");
$umask = umask(0);
open (TMP, ">$TempFile");
umask($umask); ### i dont know what this does
while(<LIST>)
{
chop;
print TMP "$_ ";
($tname, $tpass) = split(':');
$tapass{$tname} = $tpass;
}
close(LIST);
# unless($tapass{$webmaster2}) ## not sure what this does
if($webmaster ne ????)
### what goes in ????
{
................etc..etc..etc..
thx in advance to those who can help me out
------------------------------
Date: Thu, 3 Dec 1998 15:44:14 +1100
From: "Ron Savage" <Savage.Ron.RS@bhp.com.au>
Subject: Re: Sorting VERY large files effeciently
Message-Id: <7454tj$ck11@atbhp.corpmel.bhp.com.au>
Using Perl I would write what's called a 'tag sort'. See any good sort
reference.
Basically you read and sort the keys only, remembering which record they can
from.
After the sort you read the data attached to the keys and write it in sorted
order.
--
Ron Savage
Home (preferred): rpsavage@ozemail.com.au
Office: Savage.Ron.RS@bhp.com.au
http://www.ozemail.com.au/~rpsavage
andy-markham@mindspring.com wrote in message
<743nft$q1u$1@nnrp1.dejanews.com>...
>I have recently started working with a group that does some work on an
>HP3000. Since there is a 4GB limit on that machine, they have to find a new
>way to do some effecient sorting of data files that exceed that limit. They
>have been looking at a couple of packages on HPUX to do the job, CoSORT
>(~$2K) and something else that is on the order of $20K. It turns out that
>CoSORT can't handle it, so they are thinking about writing a $20K check to
>solve the problem.
>
>My first thought is, can't Perl be used to sort a really large flat file in
>an effecient manner? Hell, Perl can do everything else I've ever asked it
to
>do...
>
>I don't plan on writing and testing out a bunch of sort routines, so
>basically I'm hoping that someone on this group has already tackled this
>problem and has a really good response. I'd really like for us to find a
>solution in Perl, but if we end up having to write the check, so be it.
>
>So, is Perl up to the task? Please say YES!
>
>- Andy (andy-markham@mindspring.com)
>
>-----------== Posted via Deja News, The Discussion Network ==----------
>http://www.dejanews.com/ Search, Read, Discuss, or Start Your Own
------------------------------
Date: 03 Dec 1998 01:29:13 -0500
From: Uri Guttman <uri@sysarch.com>
Subject: Re: Sorting VERY large files effeciently
Message-Id: <x767btyc06.fsf@sysarch.com>
>>>>> "RS" == Ron Savage <Savage.Ron.RS@bhp.com.au> writes:
RS> Using Perl I would write what's called a 'tag sort'. See any good
RS> sort reference. Basically you read and sort the keys only,
RS> remembering which record they can from. After the sort you read
RS> the data attached to the keys and write it in sorted order.
what if the number (and size) of keys is still too big to fit into
virtual memory?
this will work for ANY size of database provided you have external
storage to hold the temp files.
does anyone else remember tape sorts? you read a mess of records into
ram (only enough to fill memory) and do a quicksort. you write out that
sorted block of records to a tape (or disk file today). you repeat until
all the records are in sorted blocks. then you do merges of the sorted
blocks which is very efficient. believe it or not, the fibonacci series
comes into play as you determine the optimal number of sort blocks and
tapes to make and merges to be done with them. i learned this over 20
years ago from ron rivest (of RSA fame). it still the best algorithm
for very large sorts when you have more data than fits into ram.
i bet syncsort uses this algorithm for their largest sorts.
uri
--
Uri Guttman ----------------- SYStems ARCHitecture and Software Engineering
Perl Hacker for Hire ---------------------- Perl, Internet, UNIX Consulting
uri@sysarch.com ------------------------------------ http://www.sysarch.com
The Best Search Engine on the Net ------------- http://www.northernlight.com
------------------------------
Date: 2 Dec 1998 22:15:14 -0500
From: mjd@op.net (Mark-Jason Dominus)
Subject: Re: system() executes at unexpected time in SunOS4, Perl5, seems to fork early
Message-Id: <744vo2$om9$1@monet.op.net>
My article about buffering at
http://www.plover.com/~mjd/perl/FAQs/
discusses this exact problem.
------------------------------
Date: Thu, 03 Dec 1998 06:28:09 GMT
From: mcafee@waits.facilities.med.umich.edu (Sean McAfee)
Subject: TIESCALAR: Is this a bug?
Message-Id: <Zbq92.2387$CY1.9626630@news.itd.umich.edu>
sub TIESCALAR { bless \my $x }
sub FETCH { sub { print "foo\n" } }
tie $x, 'main';
&$x;
The above code fails with this error message:
Can't use an undefined value as a subroutine reference at ...
However, if any code which uses $x's value in a nontrivial way is inserted
between the tie and the function call, the code works as one would expect.
Examples:
defined($x);
$x + 0;
$x * 3;
$x << 4;
Any of the above lines make the code work when put before the function
call. A simple "$x;" does NOT remove the error message.
This behavior seems bizarre, at the very least. Is there a good reason
for it that I don't see?
--
Sean McAfee | GS d->-- s+++: a26 C++ US+++$ P+++ L++ E- W+ N++ |
| K w--- O? M V-- PS+ PE Y+ PGP?>++ t+() 5++ X+ R+ | mcafee@
| tv+ b++ DI++ D+ G e++>++++ h- r y+>++** | umich.edu
------------------------------
Date: 02 Dec 1998 19:01:01 -0800
From: Russ Allbery <rra@stanford.edu>
Subject: Re: When does CLOSE not FLUSH?
Message-Id: <ylsoey2aky.fsf@windlord.stanford.edu>
Bart Lateur <bart.lateur@skynet.be> writes:
> Russ Allbery wrote:
>> No. That's the whole point of O_APPEND. O_APPEND does an implicit
>> seek to end of file *before every write to the file*. So it doesn't
>> matter if the file changes after you opened it; if you opened it with
>> O_APPEND, you'll still be writing to the current end of the file.
> I'd like to believe that. Could anybody provide a code snippet that
> would irrefutably prove that?
Well, someone else posted one, and it's pretty clearly documented in the
man page.
Note that it does the seek before every *write*, and that's a write(2).
What that means is that if you're writing to a file you opened with
O_APPEND, and you're using buffering (stdio), which is what you get by
default with Perl's open, then it's possible that any given print to that
file will be broken up into more than one write(2) call. Particularly if
it contains multiple lines or is long. That means that if you have two
simultaneous writers, it's still possible for their data to be intermixed
although each will write to the end of the file when it does its write.
--
#!/usr/bin/perl -- Russ Allbery, Just Another Perl Hacker
$^=q;@!>~|{>krw>yn{u<$$<[~||<Juukn{=,<S~|}<Jwx}qn{<Yn{u<Qjltn{ > 0gFzD gD,
00Fz, 0,,( 0hF 0g)F/=, 0> "L$/GEIFewe{,$/ 0C$~> "@=,m,|,(e 0.), 01,pnn,y{
rw} >;,$0=q,$,,($_=$^)=~y,$/ C-~><@=\n\r,-~$:-u/ #y,d,s,(\$.),$1,gee,print
------------------------------
Date: 2 Dec 1998 22:04:31 -0500
From: mjd@plover.com (Mark Dominus)
Subject: Re: Why is "... @foo ..." occasionally a syntax error?
Message-Id: <744v3v$olh$1@monet.op.net>
In article <36656B5E.BA3F79E4@eddie.mit.edu>,
John Chambers <jc@eddie.mit.edu> wrote:
>Hmmm ... How could it break? The expression "@foo" seems to be very
>well defined in perl; it is an idiomatic way of converting an array to
>a string (with $" as the separator).
No, this is simply incorrect. It's well defined, but the definition
is more complicated than you think it is.
Consider for example:
print "From: mjd@plover.com";
Should this interpolate the contents of the array @plover? Or should
it take `@plover' literally? Contrary to your proposed rule, one
would like it to take @plover literally here.
In perl1 and perl2, the answer was that @x in a double-quoted string
was *always* taken literally.
In perl3, Larry decided it ould be good to allow interpolation of
arrays (and array and hash elements and slices) inside of
double-quoted strings. But if the rule were as simple as that, it
would have broken a lot of pre-existing code such as
print "From: mjd@plover.com";
which would then suddenly generate the output
From: mjd.com
which is wrong.
So the rule in perl3 and perl4 was: If @plover has been used already,
interpolate it; otherwise take the sequence literally.
However, if strings are parsed at compile time, which they are in
perl5, the compiler can't ask whether @plover has been used or not,
because the decision about whether @plover will be taken literally
must be made at compile time, and perl won't know whether the array
has been used until execution time, when it is too late.
So the rule in perl5 is a little different; if the compiler has seen a
declaration of @plover earlier in the file, it knows that there is
really an array with that name, and it interpolates.
If not, it could decide to take the @plover literally, but the hope is
that Perl will migrate toward the simpler rule that you want to have,
and always interpolate @plover. However, before that can happen, two
other things have to happen first:
1. People have to get out of the habit of writing
print "From: mjd@plover.com";
when what they mean is
print "From: mjd\@plover.com";
and
2. Old code has to be converted.
So now, if perl sees a @plover that has *not* been predeclared, it
emits a syntax error and forces you to indicate unambiguously whether
you want the array interpolated or not. If you want interpolation,
you declare the array; if not, you put \ in front of the @.
>If @foo doesn't exist, the result is (and should be) a null
>string. There doesn't seem to be much of any way for this to
>"break". Is there a version of perl around that treats this
>expression any other way?
As I indicated above, *every* version of Perl treats this expression
some other way, and versions up until perl 3.0 did the exact opposite.
> A Perl script consists of a sequence of declarations and statements. The
> only things that need to be declared in Perl are report formats and
> subroutines. ...
>
>This seems very clear and unambiguous,
Who are you going to believe, anyway? Some vague implication in the
manual, or the error message you just got? Clear and unambiguous,
maybe, but incomplete, and, if taken ilterally, wrong.
>This seems to me to be obviously a bug,
No; it's a feature. In fact, to me it seems obviously a feature. How
could you think it was a bug? There's an error message; the
description of the error message explains it in detail, and the
program behaves the way the error message and the description says.
How could that sort of thing doesn't creep into a program by accident?
You may not like it, but that's not a bug.
>especially in light of the above quote,
If there is a bug here, it's in the `above quote'. And it's not clear
that it should be fixed. Documentation is cumbersome when it tries to
get every tiny little detail right everywhere; a bette approach is to
explain the general situation first, and the fussy details later. The
introduction to `perlsyn' is not the place to be dragging in
exceptions about error-checking on array interpolation in
double-quoted strings.
>As far as I can tell, this bug/feature isn't documented in the man pages.
What, other than the detailed explanation of the error message that's
listed in `perldiag' that other people already quoted? What else do
you want? The error message took you by surprise; that's a shame; the
next step should have been to look up the error message in the
documentation, and if you had done that, you would have found the
explanation you wanted in just the place it should be.
Most of the time, people program happily without finding out about
this bizarre and obscure error, because Perl usually guesses correctly
what you want. Burdening the basic documentation with a detailed
explanation of a complicated special case that rarely occurs is not
going to improve the manual, in my opinion.
>Well, I guess it's one more entry in my archive of perversities in various
>languages.
If you don't want perversity, you're using the wrong language.
Consider:
$string =~ /$foo[0-9]/;
Perl has two choices here: It can interpolate the variable $foo, and
take [0-9] as a character class, or it can take [0-9] as an array
subscript, compute 0-9 as a subtraction, yielding -9, and get the
9th-to-last element from the end of the array @foo. Which will it do?
Answer: The right one.
> But the perl gang is way behind.
Maybe you're not looking hard enough?
------------------------------
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 4348
**************************************