[9111] in Perl-Users-Digest
Perl-Users Digest, Issue: 2729 Volume: 8
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue May 26 19:07:34 1998
Date: Tue, 26 May 98 16:00:31 -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 Tue, 26 May 1998 Volume: 8 Number: 2729
Today's topics:
Re: "Picture of the day" <rootbeer@teleport.com>
Re: An unwelcome and undeserved slap <tchrist@mox.perl.com>
Re: An unwelcome and undeserved slap (Greg Lindahl)
Re: Calling perl from other language on Win32 <keithmur@mindspring.com>
Re: Clearly define "free software" Klaus.Schilling@home.ivm.de
Re: Clearly define "free software" (Stefaan A Eeckels)
Client socket app not reading from server. <sloscialo@chubb.com>
Re: defining constant $VERSION variable for RCS/Clearca <rootbeer@teleport.com>
Re: GNU attacks on the open software community (Greg Lindahl)
Re: GPL documentation == unspeakable evil (Stefaan A Eeckels)
Re: grep -v? (Craig Berry)
Re: Have we got a good free Perl manual? (Marcus G. Daniels)
Re: help! sort data / build a database <rootbeer@teleport.com>
Re: Inplace file editing within a perl program <brianm@kodak.com>
Re: Inplace file editing within a perl program <rootbeer@teleport.com>
Re: list context: || vs or <rootbeer@teleport.com>
Re: list context: || vs or <tchrist@mox.perl.com>
Re: list context: || vs or (Matt Knecht)
Re: list context: || vs or (Matt Knecht)
Re: list context: || vs or <tchrist@mox.perl.com>
Re: list context: || vs or <tchrist@mox.perl.com>
Re: list context: || vs or <rootbeer@teleport.com>
Location Header in Netscape (J1T1W1)
Re: perl times out <rootbeer@teleport.com>
pingecho in net::ping for win32 <playinmantis@earthlink.net>
Digest Administrivia (Last modified: 8 Mar 97) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Tue, 26 May 1998 19:52:22 GMT
From: Tom Phoenix <rootbeer@teleport.com>
Subject: Re: "Picture of the day"
Message-Id: <Pine.GSO.3.96.980526124539.27437Q-100000@user2.teleport.com>
On Tue, 26 May 1998, Portoles wrote:
> Does anyone out there know of a daily rotation script program. For
> example, quote of the day or picture of the day?
Yes. If you're wanting to write one, you probably want to use cron or your
system's equivalent. If you're looking for already-written software, there
are many archives of useful scripts; your favorite web search engine will
help you to find them. Good luck!
--
Tom Phoenix Perl Training and Hacking Esperanto
Randal Schwartz Case: http://www.rahul.net/jeffrey/ovs/
------------------------------
Date: 26 May 1998 20:36:20 GMT
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: Re: An unwelcome and undeserved slap
Message-Id: <6kf944$5v4$1@csnews.cs.colorado.edu>
[courtesy cc of this posting sent to cited author via email]
In comp.lang.perl.misc, Wolfgang Denk <wd@denx.muc.de> writes:
:>Unfortunately RMS was not tactful about it, and he has invalidated his
:>claim in the eyes of many people, but I do think he has some sort of point.
:
:I was one of his fans; this has changed *much*.
Same here.
To be fair, one should remember that annoying or even ignorant though
he may sometimes be, Richard is not ungifted.
It's also ok to agree with on person on some matters and disagree with
them on others.
--tom
--
On Monday mornings I am dedicated to the proposition that all men are
created jerks.
--H. Allen Smith, "Let the Crabgrass Grow"
------------------------------
Date: 26 May 1998 20:31:07 GMT
From: lindahl@pbm.com (Greg Lindahl)
Subject: Re: An unwelcome and undeserved slap
Message-Id: <6kf8qb$ino@news3.newsguy.com>
> > > You really want *another* thread on this?
> >
> > No. The entire "GNU Linux" thread was extremely non-constructive, so
> > everyone really should avoid it like the plague.
>
> Tell that to RMS.
I have. I'm also telling it to you. rms has opinions and you have
opinions; you don't have to constantly refight the same flamewar over
and over. And it doesn't matter who started it this time around:
Just Say No.
-- g
------------------------------
Date: Tue, 26 May 1998 16:07:40 -0500
From: "Keith G. Murphy" <keithmur@mindspring.com>
Subject: Re: Calling perl from other language on Win32
Message-Id: <356B2F1C.C22FFEA7@mindspring.com>
I find that to get the flexibility I want in invoking Perl
programatically, CreateProcess() is the API call to use.
Some tips:
Use the StartupInfo block with these settings:
StartupInfo.hStd* equal to handles of the files you want your input,
output, error associated with.
StartupInfo.dwFlags = STARTF_USESTDHANDLES or STARTF_USESHOWWINDOW.
Use GetEnvironmentStrings to get an environment block to pass to
CreateProcess(); be sure to get rid of it when you've finished.
I have a whole chunk of Delphi (Object Pascal) code that does all this.
I'll E-mail it (or post it here) for you if you like.
Considering your name, Pascal, shouldn't you really be using Delphi?
:-)
It's also :=}.
pascal POTTIER wrote:
>
> I'm new on Perl, but it's a :=} language.
>
> I'm having a user interface with VB or VC++ and i want to call Perl scripts.
> I am opening a DOS box each time to shell the Perl interpreter.
>
> Is there a nicer or faster way to launch scripts ?
>
> Thanks to everyone for help.
------------------------------
Date: 26 May 98 20:39:37 GMT
From: Klaus.Schilling@home.ivm.de
Subject: Re: Clearly define "free software"
Message-Id: <356b2889.0@news.ivm.net>
>
> Re: Clearly define "free software"
>
> From: les@MCS.COM (Leslie Mikesell)
> References:
> <3569ac1f.0@news.ivm.net>
>In article <3569ac1f.0@news.ivm.net>, <Klaus.Schilling@home.ivm.de> wrote:
>>>
>>>>> >Proprietary software like oracle is immoral.
>>>>>
>>>>> Why do you think that? I can understand the concept that you do
>>>>> not want to pay for software that someone else developed and therefore
>>>>> owns. I don't understand the concept that the existence of
>>>>> this work is immoral. Is someone harmed by the fact that this
>>>>> work, which wouldn't otherwise exist, is available to people willing
>>>>> to help recover the cost of it's development and encourage further
>>>>> such work?
>>
>>Intellectual property is theft from the collective consciousness, thus evil.
>
>Does that mean you believe that all ideas are 'discovered', as opposed
>to being created by individual effort?
>
Ideas are preexistant and rememorized.
Klaus Schilling
------------------------------
Date: 26 May 1998 22:27:21 GMT
From: Stefaan.Eeckels@ecc.lu (Stefaan A Eeckels)
Subject: Re: Clearly define "free software"
Message-Id: <6kffk9$seg$2@justus.ecc.lu>
In article <356b2889.0@news.ivm.net>,
Klaus.Schilling@home.ivm.de writes:
>
> Ideas are preexistant and rememorized.
This probably explains why the flies in my house
get so many brilliant ideas ;-)
--
Stefaan
--
PGP key available from PGP key servers (http://www.pgp.net/pgpnet/)
___________________________________________________________________
Williams and Holland's Law: If enough data is collected,
anything may be proven by statistical methods.
------------------------------
Date: Tue, 26 May 1998 17:07:01 -0400
From: "Sergio Loscialo" <sloscialo@chubb.com>
Subject: Client socket app not reading from server.
Message-Id: <6kfb24$6qq@sidney.chubb.com>
I am having some difficulty in getting a client app to read from a
Windows 95/NT server app. I used the simple client sample from
the 2nd Camel book and can connect and send information to the
server app. The server sends back a response, but the client
apps never gets it until I kill the server app.
Here's a sample of the client app:
print $HTMLHeader;
$remote = shift || $server;
$port = shift || $server_port;
if ($port =~ /\D/) { $port = getservbyname($port, 'tcp') }
die "No port.<br>" unless $port;
$iaddr = inet_aton($remote) or die "No host: $remote<br>";
$paddr = sockaddr_in($port, $iaddr);
$proto = getprotobyname('tcp');
socket(SOCK, PF_INET, SOCK_STREAM, $proto) or die "Socket: $!<br>";
connect(SOCK, $paddr) or die "Connect: $!<br>";
# Send some info
$line = "hello there.";
send(SOCK, $line, length($line));
# Read some info
while (defined($line=<SOCK>)) {
print "<h1>$line<\h1>\n";
}
close (SOCK) or die "Close: $!<br>";
Any help would be greatly appreciated. All I really need to do is read
the response to see if everything went ok on the server side.
----
Sergio Loscialo
Chubb Computer Services
http://ccs.chubb.com
------------------------------
Date: Tue, 26 May 1998 19:16:38 GMT
From: Tom Phoenix <rootbeer@teleport.com>
Subject: Re: defining constant $VERSION variable for RCS/Clearcase
Message-Id: <Pine.GSO.3.96.980526120315.27437M-100000@user2.teleport.com>
On 26 May 1998 jari.aalto@poboxes.com wrote:
> *FILE_ID = \q$Id: perl-style.txt,v 1.41 1998/05/23 08:39:09 jaalto Exp jaalto $;
>
> {
> my $ver = (split ' ', $FILE_ID)[$FILE_ID =~ /@@/ ? 1: 2];
> *VERSION = \sprintf "%d.%03d", $ver =~ /(\d+)\.(\d+)/;
> }
>
> $VERSION = 1;
I'm not completely sure, but I think that the reason this didn't work is
because the assignment to *VERSION is not a constant value determined at
compile time, but the result of an expression. This works, though.
{
my $ver;
use constant FILE_ID =>
q$Id: perl-style.txt,v 1.41 1998/05/23 08:39:09 jaalto Exp jaalto $;
BEGIN {
$ver = (split ' ', FILE_ID)[FILE_ID =~ /@@/ ? 1: 2];
}
use constant VERSION =>
sprintf "%d.%03d", $ver =~ /(\d+)\.(\d+)/;
}
At this point, you could even do this sort of thing, if you wished.
use vars qw/$VERSION/;
*VERSION = \VERSION;
print "$VERSION\n";
$VERSION = 'oops'; # Causes the error
Hope this helps!
--
Tom Phoenix Perl Training and Hacking Esperanto
Randal Schwartz Case: http://www.rahul.net/jeffrey/ovs/
------------------------------
Date: 26 May 1998 21:40:10 GMT
From: lindahl@pbm.com (Greg Lindahl)
Subject: Re: GNU attacks on the open software community
Message-Id: <6kfcrq$ld7@news1.newsguy.com>
Horst von Brand <vonbrand@inf.utfsm.cl> writes:
> As long as it's just plans and grandiose ideas... Hurd is _still_ 0.2,
> still totally unusable (never could get grub to grok the disks of a
> standard PC clone), and dates from June 12, 1997. Linux started way later
> than the hurd, and it just _works_.
Forgive me if I'm unclear on the concept, but what constructive
purpose is served by flaming the Hurd? That's not even on-topic in
this flamewar, much less constructive.
> Don't get me wrong: I sincerely admire the enormous amount of work done by
> the FSF, and I'm grateful for the software it has given all of us. I think
> it is sad to see it in the current stand.
And even more sad to see you flaming for no purpose whatsoever. [Not
really a personal flame, many people are doing that these days...]
Go work on the software you like, and leave other people to work on
whatever they like. If that's the Hurd, so be it. Me, I use Linux, but
I respect the right of everyone to work on what they find interesting.
-- g
------------------------------
Date: 26 May 1998 22:06:12 GMT
From: Stefaan.Eeckels@ecc.lu (Stefaan A Eeckels)
Subject: Re: GPL documentation == unspeakable evil
Message-Id: <6kfeck$seg$1@justus.ecc.lu>
In article <6kekuk$r3k$1@nnrp1.dejanews.com>,
birgitt@my-dejanews.com writes:
> In article <6kdv95$oct$1@justus.ecc.lu>,
> Stefaan.Eeckels@ecc.lu (Stefaan A Eeckels) wrote:
> An author of GPLed package, whose work is a derivative work
> of a small original GPLed package (you say size is not relevant),
> and whose package needs modules and libraries copyrighted by
> other authors all under GPL, has the freedom to change the license
> of his package (his code plus all used code of the modules)
> if he gets releases from all previous authors plus *all* authors
> of all modules needed ?
Yes. I think you shouldn't stress 'his' package, because it
contains his code, and that of numerous other people. The
way you've described it, the package really is a group effort,
coordinated by the lead author. Linux is such a project, on
a very large scale. Surely, you wouldn't like Linus to have
the right to suddenly make Linux non-free ;-)
>
> Does he still need the release of all module author's if he
> wants to change the license for his own code from a certain version on
> from GPL to something else ?
In the case of Perl, one could argue that the usage of Perl
modules is not a sufficient reason to make a program a
derivative work. With Perl scripts, the whole issue is really
a non-starter, as Perl scripts are *always* distributed in
source form (maybe that's why the Perl compiler remains
pie-in-the-sky ;-)
>
> If that is so, doesn't it make it very difficult then to use
> modules, as changing licenses becomes so difficult ?
See above. I might even have goofed as far as modules
are concerned, but such cases would have to be tested
in Court (my uncle, who is a lawyer, always refuses to
say 'the law says this'; he always says 'let's test
it in court, we might have a chance' :-). In any case,
the AL is a lot easier than the GPL when it comes to
the handling of derivative works.
>
> And how fair is that, if your code is 10000 lines and the
> module's code of another author is 40 lines, how is it that
> this author can have so much power in licensing terms
> over the 10 000 lines of code of the main author ?
Because in your scenario the second (lead) author based
his work on GPL'ed code. He supposedly thought this to
be a tremendous advantage compared to writing the whole
shebang himself. Mind you, nobody forces you to base
developments on GPL'ed code. You can buy a commercial
library, or write it yourself. When you use someone else's
property, you should respect it.
>
>> Author #2 cannot change the licensing status of the program,
>> as he doesn't hold all the copyrights, and doesn't have the
>> appropriate licenses to do so.
>
> So, basically that means that an author who has chosen once
> GPL can not change to any other license as long as he has
> not permissions and releases from *all* authors of code, who
> originally participated to make the package a better product ?
> Including authors of patches etc. independent of how big
> or small the contribution were ?
Yes. Maybe the patches corrected major bugs that made the
original impossible to use ;-)
>
> This seems then not to be very "free" and could be potentially
> "unfair".
That depends on your definition of 'free'. Freedom is to be
allowed to do what you want *as long as you are not impinging
on other people's freedom*. Freedom is never absolute (and
democracy is more about respect for minorities than the rule
of the majority), and the condition for using Open Source
software as basis of your product is that you respect the
original author's license. In any case, the 'free' in
FSF and 'free' software is not about *your* freedom to do
as you please with other people's code, but to keep the
software freely available under the terms of the original
license.
>
>> There is no other option, unless the author(s) decide(s) to
>> release under another license. And even then, the original
>> program remains available under the GPL and can be maintained
>> and enhanced by others. This is the purpose of the GPL.
>
> I understood that part, I just don't understand how you can
> ever get out of a GPL license if you have to get permissions
> from so many authors who might have made only relatively
> small contributions.
Why would you want to change the license? I can see only
one reason, and that is that you hope to make more money
from selling a proprietary program. If your work is based
on that of other people, this is what is usually called
'theft'. Getting their permission, and allowing them to
share in the monetary rewards of the change in license
is nothing more than honourable.
>
>> > Am I wrong, naiv ?
>> Both ;-)
>
> Now, did I make a little progress here ? Or still very wrong ?
> ;-)
You're getting there.
>
> Ooops, I do, I do, I am not the sueing monger, but I
> wouldn't choose software either which has the potential of doing
> too much damage.
Which has *nothing* to do with the license it comes with, but
with your accurate assesment of its qualities and vices.
>
> And I would not like to put years of my sweat into developing
> software (if I were a software developer - luckily I never would
> be able to be one anyway ;-) for which I would be
> so much dependent on other people to change licensing terms even
> slightly.
Then don't base your world-shattering new program on GPL'ed
code. The GPL is clear (to people with an open mind) and
unambiguous, and you should understand its implications
before you embark on developing a program incorporating
other people's GPL'ed work.
>
> Thank you for your answer.
You're very welcome.
--
Stefaan
--
PGP key available from PGP key servers (http://www.pgp.net/pgpnet/)
___________________________________________________________________
Williams and Holland's Law: If enough data is collected,
anything may be proven by statistical methods.
------------------------------
Date: 26 May 1998 22:10:10 GMT
From: cberry@cinenet.net (Craig Berry)
Subject: Re: grep -v?
Message-Id: <6kfek2$mu$1@marina.cinenet.net>
Shawn Laemmrich (swlaemmr@dilbert.tdg.mtu.edu) wrote:
: I need to write a simple script that searches line by line through a text
: file and finds any characters that are NOT letters or numbers. In
: bourne shell I would use grep -v to do this, how do I do it in perl?
>From the command line:
perl -nwe 'print if /[^A-Za-z\d\s]/' input-file-list
This actually finds any line containing a character which is not a letter,
number, or whitespace; change \s to \n if you really want this to match on
whitespace as well.
---------------------------------------------------------------------
| 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: 26 May 1998 15:36:56 -0700
From: marcusd@cathcart.sysc.pdx.edu (Marcus G. Daniels)
Subject: Re: Have we got a good free Perl manual?
Message-Id: <rfi1ztg3bhz.fsf@cathcart.sysc.pdx.edu>
>>>>> "TMH" == Tina Marie Holmboe <tina@scandinaviaonline.se> writes:
TMH> But perhaps I've gotten this wrong - the man-pages ain't as
TMH> free as Perl?
perlfaq and perltoot are under a non-commercial and no-modify
licenses, respectively. Perl is under the Artistic/GPL license.
------------------------------
Date: Tue, 26 May 1998 17:35:27 GMT
From: Tom Phoenix <rootbeer@teleport.com>
Subject: Re: help! sort data / build a database
Message-Id: <Pine.GSO.3.96.980526102704.27437H-100000@user2.teleport.com>
On Mon, 25 May 1998, patience wrote:
> Newsgroups: comp.os.linux.misc, comp.lang.perl.misc, comp.os.linux.setup
When cross-posting, it's good to set followups to the most appropriate
newsgroup, as I've done here.
> I need to sort data of 1000+ subjects. I could really use some advise
> or tips. : )
Have you seen perl's docs on the sort function? That's in the perlfunc
manpage.
http://www.cpan.org/doc/manual/html/pod/perlfunc/sort.html
Hope this helps!
--
Tom Phoenix Perl Training and Hacking Esperanto
Randal Schwartz Case: http://www.rahul.net/jeffrey/ovs/
------------------------------
Date: Tue, 26 May 1998 17:28:48 -0400
From: Brian Mathis <brianm@kodak.com>
To: Alvin Pollock <apollock@Xlibrary.berkeley.edu>
Subject: Re: Inplace file editing within a perl program
Message-Id: <356B3410.95C8CB9@kodak.com>
[posted and emailed]
Alvin Pollock wrote:
>
> Deep within a perl program I would like to open up a set of files
> and edit them inplace, much as I could do with the -pi switch
[...]
> Alvin Pollock
Take a look at the perlvar man page. There is a variable called $^I which you
can set that will turn on inplace editing.
Brian Mathis
--
$_="
,.,,,.,,.,,.,,,,..,,,,,,,,.,,,,,,,,,,,,,,,,,,,,,,,.,,,,,,,..,..,,.,,,,,,,,,
";s/\s//gs; tr/,./05/; @a=split(//); $_=<DATA>; tr/~`'"^/0-4/;map{$o.=
$a[$i]+$_;$i++} split(//); map{$o[++$#o]=substr($o,$j,3);$j+=3}@a;map{
print chr($_)}@o; __DATA__ # Brian Mathis, Just another perl hacker.
~'^``'``~```~"'~^'``~```````~^`~```^~"'``'`~```^`~"~"'`~^~^'~^^`~'`~```^~`~
------------------------------
Date: Tue, 26 May 1998 20:40:50 GMT
From: Tom Phoenix <rootbeer@teleport.com>
Subject: Re: Inplace file editing within a perl program
Message-Id: <Pine.GSO.3.96.980526133912.27437l-100000@user2.teleport.com>
On Tue, 26 May 1998, Alvin Pollock wrote:
> I want to loop through each line and do a search and replace
> on a substring, just like if I did:
>
> perl -pi -e 's/this/that/g;' filename
>
> on the command line.
{
local $^I = ''; # Could be '.bak' instead
local @ARGV = 'filename'; # Could be a glob
while (<>) {
s/this/that/g;
print;
}
}
Hope this helps!
--
Tom Phoenix Perl Training and Hacking Esperanto
Randal Schwartz Case: http://www.rahul.net/jeffrey/ovs/
------------------------------
Date: Tue, 26 May 1998 21:06:26 GMT
From: Tom Phoenix <rootbeer@teleport.com>
Subject: Re: list context: || vs or
Message-Id: <Pine.GSO.3.96.980526134134.27437m-100000@user2.teleport.com>
On Tue, 26 May 1998, Matt Knecht wrote:
> I've noticed some odd behaviour when using || as opposed to or.
As you know, it's all in the precedence chart. The 'or' has very very low
precedence.
> #@stat = stat($fname) or die "error:$!";
( @stat = stat($fname) ) or (die "error:$!");
That is, if the assignment to @stat was an empty list, die. That's what
you want, I think.
> @stat = stat($fname) || die "error:$!";
@stat = (stat($fname) || die "error:$!");
That is, if stat in a scalar context (!!!) returns a false value, die. If
it returned a true value, @stat gets that true scalar value. (Why a scalar
context? Because the left side of either kind of 'or' is a Boolean
context, which is always scalar.)
> @stat gets the value of 1 when using || (Actually, $stat[0]).
Of course, stat isn't documented to do anything in particular in a scalar
context, but in this case it seems to be returning a boolean "stat
succeeded" value. But since it's not documented, a future version of Perl
may do something different, such as dumping core, printing a warning, or
triggering a sound synthesizer to play the sound of Randal Schwartz
reading the precedence chart out loud in his best Kermit the Frog voice,
which is actually quite good. :-)
Hope this helps!
--
Tom Phoenix Perl Training and Hacking Esperanto
Randal Schwartz Case: http://www.rahul.net/jeffrey/ovs/
------------------------------
Date: 26 May 1998 21:01:37 GMT
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: Re: list context: || vs or
Message-Id: <6kfajh$7ja$1@csnews.cs.colorado.edu>
[courtesy cc of this posting sent to cited author via email]
In comp.lang.perl.misc, hex@voicenet.com (Matt Knecht) writes:
:I've noticed some odd behaviour when using || as opposed to or. The
:following script explains it better than I could:
:@stat = stat($fname) || die "error:$!";
You just used stat in a scalar context.
This is not a defined operation.
--tom
--
"I discount everything Djikstra has to say because he doesn't actually
run his programs" --Rob Pike, On Djikstra's belief that bugs in your
program are a moral failure to prove your program mathematically correct.
------------------------------
Date: Tue, 26 May 1998 21:34:39 GMT
From: hex@voicenet.com (Matt Knecht)
Subject: Re: list context: || vs or
Message-Id: <PzGa1.183$_3.1064684@news2.voicenet.com>
On Tue, 26 May 1998 21:06:26 GMT, Tom Phoenix <rootbeer@teleport.com> wrote:
>On Tue, 26 May 1998, Matt Knecht wrote:
>
>> I've noticed some odd behaviour when using || as opposed to or.
>
>As you know, it's all in the precedence chart. The 'or' has very very low
>precedence.
I'm from the school of: "Put everything in parenthesis to enforce the
precedence you mean, don't rely on any language's precedence rules."
Perl is the first language where I've had to worry about the
precedence of the assignment operator. A quick look at the list shows
me that '=' lies between '||' and 'or' (And my mistake).
I love Perl. It's a fantastic language, but having to worry about the
precedence of '=' seems a bit kooky to me. I can't think of any time
where I would want '=' to be a higher precedence than _anything_.
>That is, if stat in a scalar context (!!!) returns a false value, die. If
>it returned a true value, @stat gets that true scalar value. (Why a scalar
>context? Because the left side of either kind of 'or' is a Boolean
>context, which is always scalar.)
>Of course, stat isn't documented to do anything in particular in a scalar
>context, but in this case it seems to be returning a boolean "stat
>succeeded" value.
stat() returns a list. In scalar context, that should be equal to
something like:
DB<2> @list = ();
DB<3> print scalar @list;
0
Which works nicely when you say: if (scalar @list) { do_stuff(); }
Or even: @my_list = some_sub_that_returns_a_list() or die;
>But since it's not documented, a future version of Perl
>may do something different, such as dumping core, printing a warning,
Hmm... maybe all system calls should be checked to see if they are
returning true/false on a succeed/fail? At any rate, I sure hope that
looking at return values from system calls, whether they return lists
or scalars won't break in the next version of Perl!
>or
>triggering a sound synthesizer to play the sound of Randal Schwartz
>reading the precedence chart out loud in his best Kermit the Frog voice,
>which is actually quite good. :-)
This would be worth the extra time it would take to download Perl. I
look forward to it in the next version!
>Hope this helps!
Yes, it did. Thanks.
--
Matt Knecht + <hex@voicenet.com>
------------------------------
Date: Tue, 26 May 1998 21:47:14 GMT
From: hex@voicenet.com (Matt Knecht)
Subject: Re: list context: || vs or
Message-Id: <CLGa1.184$_3.1064967@news2.voicenet.com>
On 26 May 1998 21:01:37 GMT, Tom Christiansen <tchrist@mox.perl.com> wrote:
>:@stat = stat($fname) || die "error:$!";
>
>You just used stat in a scalar context.
>This is not a defined operation.
Hrm. What's the difference between:
$scalar = scalar @list;
$scalar = scalar some_sub_that_returns_a_list();
or even:
@list = qw(x y z);
$scalar = @list;
print $scalar;
3
One is a defined operation and one is not? Why? I can't find
anything in the documentation that says there is a difference between
a list, and a function that returns a list. In fact, in many places
in the Camel and Panther inline anonymous lists are used interchangably
with subs that return lists.
--
Matt Knecht + <hex@voicenet.com>
------------------------------
Date: 26 May 1998 22:12:58 GMT
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: Re: list context: || vs or
Message-Id: <6kfepa$c4h$1@csnews.cs.colorado.edu>
[courtesy cc of this posting sent to cited author via email]
In comp.lang.perl.misc, hex@voicenet.com (Matt Knecht) writes:
:Hrm. What's the difference between:
:
:$scalar = scalar @list;
^ wrong name
That's not a list. That's an array.
:$scalar = scalar some_sub_that_returns_a_list();
:or even:
:
:@list = qw(x y z);
That's not a list. That's an array.
:$scalar = @list;
That's not a list. That's an array.
:print $scalar;
:3
:One is a defined operation and one is not? Why? I can't find
:anything in the documentation that says there is a difference between
:a list, and a function that returns a list.
There isn't. But you're calling @whatever a list, and it's not.
It's an array.
Question: How do you produce a reference to a list?
Type: References
Difficulty: 6/7 (Hard)
Answer: \@array
Correct: No.
Why: @array is not a list, but an array.
Answer: [ @array ]
Correct: No.
Why: That makes a reference to a newly allocated anonymous
array, and populates it with a copy of the contents
of @array.
Answer: \($s, @a, %h, &c)
Correct: No.
Why: The backslash operator is distributive across a list, and
produces a list in return, this being (\$s, \@a, \%h, \&c).
Well. In list context. In scalar context, it's a strange
way to get a reference to the function &c.
Answer: You can't take a reference to a list.
Correct: Yes.
Why: A list is not an array, although is many places one may be
used for the other. An array has an AV allocated,
whereas a list is just some values on a stack somewhere.
You cannot alter the length of a list, for example, any
more than you could alter a number by saying something
like 23++. While an array contains a list, it is not
a list itself.
Beyond that, you cannot have a "list in scalar context". This is
like dividing by 0. It can't happen. The universe will not allow it.
@a = (1,2,3);
$s = (1,2,3);
The second is not assigning a list, you know. It is not a "list
in scalar context".
There's something about the entire contexture of the language
that is unclear to the general public, and I'm not sure
what to do to clear it up.
--tom
--
If you want to program in C, program in C. It's a nice language. I
use it occasionally... :-)
--Larry Wall in <7577@jpl-devvax.JPL.NASA.GOV>
------------------------------
Date: 26 May 1998 22:18:42 GMT
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: Re: list context: || vs or
Message-Id: <6kff42$c4h$2@csnews.cs.colorado.edu>
[courtesy cc of this posting sent to cited author via email]
In comp.lang.perl.misc,
hex@voicenet.com (Matt Knecht) writes:
:I love Perl. It's a fantastic language, but having to worry about the
:precedence of '=' seems a bit kooky to me. I can't think of any time
:where I would want '=' to be a higher precedence than _anything_.
You could stop using or, you know. I have. (And Larry continues to
chide me for it. I have to go through all 650 odd pages of the Perl
Cookbook and turn the ||'s into or's because he told me too. Grrr......)
:stat() returns a list. In scalar context, that should be equal to
:something like:
:
: DB<2> @list = ();
: DB<3> print scalar @list;
This is your unbelievably bogus misunderstanding.
It's just off. Apparently you break this:
@pwent = getpwnam("fred");
$uid = getpwnam("fred");
Or this:
@struct_tm = localtime($time);
$datestring = localtime($time);
I've said it a thousand times, in capital letters, in bold, and still
many hear me not.
JUST BECAUSE YOU KNOW WHAT SOMETHING DOES IN LIST
CONTEXT IN NO FASHION WHATSOEVER ALLOWS YOU TO
INFER *ANYTHING* ABOUT ITS BEHAVIOR IN SCALAR CONTEXT.
--tom
--
"Sometimes the sins of the fathers are visited on the nephews and nieces."
--Larry Wall
------------------------------
Date: Tue, 26 May 1998 22:50:00 GMT
From: Tom Phoenix <rootbeer@teleport.com>
Subject: Re: list context: || vs or
Message-Id: <Pine.GSO.3.96.980526153136.8000A-100000@user2.teleport.com>
On Tue, 26 May 1998, Matt Knecht wrote:
> I love Perl. It's a fantastic language, but having to worry about the
> precedence of '=' seems a bit kooky to me. I can't think of any time
> where I would want '=' to be a higher precedence than _anything_.
You did this time. :-)
@list = stat($filename) or die "Can't stat '$filename': $!";
> stat() returns a list. In scalar context, that should be
...unknown until you see the manpage. Only a few list-returning functions
return the length of that list when called in a scalar context; the vast
majority don't. (I posted a comparitive list of these on about the 29th of
April; look for the subject "Initializing hash with null array" in your
favorite Usenet archive to find it.) If you can't read Larry's mind, you
have to see the manpage. :-)
> Hmm... maybe all system calls should be checked to see if they are
> returning true/false on a succeed/fail?
Well, ideally, anything which can fail _should_ signal failure in some
way. The stat call does return a proper succeed/fail value if you're
calling it in a list context, as above or similarly (say, in an 'if'
test).
Cheers!
--
Tom Phoenix Perl Training and Hacking Esperanto
Randal Schwartz Case: http://www.rahul.net/jeffrey/ovs/
------------------------------
Date: 26 May 1998 21:55:50 GMT
From: j1t1w1@aol.com (J1T1W1)
Subject: Location Header in Netscape
Message-Id: <1998052621555000.RAA21238@ladder03.news.aol.com>
Is there a CGI script out there that will call up a webpage and print out
the path to the html file, but not the html file itself on the Location header
in Netscape. I now if the default html file(index.html) for that particular
directory will not be display if it is opened, but what about a file that is
not the default file.
TIA,
J1T1W1
------------------------------
Date: Tue, 26 May 1998 20:26:19 GMT
From: Tom Phoenix <rootbeer@teleport.com>
Subject: Re: perl times out
Message-Id: <Pine.GSO.3.96.980526132258.27437h-100000@user2.teleport.com>
On Tue, 26 May 1998, Dieter Wiesflecker wrote:
> how can I avoid that my cgi-script (wich makes some socket-connection
> stuff) times out after about 1 minute?
If you're not doing something to make your script time out, there's
probably something set to terminate cgi scripts after a time limit on your
webserver. If your system administrator can't help you, get a new one. :-)
Good luck!
--
Tom Phoenix Perl Training and Hacking Esperanto
Randal Schwartz Case: http://www.rahul.net/jeffrey/ovs/
------------------------------
Date: Tue, 26 May 1998 15:29:00 -0700
From: Matthew Purdon <playinmantis@earthlink.net>
Subject: pingecho in net::ping for win32
Message-Id: <356B422C.399B9841@earthlink.net>
I'm attemping to use the pingecho subroutine from ping.pm for win32, but
to no avail. When I called it, I get "The Unsupported function alarm
function is uinmplemented". I tried commenting out the two alarm
functions in the "ping_tcp" subroutine. When I did this, it returned a
"0". I also tried to change the protocol to "udp" in the pingecho
subroutine, which also returned a "0" even when trying to ping a well
known host like www.yahoo.com. Anyone have any suggestions?
thanks,
matthew
------------------------------
Date: 8 Mar 97 21:33:47 GMT (Last modified)
From: Perl-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 8 Mar 97)
Message-Id: <null>
Administrivia:
The Perl-Users Digest is a retransmission of the USENET newsgroup
comp.lang.perl.misc. For subscription or unsubscription requests, send
the single line:
subscribe perl-users
or:
unsubscribe perl-users
to almanac@ruby.oce.orst.edu.
To submit articles to comp.lang.perl.misc (and this Digest), send your
article to perl-users@ruby.oce.orst.edu.
To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.
To request back copies (available for a week or so), send your request
to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
where x is the volume number and y is the issue number.
The Meta-FAQ, an article containing information about the FAQ, is
available by requesting "send perl-users meta-faq". The real FAQ, as it
appeared last in the newsgroup, can be retrieved with the request "send
perl-users FAQ". Due to their sizes, neither the Meta-FAQ nor the FAQ
are included in the digest.
The "mini-FAQ", which is an updated version of the Meta-FAQ, is
available by requesting "send perl-users mini-faq". It appears twice
weekly in the group, but is not distributed in the digest.
For other requests pertaining to the digest, send mail to
perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
sending perl questions to the -request address, I don't have time to
answer them even if I did know the answer.
------------------------------
End of Perl-Users Digest V8 Issue 2729
**************************************