[13516] in Perl-Users-Digest
Perl-Users Digest, Issue: 926 Volume: 9
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Sep 27 23:07:33 1999
Date: Mon, 27 Sep 1999 20:05:09 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <938487909-v9-i926@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Mon, 27 Sep 1999 Volume: 9 Number: 926
Today's topics:
$_ assignment (Danny Aldham)
Re: $_ assignment <jkline@one.net>
Re: Advice wanted: Creating an .exe <madebeer@igc.apc.org>
array getting in the way of compilation (shaun.coon)
Re: array getting in the way of compilation <hiller@email.com>
Re: array getting in the way of compilation <ltl@rgsun40.viasystems.com>
Re: array getting in the way of compilation <crdevilb@mtu.edu>
Re: array getting in the way of compilation <ltl@rgsun40.viasystems.com>
Calling an OLE method with parameters with Perl <Joe.Custerman@markettools.com.NOSPAM!!!!!!>
Re: CGI or JDBC <madebeer@igc.apc.org>
Re: Command Line CGI Script <admin@gatewaysolutions.net>
Determin IP address of client Browser (Derek Lavine)
Do you now an affordable Perl editor for Windows NT <ericdub@sympatico.ca>
Re: Do you now an affordable Perl editor for Windows NT <fliptop@underwear.peacecomputers.com>
Re: Do you now an affordable Perl editor for Windows NT <ltl@rgsun40.viasystems.com>
Re: File Upload <bwilcox@eudoramail.com>
fork()? <ytliu@cgi-factory.com>
Re: Looking for Downloadscript <madebeer@igc.apc.org>
Re: pattern matching problem <madebeer@igc.apc.org>
Re: remove the html tag in the file <skilchen@swissonline.ch>
Re: remove the html tag in the file (Randal L. Schwartz)
Re: Slice in scalar context (Greg Bacon)
Re: Slice in scalar context <uri@sysarch.com>
Sorting weird numeric data <mikes@athabascau.ca>
Re: Sorting weird numeric data <bwalton@rochester.rr.com>
Re: Suggestion - comp.lang.perl.flame (was Re: You shou <mpersico@erols.com>
Re: Trouble with CPAN module <ask_for_my_address_if_you_need_it@earthlink.net>
Re: using System function to run other programs (Charles DeRykus)
Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 27 Sep 1999 23:13:17 GMT
From: danny@hendrix.postino.com (Danny Aldham)
Subject: $_ assignment
Message-Id: <7sotmd$dcm$1@hendrix.postino.com>
X-Newsreader: TIN [version 1.2 PL2]
I find I am constantly assigning values to $_ , like:
$_ = $Domain ;
s/\./_/g ;
$Domain_Directory = $_ ;
since so many commands, (like substitute) , assume you are working with $_ .
What is the better way to do this, I know this is not right.
--
Danny Aldham Providing Certified Internetworking Solutions to Business
www.postino.com E-Mail, Web Servers, Mail Lists, Web Databases, SQL & Perl
------------------------------
Date: Mon, 27 Sep 1999 20:39:19 -0400
From: Joe Kline <jkline@one.net>
To: Danny Aldham <danny@hendrix.postino.com>
Subject: Re: $_ assignment
Message-Id: <37F00E37.1BAE850A@one.net>
[posted and mailed]
Danny Aldham wrote:
>
> X-Newsreader: TIN [version 1.2 PL2]
>
> I find I am constantly assigning values to $_ , like:
> $_ = $Domain ;
> s/\./_/g ;
> $Domain_Directory = $_ ;
>
> since so many commands, (like substitute) , assume you are working with $_ .
> What is the better way to do this, I know this is not right.
You don't have to always use the implied '$_' in s/// or tr/// or m//.
You might want to take a look at 'perldoc perlre'.
There you will find:
$line = 'some dummy line for example';
$line =~ s/line for example/might want to read the docs/;
Like everything in Perl (and most of life it seems) depends upon the
context of the usage. If you have any better examples/snippets of code
that might illuminate what you are asking, you might get significantly
better answers.
joe
-----------== Posted via Newsfeeds.Com, Uncensored Usenet News ==----------
http://www.newsfeeds.com The Largest Usenet Servers in the World!
------== Over 73,000 Newsgroups - Including Dedicated Binaries Servers ==-----
------------------------------
Date: Mon, 27 Sep 1999 18:26:02 -0700 (PDT)
From: Michael de Beer <madebeer@igc.apc.org>
Subject: Re: Advice wanted: Creating an .exe
Message-Id: <APC&1'0'50775dcb'682@igc.apc.org>
I'm not familiar with creating perl standalone .exe files.
You could bundle up your own version of perl, that include LWP, and have
a .bat file that runs that version on your script.
In the unix world various companies do this so their perl scripts will
always work. They sometime rename the executable to ${name}perl.
-Mike
------------------------------
Date: Mon, 27 Sep 1999 20:41:01 -0400
From: shaun.coon@ayer.mec.edu (shaun.coon)
Subject: array getting in the way of compilation
Message-Id: <MPG.1259d8a8f80f6ec7989685@news.earthlink.net>
I'm writing a piece of code that is meant to circulate through a list of
data, and place chunks of it into a group of arrays (based on a fairly
simple alphabetical criteria). I've done this with a set of elsif
statements following the initial if. Once the compiler hits the following
piece of code:
" } elsif ($section[$k] eq m) {
@mlist = (@mlist, " $data[$k]")
}"
it throws up an error that "@mlist must now be written as \@mlist at line
blah blah blah". The identical (I simply copied and pasted the code, and
then changed the individual values) sections dealing with "@alist"
through "@llist" work fine. I've changed the name of @mlist to see if I'd
stumbled upon some undocumented PERL special variable, but to no avail.
If anyone can shed light on what mechanism is doing this, I'd appreciate
it.
Shaun Coon
Network Manager
Ayer Public Schools
Ayer, MA
shaun.coon@ayer.mec.edu
------------------------------
Date: Tue, 28 Sep 1999 01:10:50 GMT
From: Jordan Hiller <hiller@email.com>
Subject: Re: array getting in the way of compilation
Message-Id: <37F01649.F46D0C7F@email.com>
You should probably be using push():
} elsif ($section[$k] eq m) { # <-- don't you want to have quotes
# around that "m"?
push(@mlist, " $data[$k]"); # <-- try push() here
}
Jordan
"shaun.coon" wrote:
> " } elsif ($section[$k] eq m) {
> @mlist = (@mlist, " $data[$k]")
> }"
--
Jordan Hiller (hiller@email.com)
JavaScript and Perl programs for
making online tests and quizzes:
http://web-shack.hypermart.net/quiz.html
------------------------------
Date: 28 Sep 1999 01:15:31 GMT
From: lt lindley <ltl@rgsun40.viasystems.com>
Subject: Re: array getting in the way of compilation
Message-Id: <7sp4rj$501$1@rguxd.viasystems.com>
shaun.coon <shaun.coon@ayer.mec.edu> wrote:
:> Once the compiler hits the following
:>piece of code:
:>" } elsif ($section[$k] eq m) {
:> @mlist = (@mlist, " $data[$k]")
:> }"
:>it throws up an error that "@mlist must now be written as \@mlist at line
:>blah blah blah". The identical (I simply copied and pasted the code, and
:>then changed the individual values) sections dealing with "@alist"
:>through "@llist" work fine. I've changed the name of @mlist to see if I'd
:>stumbled upon some undocumented PERL special variable, but to no avail.
:>If anyone can shed light on what mechanism is doing this, I'd appreciate
:>it.
Well, my, my, didn't you stumble onto an interesting little gotcha.
The problem is the letter 'm'. You didn't put it in quotes, so
perl assumes it is the matching operator and that ')' is your
delimiter for the operator. The contents of that are string
interpolated and you get that nice message about a bare '@'
in a string.
But I cannot reproduce that exact behavior. I get a message
about a runaway multiline string. Of course I'm using the '-w'
option and 'use strict'. You should be too.
Also, you need to read up on push, pop, shift, unshift and splice
array operators.
--
// Lee.Lindley /// I used to think that being right was everything.
// @bigfoot.com /// Then I matured into the realization that getting
//////////////////// along was more important. Except on usenet.
------------------------------
Date: 28 Sep 1999 01:39:04 GMT
From: Colin R. DeVilbiss <crdevilb@mtu.edu>
Subject: Re: array getting in the way of compilation
Message-Id: <7sp67o$ot8$1@campus3.mtu.edu>
shaun.coon <shaun.coon@ayer.mec.edu> wrote:
> " } elsif ($section[$k] eq m) {
> @mlist = (@mlist, " $data[$k]")
> }"
> it throws up an error that "@mlist must now be written as \@mlist at line
> blah blah blah". The identical (I simply copied and pasted the code, and
> then changed the individual values) sections dealing with "@alist"
> through "@llist" work fine.
are you using the -w flag?
if so, you should get warnings for all of the other, similar constructs:
perl -wle 'print q/a/ eq a'
Unquoted string "a" may clash with future reserved word at -e line 1.
1
however, perl infers that 'm)' begins a regular expression match in scalar
context, which is closed by the ')' on the assignment line, thus triggering
the error regarding @mlist in the quoted context.
the solution: quote all of your lowercase barewords (e.g. 'm', 'a').
this should remove the compile error and is much clearer in general.
perldoc perlop
Colin DeVilbiss
crdevilb@mtu.edu
------------------------------
Date: 28 Sep 1999 02:12:04 GMT
From: lt lindley <ltl@rgsun40.viasystems.com>
Subject: Re: array getting in the way of compilation
Message-Id: <7sp85k$5mc$1@rguxd.viasystems.com>
Colin R. DeVilbiss <crdevilb@mtu.edu> wrote:
:>the solution: quote all of your lowercase barewords (e.g. 'm', 'a').
:>this should remove the compile error and is much clearer in general.
Why quote just the lowercase barewords? Isn't that kind of like
saying that you only need to use a condom if she isn't a nice girl?
--
// Lee.Lindley /// I used to think that being right was everything.
// @bigfoot.com /// Then I matured into the realization that getting
//////////////////// along was more important. Except on usenet.
------------------------------
Date: Mon, 27 Sep 1999 18:18:27 -0600
From: "Joe Custerman" <Joe.Custerman@markettools.com.NOSPAM!!!!!!>
Subject: Calling an OLE method with parameters with Perl
Message-Id: <7sp558$c2t$1@news1.xs4all.nl>
Hi,
There are OLE methods in VB which you have to call with the parameters you
want to be set.
For instance, there is a method from an OLE object which has as input the
filename graphical image and it's size (x = width and y = height). In VB it
looks like this:
<Begin VB code>
filename="c:\temp\testfile.gif"
set obj=Server.CreateObject("<name OLE object>")
Select Case obj.GetFileDimensions(filename,x,y)
Case 1
out_str="GIF image: " & x & "x" & y
Case 2
out_str="JPEG image: " & x & "x" & y
Case 3
out_str="BMP image: " & x & "x" & y
Case 0
out_str="Unknown file format"
End Select
<End VB code>
These two parameters are empty before the call, and set after the call.
Does anybody know how to parse and retrieve these parameters in Perl?
The following code doesn't work:
<Begin Perl code>
$filename="c:\\temp\\testfile.gif"
$Case = $obj->GetFileDimensions($filename,$x,$y);
set obj=Server.CreateObject("<name OLE object>")
Result:
$x = undef;
$y = undef;
$tmp_variable = undef;
<End Perl code>
Thanks in advance,
Joe
------------------------------
Date: Mon, 27 Sep 1999 15:27:47 -0700 (PDT)
From: Michael de Beer <madebeer@igc.apc.org>
Subject: Re: CGI or JDBC
Message-Id: <APC&1'0'50775dc8'6ef@igc.apc.org>
>what are the pros and cons of using one technology over another ?
Java vs. Perl? Scan dejanews for advocacy wars on this subject.
From perlfaq1 How does Perl compare with other languages like Java....
Favorably in some areas, unfavorably in others. Precisely
which areas are good and bad is often a personal choice, so
asking this question on Usenet runs a strong risk of
starting an unproductive Holy War.
...
For various reasons, Perl is probably not well-suited for
real-time embedded systems, low-level operating systems
development work like device drivers or context-switching
code, complex multithreaded shared-memory applications, or
extremely large applications. You'll notice that perl is
not itself written in Perl.
>I don't really want to have to learn PErl but it seems cheaper than paying
>for a good JDBC driver like the one from IDS software.
You say that you would need to buy a commercial JDBC driver, while in
Perl the driver is free (probably with DBI/DBD). This seems unlikely to
me, although I'm not a Java programmer. Are you sure? (check your java
docs, read java faqs, post in java newsgroups, not in comp.lang.perl.misc)
>Will CGI continue po be used in the future ?
Yes, it will.
I think your question would be better phrased:
"I need to write a web application that talks to a database. Should I use
the language Perl (using either CGI or mod_perl), or should I use
the Java language? I know that Java has good database tools (JDBC),
but I'd need to buy a JDBC driver for my database."
Both languages are good at talking to databases. If
a) what you say about the commercial JDBC driver is true, and
b) you already know Java
Then it the answer to your question can be answered by asking yourself:
'is the time to learn Perl more valuable than the cost of the driver'?
[ oh, and throw in some considerations about the complexity
cost of maintaining multiple programming languages in your site, etc..
]
-Mike
------------------------------
Date: Mon, 27 Sep 1999 19:00:18 -0500
From: "Scott Beck" <admin@gatewaysolutions.net>
Subject: Re: Command Line CGI Script
Message-Id: <rv07ltel3i550@corp.supernews.com>
> Scott Beck <admin@gatewaysolutions.net> wrote:
> : The script I am running is an install script for a program.
> : The program will not run from the command line but from the browser.
> : It will need read, write, and create privileges on the directories that
are
> : created
> : with the install script.
> : The only way to do this is set the directories permissions to 0777 or
have
> : them owned
> : by the script.
> : The first option is a security risk and should not be done.
>
> Unfortunately, the second option is a risk, too, since a directory that is
> writeable by "nobody" is writeable by *anybody's* CGI script, not just the
> one you're installing. You're probably aware of this but it's worth
> pointing out.
>
Yes I do know this but setting the permissions to 0777 is still more
dangerous than
o755 and still allowing cgi's to use them.
> Unfortunately again, I don't have a good solution to offer; if you want
> something that's portable, you don't really have a lot of options (as far
> as I know); you could try to chown the file and then make the permissions
> 0777 if that fails, but I wouldn't recommend either solution if the data
> you're going to be writing is at all sensitive.
>
> What about having an install script that runs as a CGI instead of as a
> shell script, at least to create the necessary directory?
Well I looked at this option but the user would still have to change the
directory permissions to allow the CGI script to create the needed
directories.
I also looked at CGI-Wrap but I am pretty sure most servers do not have that
installed.
I was thinking there may be a way to fork a process and have the previous
process die.
Maybe that would allow the second process to run as user nobody but I tried
this and it
did not work.
O well.
I guess there is no solution to this.
I guess I will have to depend on the user having root access and being able
to chown.
Thanks though
Scott Beck.
------------------------------
Date: Tue, 28 Sep 1999 12:26:15 +1000
From: derek@realware.com.au (Derek Lavine)
Subject: Determin IP address of client Browser
Message-Id: <MPG.125ad250870216e3989680@news.hutch.com.au>
Hi all,
I have a situation where I would like to provide access to a site thus
www.mydom.mysite.com.au
The index.html auto loads a login script and I would like the login
script to check against a list of privilege IP addresses and for those it
offers slightly different options.
Is this possible. If not I can think of a few ways to simulate what I
need but this would be easiest.
Thanks
Derek
------------------------------
Date: Tue, 28 Sep 1999 01:29:39 GMT
From: "Eric Dubreuil" <ericdub@sympatico.ca>
Subject: Do you now an affordable Perl editor for Windows NT
Message-Id: <7SUH3.26804$FW3.27071@news21.bellglobal.com>
Hi!
I just installed Perl on my PC (Windows NT) and would like to get a nice
editor to edit my Perl code. I looked at a few commercials ones but they
are too expensive (and have way too many features for myt needs anyway).
I just need cheap, freeware or chareware editor that could do code identing
and/or keywords coloring and stuff like that. I'm looking for an editor that
would be just a little more programmer friendly that Wordpad...
Any suggestions?
Thanks!
------------------------------
Date: Mon, 27 Sep 1999 21:57:10 -0400
From: fliptop <fliptop@underwear.peacecomputers.com>
Subject: Re: Do you now an affordable Perl editor for Windows NT
Message-Id: <37F02076.39489A35@underwear.peacecomputers.com>
Eric Dubreuil wrote:
> I just need cheap, freeware or chareware editor that could do code identing
> and/or keywords coloring and stuff like that. I'm looking for an editor that
> would be just a little more programmer friendly that Wordpad...
homesite gets 5 cows on tucows. you didn't mention how much was too
much; it's $89. 30-day trial, too.
fliptop
--
The views expressed above are not necessarily those of anyone else on
the planet.
Email address spam protected; remove underwear to reply.
------------------------------
Date: 28 Sep 1999 01:42:02 GMT
From: lt lindley <ltl@rgsun40.viasystems.com>
Subject: Re: Do you now an affordable Perl editor for Windows NT
Message-Id: <7sp6da$556$1@rguxd.viasystems.com>
Eric Dubreuil <ericdub@sympatico.ca> wrote:
:>I just need cheap, freeware or chareware editor that could do code identing
:>and/or keywords coloring and stuff like that. I'm looking for an editor that
:>would be just a little more programmer friendly that Wordpad...
Real men use vi (or vim). Machoists will tell you to try emacs.
The rest are ignorant sluts. And you really shouldn't post that
kind of question in a perl newgroup unless you are trolling.
You aren't trolling, are you Eric?
--
// Lee.Lindley /// I used to think that being right was everything.
// @bigfoot.com /// Then I matured into the realization that getting
//////////////////// along was more important. Except on usenet.
------------------------------
Date: Mon, 27 Sep 1999 22:13:48 -0400
From: "Bob Wilcox" <bwilcox@eudoramail.com>
Subject: Re: File Upload
Message-Id: <938484960.341318@news.tir.com>
Abigail wrote in message ...
>Bob Wilcox (bwilcox@eudoramail.com) wrote on MMCCXI September MCMXCIII in
><URL:news:937869758.672994@news.tir.com>:
>[] Take a look at http://www.terminalp.com/scripts/
>You post a one-liner, Jeopardy style, quoting 94 lines, including
>the sig? I would call you an idiot, but that would insult a lot
>of idiots.
I wonder how many others have you in their kill file...as I now do...
------------------------------
Date: Mon, 27 Sep 1999 21:02:41 -0700
From: "Yutung Liu" <ytliu@cgi-factory.com>
Subject: fork()?
Message-Id: <7sp7j6$bv2$1@jetsam.uits.indiana.edu>
Can anyone explain what does the following tags do step by step?
$pid = fork();
print "fork failed: $!" unless defined
$pid;
if ($pid) {
Print "the mails have been sent";
exit();
}
else {
close (STDOUT);
--
Your Sincerely,
Yutung L.
------------------------------
Date: Mon, 27 Sep 1999 16:26:57 -0700 (PDT)
From: Michael de Beer <madebeer@igc.apc.org>
Subject: Re: Looking for Downloadscript
Message-Id: <APC&1'0'50775dc9'6b9@igc.apc.org>
in perl, check out the module LWP from www.cpan.org
If you don't need it in perl, ncftpget works well in linux.
-Mike
------------------------------
Date: Mon, 27 Sep 1999 15:07:21 -0700 (PDT)
From: Michael de Beer <madebeer@igc.apc.org>
Subject: Re: pattern matching problem
Message-Id: <APC&1'0'50775dc7'1d5@igc.apc.org>
Greg wrote:
>but if I do:
$type = "MAC";
while(<>) {
..
if ($5 !~ /$type/i) {next; }
..
}
>[it skips all the lines]
My guess is that at the point of comparison, $type is no longer 'MAC'.
Probably due to scoping issues (my, local).
Are you using -w (and maybe use strict)? That would probably warn you if
you are changing scope by accident. You could also inspect type just
before the regexp with
print STDERR "type:$type\n";
HTH
-Michael
------------------------------
Date: Tue, 28 Sep 1999 02:29:59 +0200
From: "Samuel Kilchenmann" <skilchen@swissonline.ch>
Subject: Re: remove the html tag in the file
Message-Id: <7sp2cc$cen$1@news.swissonline.ch>
Dan Sugalski <dan@tuatha.sidhe.org> schrieb in im Newsbeitrag:
_tTH3.1896$Af7.36495@news.rdc1.ct.home.com...
>
> Sorry, old joke. I'm pretty sure you could construct a regex such that
> doing this:
>
> $src =~ s/$c_compiler_regex/$c_compiler_subs/g;
>
> would take $src (as C, or any other, source) and compile it down to an
> object module.
Why do you not start with a try to write such a single regex where $src
first contains HTML and after the substitution contains plain text. For
my part i'm pretty sure that this is impossible.
------------------------------
Date: 27 Sep 1999 19:00:43 -0700
From: merlyn@stonehenge.com (Randal L. Schwartz)
Subject: Re: remove the html tag in the file
Message-Id: <m14sgfg5h0.fsf@halfdome.holdit.com>
>>>>> "Samuel" == Samuel Kilchenmann <skilchen@swissonline.ch> writes:
Samuel> Why do you not start with a try to write such a single regex where $src
Samuel> first contains HTML and after the substitution contains plain text. For
Samuel> my part i'm pretty sure that this is impossible.
s/^//;
HTML *is* plain text. That's part of the beauty of it. :)
print "Just another Perl hacker,"
--
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!
------------------------------
Date: 28 Sep 1999 00:25:42 GMT
From: gbacon@ruby.itsc.uah.edu (Greg Bacon)
Subject: Re: Slice in scalar context
Message-Id: <7sp1u6$9am$1@info2.uah.edu>
In article <x7r9jkylll.fsf@home.sysarch.com>,
Uri Guttman <uri@sysarch.com> writes:
: >>>>> "GB" == Greg Bacon <gbacon@ruby.itsc.uah.edu> writes:
:
: GB> Constant lists change. Consider the idiomatic C code
:
: GB> int array[] = { 1, 2, 4, 8, 16, 32, 64, };
: GB> int powers = sizeof(array) / sizeof(array[0]);
:
: perl doesn't have that.
No kidding.
: arrays ne lists.
Ya think?
: why would you want to count a
: CONSTANT list and not use the list again? in perl it is useless to do
: that.
Can you prove that? Keep in mind that so called constant lists do
change over the lifetime of a program.
: a constant list used as a slice makes sense but to count the
: results of that slice is just wasting your cpu as the results of the
: slice are discarded.
Perhaps, but I don't put anything past Perl programmers. :-)
: GB> It's written this way for maintainability. The same is true of the
: GB> "fine waste of code" that Larry submitted.
:
: in the above line of code. how are the values of fred, barney and wilma
: ever going to be used again? they are lost to the ether, my friend. it
: is pining for the bit bucket. it has been garbage collected. it is an
: ex-list!
What about side effects?
: GB> : also the () in counting the number of elements in a list makes sense,
: GB> : but just counting the number of elements in a slice makes little
: GB> : sense.
:
: GB> Really? Can you prove that it will never be useful?
:
: because the values returned by the slice are thrown away by the (). so
: you might as well count the slice indexes. but that is silly too if
: the indexes are a list of constants.
How will you stop a programmer from changing the code?
: because again they are only in
: that one expression and must be cut and pasted to be used elsewhere.
: can you say "bug waiting to happen"?
Say we're programming in C and have
int array[] = { 1, 2, 4, 8, 16, 32, 64, };
Which of the following would you consider best for holding the number of
elements in array?
int powers = sizeof(array) / sizeof(array[0]);
int powers = 7;
I realize that arrays and lists are different. Keep in mind that Perl's
notion of lists is a little more powerful and useful than C's. Also
note that both C's arrays and Perl's lists aren't resizable.
: GB> What if the number of indices in the slice list changes?
:
: you still throw away data waste computation. remember you have a ()
: there and no assignment of the slice or its indexes.
Side effects?
: so you might as
: well assign a scalar constant to the variable and remove the list
: code.
What if I want to count? What if the list of indices is itself variable?
Greg
--
Reading the FAQ is like staying in line--it's something you should
learn in kindergarten. Usenet needs a better kindergarten.
-- Larry Wall in <1995Nov9.193745.13694@netlabs.com>
------------------------------
Date: 27 Sep 1999 22:41:47 -0400
From: Uri Guttman <uri@sysarch.com>
Subject: Re: Slice in scalar context
Message-Id: <x7g0zzzris.fsf@home.sysarch.com>
>>>>> "GB" == Greg Bacon <gbacon@ruby.itsc.uah.edu> writes:
GB> : why would you want to count a
GB> : CONSTANT list and not use the list again? in perl it is useless to do
GB> : that.
GB> Can you prove that? Keep in mind that so called constant lists do
GB> change over the lifetime of a program.
what does that mean? it is a constant list (1, 2, 3). so how can it
change in the lifetime of the program?
GB> What about side effects?
who mentioned side effects. we are talking about constant lists. keep
the discussion on topic. a constant list is just that. no side effects,
no changing during the lifetime of the program.
GB> : GB> : also the () in counting the number of elements in a list makes sense,
GB> : GB> : but just counting the number of elements in a slice makes little
GB> : GB> : sense.
GB> :
GB> : GB> Really? Can you prove that it will never be useful?
GB> :
GB> : because the values returned by the slice are thrown away by the (). so
GB> : you might as well count the slice indexes. but that is silly too if
GB> : the indexes are a list of constants.
GB> How will you stop a programmer from changing the code?
what does that have to do with a constant list? my point is they can
change it all they want but just counting it (with no side effects) is a
waste as the list is not being used for anything else. keept this
focused to just that one point. why count a constant list?
GB> Say we're programming in C and have
this is perl. who cares how c does it.
GB> int array[] = { 1, 2, 4, 8, 16, 32, 64, };
GB> int powers = sizeof(array) / sizeof(array[0]);
GB> int powers = 7;
but you are assigning that array/list. in the perl example no assignment or
side effects are being done. so you comparison is null and void.
GB> Side effects?
not allowed in constant lists. how often do i have to say this? if there
is a side effect, it is not a constant list.
GB> What if I want to count? What if the list of indices is itself variable?
then you have to either assign it to keep the indices for use later, or
copy the code (bug prone) to recalculate the indices. so again, counting
a list of indices is useless. you either have to have the list for use
again or by putting it in a slice you throw away the data. but here is a
poor counter-example:
$count = () = @array[ &dynamic_list_of_indices ] = &list_of_values ;
horrible code but it does show you the need to count the number of
assigned values. but i think it proves my point all the more. you should
assign the list of indices to an array first and then do the slice
assignment. it is clearer in all ways. and neither list is a constant
list.
uri
--
Uri Guttman ----------------- SYStems ARCHitecture and Software Engineering
uri@sysarch.com --------------------------- Perl, Internet, UNIX Consulting
Have Perl, Will Travel ----------------------------- http://www.sysarch.com
The Best Search Engine on the Net ------------- http://www.northernlight.com
------------------------------
Date: Tue, 28 Sep 1999 01:55:49 GMT
From: Mike Sosteric <mikes@athabascau.ca>
Subject: Sorting weird numeric data
Message-Id: <btanx082.fsf@edlo1.ab.wave.home.com>
How can I sort strings like this
1.1
1.1.1
1.1.2
1.2
1.3
so that I get
1.1
1.1.1
1.1.2
1.2
1.3
and not
1.1
1.1.1
1.1.2
1.2
1.3
as I do with <=>
cmp will not work because then I get
1.1
10.0
which is not what I want
TIA
mike
------------------------------
Date: Mon, 27 Sep 1999 22:34:24 -0400
From: Bob Walton <bwalton@rochester.rr.com>
Subject: Re: Sorting weird numeric data
Message-Id: <37F02930.F3C909C@rochester.rr.com>
Mike Sosteric wrote:
>
> How can I sort strings like this
>
> 1.1
> 1.1.1
> 1.1.2
> 1.2
> 1.3
>
> so that I get
>
> 1.1
> 1.1.1
> 1.1.2
> 1.2
> 1.3
>
> and not
>
> 1.1
> 1.1.1
> 1.1.2
> 1.2
> 1.3
>
> as I do with <=>
>
> cmp will not work because then I get
>
> 1.1
> 10.0
>
> which is not what I want
Mike, try:
@in=<>;
@out=sort byweirdnumbers @in;
print for(@out);
sub byweirdnumbers{
my(@a)=split /\./,$a;
my(@b)=split /\./,$b;
my($v)=0;
for (1..($#a>$#b?$#a:$#b)){
return $v if $v|=$a[$_]<=>$b[$_];
}
return $v;
}
This isn't the most efficient, but works regardless of the depth
of nesting of the numbers.
>
> TIA
>
> mike
--
Bob Walton
------------------------------
Date: Mon, 27 Sep 1999 20:51:59 -0400
From: "Matthew O. Persico" <mpersico@erols.com>
Subject: Re: Suggestion - comp.lang.perl.flame (was Re: You should be admired)
Message-Id: <37F0112F.3957ACB1@erols.com>
Jonathan Stowe wrote:
>
> I have a suggestion. It seems to me that the steady trickle of boring,
> worthy intelligent posts in this group is actually beginning to have
> an impact on the ability of people to actually engage in any really
> worthwhile flaming here - and I am sure that most of the regulars
> would deplore that as being a waste of a potentially excellent resource.
>
> To remedy this I would suggest that we have a new group comp.lang.perl.flame
> which will not be encumbered with any stupid technical stuff about the
> language itself.
Ok, maybe I can't type a decent query into DejaNews, for which I will now
be flamed, but why don't we create a new bit-bucket, er, newsgroup :-)
called
comp.lang.perl.cgi
Wouldn't that draw off a good portion of the noise?
And ff it has been suggested and I missed it, flame away.
--
Matthew O. Persico
"Tell me Larry, what part of this newsgroup _is_ in good taste?" -
Elaine -HFB- Ashton <elaine@chaos.wustl.edu> in comp.lang.perl.misc
------------------------------
Date: Mon, 27 Sep 1999 18:20:16 -0700
From: Phil Doe <ask_for_my_address_if_you_need_it@earthlink.net>
Subject: Re: Trouble with CPAN module
Message-Id: <37F017D0.AF3474C9@earthlink.net>
That doesn't seem to be the problem:
pvoris@localhost ~]$ rpm -q zlib
zlib-1.1.2-2
pvoris@localhost ~]$ su -p
Password:
root@localhost ~]# perl -MCPAN -eshell
cpan shell -- CPAN exploration and modules installation (v1.50)
ReadLine support enabled
cpan> install Compress::Zlib
Compress::Zlib is up to date.
:(
------------------------------
Date: Tue, 28 Sep 1999 01:44:14 GMT
From: ced@bcstec.ca.boeing.com (Charles DeRykus)
Subject: Re: using System function to run other programs
Message-Id: <FIqy5q.4nG@news.boeing.com>
In article <MPG.12558da51e86923989fd7@nntp.hpl.hp.com>,
Larry Rosler <lr@hpl.hp.com> wrote:
>In article <37EBE07A.F7EDA417@mail.cor.epa.gov> on Fri, 24 Sep 1999
>13:35:06 -0700, David Cassell <cassell@mail.cor.epa.gov> says...
>...
>
>That is, if $value is TRUE, replace it with 'replacement'; otherwise
>retain the FALSE value of $value. For example,
>
> print "$n marble", $n != 1 && 's', "\n";
>
>instead of this Golf loser:
>
> print "$n marble", $n != 1 ? 's' : "", "\n";
>
>because the FALSE value '$n != 1' in this case is a null string.
>
So, the null string reminds you of a "Golf" whiff :)
Gratuitous negation should be a much, much greater peeve.
Positives such as
$n > 1 && 's' ,or, even
$n == 1 ? "" : 's"
read far, far better IMO.
Rgds,
--
Charles DeRykus
------------------------------
Date: 16 Sep 99 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 16 Sep 99)
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.
| NOTE: The mail to news gateway, and thus the ability to submit articles
| through this service to the newsgroup, has been removed. I do not have
| time to individually vet each article to make sure that someone isn't
| abusing the service, and I no longer have any desire to waste my time
| dealing with the campus admins when some fool complains to them about an
| article that has come through the gateway instead of complaining
| to the source.
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.
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 V9 Issue 926
*************************************