[16287] in Perl-Users-Digest
Perl-Users Digest, Issue: 3699 Volume: 9
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Jul 17 21:10:29 2000
Date: Mon, 17 Jul 2000 18:10:18 -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: <963882618-v9-i3699@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Mon, 17 Jul 2000 Volume: 9 Number: 3699
Today's topics:
Re: Passing and using multidimensional array references <sumus@aut.dk>
Re: Passing and using multidimensional array references (jason)
Re: Perl and Mysql (Abigail)
Re: Perl can't add ! (Abigail)
Re: Perl can't add ! (Logan Shaw)
Please help me find script... crfr_master@usa.net
Re: Please help me find script... <godzilla@stomp.stomp.tokyo>
problem with socket/webmail client fgont@my-deja.com
Re: Question: system() from C++ CGI to Perl with Kernel (Mark W. Schumann)
Re: Read a file into a hash ? <lr@hpl.hp.com>
Re: Read a file into a hash ? (Logan Shaw)
Re: Read a file into a hash ? (Logan Shaw)
Re: regular expression - html tag-esque pattern <bart.lateur@skynet.be>
Re: Shortcut for non-defined variables (James Weisberg)
String and Hash question...rather urgent <anuragmenon@my-deja.com>
Re: String and Hash question...rather urgent (Logan Shaw)
Re: String and Hash question...rather urgent <sumus@aut.dk>
Re: stupid perl question (Mark W. Schumann)
Re: Suggestion for syntax change <sumus@aut.dk>
Re: Suggestion for syntax change <lr@hpl.hp.com>
Re: Suggestion for syntax change (jason)
Re: Suggestion for syntax change (jason)
Re: Suggestion for syntax change <bart.lateur@skynet.be>
Re: Suggestion for syntax change <sumus@aut.dk>
Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 18 Jul 2000 00:12:25 +0200
From: Jakob Schmidt <sumus@aut.dk>
Subject: Re: Passing and using multidimensional array references
Message-Id: <hf9otnhy.fsf@macforce.sumus.dk>
bchodo@my-deja.com writes:
> sub prog {
> my @array = shift;
this merely puts the array ref you passed as parameter into $array[ 0 ].
> my $array;
I'm not sure what you expected this to do?
> # get element 2,5 of array
> print "This is element 2,5:" . $$array[2][5];
nonono - use the dereference operator -> as in:
$arrayref->[ 2 ][ 5 ];
Cleanup:
sub prog {
my $arrayref = shift;
print "This is element 2,5: $arrayref->[ 2 ][ 5 ]\n";
}
--
Jakob
------------------------------
Date: Mon, 17 Jul 2000 22:33:00 GMT
From: elephant@squirrelgroup.com (jason)
Subject: Re: Passing and using multidimensional array references
Message-Id: <MPG.13de26efa6a158b19896d7@news>
bchodo@my-deja.com wrote ..
>I have a large array that I want to pass to a subroutine. I passed the
>reference (\@array) to keep from having to pass the array, but now I'm
>having trouble accessing individual elements in the file (i.e.)
>I thought that I could do:
>.
>.
>.
>prog(\@array);
here you pass a reference to an array .. a scalar
>sub prog {
>my @array = shift;
here you assign a scalar to an array which will have the effect of
setting the first element of your array to that scalar .. ie. the array
reference from outside will be in $array[0]
you need to realise that an array reference is a scalar .. it is store
in a scalar variable .. take a look at
perldoc perlref
--
jason -- elephant@squirrelgroup.com --
------------------------------
Date: 17 Jul 2000 18:50:32 EDT
From: abigail@delanet.com (Abigail)
Subject: Re: Perl and Mysql
Message-Id: <slrn8n74f0.ibq.abigail@alexandra.delanet.com>
David Fleet (dfleet@avaterra.com) wrote on MMDXII September MCMXCIII in
<URL:news:3972e268_1@nnrp1.news.uk.psi.net>:
## I am having serious problems trying to get my Perl script to connect to my
## Mysql database.
## Has anyone had problems trying to get Perl to access their mysql database?
Yes.
## If so, what did you have to do to correct it?
I fixed the typo in the password.
HTH. HAND.
Abigail
--
perl -wle '$, = " "; sub AUTOLOAD {($AUTOLOAD =~ /::(.*)/) [0];}
print+Just (), another (), Perl (), Hacker ();'
------------------------------
Date: 17 Jul 2000 19:08:45 EDT
From: abigail@delanet.com (Abigail)
Subject: Re: Perl can't add !
Message-Id: <slrn8n75h5.ibq.abigail@alexandra.delanet.com>
jcano@mmcnet.com (jcano@mmcnet.com) wrote on MMDXII September MCMXCIII in
<URL:news:lzlmz1cypc.fsf@mmcnet.com>:
``
`` Now if you need perfect representation combined with irrational
`` numbers you are in trouble.
Algebraic numbers can be represented perfectly in finite amount of memory.
After all, algebraic numbers are roots of finite degree polynooms,
with integer coordinates. The square root of 2 for instance is a root
of f(x):x^2 - 2.
Now, if only I can remember the rules for arithmetic.
Abigail
--
$; # A lone dollar?
=$"; # Pod?
$; # The return of the lone dollar?
{Just=>another=>Perl=>Hacker=>} # Bare block?
=$/; # More pod?
print%; # No right operand for %?
------------------------------
Date: 17 Jul 2000 18:45:22 -0500
From: logan@cs.utexas.edu (Logan Shaw)
Subject: Re: Perl can't add !
Message-Id: <8l05qi$nk2$1@provolone.cs.utexas.edu>
In article <slrn8n75h5.ibq.abigail@alexandra.delanet.com>,
Abigail <abigail@delanet.com> wrote:
>jcano@mmcnet.com (jcano@mmcnet.com) wrote on MMDXII September MCMXCIII in
><URL:news:lzlmz1cypc.fsf@mmcnet.com>:
>``
>`` Now if you need perfect representation combined with irrational
>`` numbers you are in trouble.
>
>
>Algebraic numbers can be represented perfectly in finite amount of memory.
>After all, algebraic numbers are roots of finite degree polynooms,
>with integer coordinates. The square root of 2 for instance is a root
>of f(x):x^2 - 2.
Hmm...
If you can represent them, that's great. But, can you do arithmetic on
them? You can always do things symbolically, but ultimately you may
want to have an actual value for your expression.
Furthermore, it's really handy if the representation of the result of
an operation isn't more complicated than the representation of the
operands. If it is more complicated (or if there isn't an upper bound
on how complicated it'll get), you have the disheartening property that
running time is more than proportional to the number of arithmetic
operations to be performed.
- Logan
------------------------------
Date: Mon, 17 Jul 2000 23:04:13 GMT
From: crfr_master@usa.net
Subject: Please help me find script...
Message-Id: <8l03d2$hoo$1@nnrp1.deja.com>
Hello.
I am searching for a cgi script which can 'hide' or 'cloak' affiliate
links.
There are many websites using this, and the link usually looks like
that or
similiar:
http://www.domain.com/cgi-bin/redirect.cgi?ID=43
Please give me the script name, or place where I can find or buy such
script!
Thank you very much!
Mark R.
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: Mon, 17 Jul 2000 16:24:04 -0700
From: "Godzilla!" <godzilla@stomp.stomp.tokyo>
Subject: Re: Please help me find script...
Message-Id: <39739594.6F08E296@stomp.stomp.tokyo>
crfr_master@usa.net wrote:
> I am searching for a cgi script which can 'hide' or
> 'cloak' affiliate links. There are many websites
> using this, and the link usually looks like
> that or similiar:
> http://www.domain.com/cgi-bin/redirect.cgi?ID=43
> Please give me the script name, or place where I can
> find or buy such script!
Stuff ten crisp c-notes in an envelope
and snail mail them to me. Upon receipt,
I will tell you where you can find this
redirect.cgi script. It's name is kept
a secret for very clear reasons.
Godzilla!
--
$godzilla = "godzilla rocks!";
srand(time() ^ ($$ + ($$ << 15)));
sub randcase
{ rand(40) < 20 ? "\u$1" : "\l$1" ; }
$godzilla =~ s/([a-z])/randcase($1)/gie;
print $godzilla; exit;
------------------------------
Date: Mon, 17 Jul 2000 23:51:46 GMT
From: fgont@my-deja.com
Subject: problem with socket/webmail client
Message-Id: <8l066c$js4$1@nnrp1.deja.com>
Hi!
I've made a cgi-script to be able to read a POP3 account.
I've this problem: When I try to get the "From" line of an e-mail
header, I get only the first content of the "From:" field.
For example, suppose that the header of a message has the following
line:
From: "Fernando Ariel Gont" <fernandogont@softhome.net>
Well, my script will only get "Fernando Ariel Gont" (i.e., it will
not get the string "<fernandogont@softhome.net>").
I thought that the problem was in how I splitted the "From:" line.
But I've found that my cgi-script NEVER GETs the complete line.
That means, when it does a:
$_ = <SOCKFD>;
It gets 'From: "Fernando Ariel Gont"' and not the complete line.
Can any of you help me?
(At the bottom of this message you'll find the source code)
Kind Regards,
Fernando Ariel Gont
e-mail: fgont@SPAMSUCKS.softhome.net
#!/usr/bin/perl
use Socket;
$port = 110;
$ip = ""; # You must set it to the POP3 server IP address
$usr= ""; # You must set it to the POP3 username
$pwd= ""; # You must set it to the POP3 password for username
undef @size;
undef @date;
undef @mid;
undef @from;
undef @to;
undef @subject;
print "Content-type: text/html\n\n";
if(&login() == 0){
print "Successfully logged in!<BR>";
}
if(&listmsgs() == 0){
print "Messages successfully LISTed!<BR>";
}
$nsize = scalar(@size);
&getfields();
if(&logout() == 0){
print "Successfully QUIT from server!<BR>";
}
print "<TABLE>";
for($temp=1; $temp<$nsize; $temp++){
print "<TR><TD>$temp<TD>@from[$temp]<TD>@size[$temp]<TD>@subject
[$temp]</TR>";
}
print "</TABLE></BODY></HTML>";
exit(0);
sub logout(){
print SOCKFD "QUIT\n";
$_= <SOCKFD>;
close (SOCKFD);
if(/\+OK/){
return(0);
}
else{
return(1);
}
}
sub listmsgs(){
print SOCKFD "LIST\n";
$_=<SOCKFD>;
if(/\+OK/){
for($temp=1; ;$temp=$temp+1){
$_= <SOCKFD>;
if(/\.\s+/){
last;
}
else {
($trash, $tam) = split /\s/, $_, 2;
chop($tam);
@size[$temp] = $tam;
}
}
return(0);
}
else{
return(1);
}
}
sub getfields(){
for($temp = 1; $temp<($nsize+1); $temp=$temp+1){
print SOCKFD "TOP $temp 0\n";
$_=<SOCKFD>;
if(/\+OK/){ # TOP command successfully
executed
for($tp=0; ;$tp=$tp+1){
$_= <SOCKFD>;
if(/\A\.\s+/){ # End of header
last;
}
else {
($field, $fvalue) = split /
\s+/, $_, 2;
chop($fvalue);
if($field eq "Date:"){
@date[$temp] = $fvalue;
}
if($field eq "Message-ID:"){
@mid[$temp] = $fvalue;
}
if($field eq "From:"){
@from[$temp] = $fvalue;
}
if($field eq "To:"){
@to[$temp] = $fvalue;
}
if($field eq "Subject:"){
@subject[$temp] = $fvalue;
}
}
}
}
else{
return(1);
}
}
}
sub login(){
unless ($ip_p_address=inet_aton($ip)){
return(1);
}
$packed_address=pack_sockaddr_in ($port, $ip_p_address);
($name, $aliases, $protocol) = getprotobyname('tcp');
unless(socket(SOCKFD, AF_INET, SOCK_STREAM, $protocol)){
return(1);
}
unless(connect(SOCKFD, $packed_address)){
close(SOCKFD);
return(1);
}
select(SOCKFD);
$|=1;
select(STDOUT);
$data= <SOCKFD>;
print SOCKFD "USER $usr\n";
$_= <SOCKFD>;
unless(/\+OK/){
return(1);
}
print SOCKFD "PASS $pwd\n";
$_= <SOCKFD>;
if(/\+OK/){
return(0);
}
else{
return(1);
}
}
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: 17 Jul 2000 20:12:23 -0400
From: catfood@apk.net (Mark W. Schumann)
Subject: Re: Question: system() from C++ CGI to Perl with Kernel 2.2.16
Message-Id: <8l07d7$jd8@junior.apk.net>
In article <3973477B.6ABB6E9D@emory.edu>,
Lisa Wilcox <lwilcox@emory.edu> wrote:
>I've got a C++ CGI making a syscall to a Perl program on a Red Hat Linux
>test server with kernel 2.2.5, and working beautifully. On another
>system where the main difference is the kernel (2.2.16), it doesn't work
>at all. I have combed through all relevant logs in /var/log and there
What do you mean by "doesn't work at all"? Does the Perl program
send no output at all to the browser? Something else?
>are no error messages whatsoever. It appears to be running the Perl
>program, as error messages from its system calls are being logged to
>/var/log/httpd/error_log. I've tried using popen() instead, with no
>success. The C++ CGI compiles cleanly and runs as expected with
>exception of the system call. The Perl program runs as expected when
>run from the command line.
Are you using -w and "use strict"? Those go a long way towards
identifying problems.
Also, are you using the CGI module (as in "use CGI;")? If not, well,
the consensus on this group is that you're just opening a can of worms
by not using it and thus reinventing the wheel.
Read up on the concept of "tainted" data in "man perlsec" too.
Finally, take a look at the Idiot's Guide to Solving Perl CGI Problems.
The "official" site for this seems to be down at the moment, so I'll
just suggest you look for "idiot's perl cgi" or somesuch on a search
engine.
>What's the problem?!?! Is this a security issue? Is this just a bug
>and all I need is a patch? I'm using Perl 5.005_03, glibc 2.1.2-11,
>apache 1.3.12, and compiling with g++. I *really* don't want to embed a
>Perl interpreter because I think its overkill for what I'm trying to
>do. However, if the problem is a security issue blocking the execution,
>either within Apache or the kernel, I would be willing to do it. If
>someone could recommend an example that makes sense, I would appreciate
>it. All I want to do is run the program and have the results print back
>to the user.
Wow... you're proposing a lot of solutions but not giving us much to go
on here. One step at a time.
------------------------------
Date: Mon, 17 Jul 2000 15:33:07 -0700
From: Larry Rosler <lr@hpl.hp.com>
Subject: Re: Read a file into a hash ?
Message-Id: <MPG.13dd297feb3984b098abda@nntp.hpl.hp.com>
In article <k8ektozh.fsf@macforce.sumus.dk> on 17 Jul 2000 23:40:18
+0200, Jakob Schmidt <sumus@aut.dk> says...
...
> Oh and by the way - I think that I ought to have included an explicit close
> too:
>
> close PASSWD;
>
> Far as I can see there's no consensus for checking the success of close()
> (on filehandles). Maybe because finding that it doesn't is just so embarrassing
> that you don't even want to know?
Closing a file opened for reading is pointless, unless another process
or later in this process intends to access it.
Closing a file opened for writing might reveal failure to write the
file, for lack of disk space or other size limits. Intervening print
statements are very seldom checked, so this is the only way.
Closing pipes must be checked, as you seem to know.
--
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com
------------------------------
Date: 17 Jul 2000 18:17:36 -0500
From: logan@cs.utexas.edu (Logan Shaw)
Subject: Re: Read a file into a hash ?
Message-Id: <8l046g$nhk$1@provolone.cs.utexas.edu>
In article <MPG.13dd297feb3984b098abda@nntp.hpl.hp.com>,
Larry Rosler <lr@hpl.hp.com> wrote:
>Closing a file opened for reading is pointless, unless another process
>or later in this process intends to access it.
Or unless the system administrator wants to unmount the disk.
- Logan, a former system administrator
------------------------------
Date: 17 Jul 2000 18:28:49 -0500
From: logan@cs.utexas.edu (Logan Shaw)
Subject: Re: Read a file into a hash ?
Message-Id: <8l04rh$nif$1@provolone.cs.utexas.edu>
In article <8kulco$8ak$1@xs4.xs4all.nl>, Fidelio <rjn@pobox.com> wrote:
>I want to read a file into a hash. I now have code like:
> open(PASSWD, '/etc/passwd');
> while (<PASSWD>) {
> ($login, $passwd, $uid, $gid,
> $gcos, $home, $shell) = split(/:/);
> # do something
> }
If you're just using this as an example, then others' suggestions are
great.
If you really want to see what's in the password file (or database --
NIS, NIS+, LDAP, etc.), then I suggest a completely different approach:
#! /usr/local/bin/perl
use User::pwent;
while ($user = getpwent)
{
printf ("%s's home directory is %s\n", $user->name, $user->dir);
}
Or something like that.
- Logan
------------------------------
Date: Tue, 18 Jul 2000 01:45:05 +0200
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: regular expression - html tag-esque pattern
Message-Id: <v367nscns9otqj4ljq52v8l6k95dkl4gs7@4ax.com>
Blair Heuer wrote:
>What I want to be able to do is use a format of: [out
>name="author"] that can have more than one attribute as well as qouted and
>unqouted values such as: [out name=author value="Not Here"].
>The problem is, I cannot figure out how to search/replace to get the values.
>What I have come up with so far is:
>
> $template =~ s/\[(\w+)\s*(.*)\]/&process($1,$2)/gie;
>Also, if two tags are next to each other, it puts them all as one, any way
>to fix that?
> ([out author][out email] would be read from the first [ to the
>last ] )
Greediness. Replace "(.*)" with "(.*?)".
>Finally, if anyone knows a better way to do this, please tell me.
I would go for a more specific parserlike thingie. For example, you can
check for:
$_ = q[name=author value="Not Here"];
@attributepairs = /(\w+\s*=\s*(?:"[^"]*"|'[^']*'|\w+))/g;
foreach (@attributepairs) {
my($key, $value) = split /\s*=\s*/, $_, 2;
# do something with each $key and $value:
print "$key -> $value\n";
}
You might have to replace the '\w's with a custom, better adapted
character class.
--
Bart.
------------------------------
Date: Tue, 18 Jul 2000 00:42:59 GMT
From: chadbour@wwa.com (James Weisberg)
Subject: Re: Shortcut for non-defined variables
Message-Id: <nKNc5.4338$IZ1.41877@iad-read.news.verio.net>
In article <slrn8msbkv.dun.abigail@alexandra.delanet.com>,
Abigail <abigail@delanet.com> wrote:
>James Weisberg (chadbour@wwa.com) wrote on MMDVIII September MCMXCIII in
><URL:news:Y6mb5.1710$IZ1.13486@iad-read.news.verio.net>:
>~~ Here's an extremely simple Perl question. Is there a shorthand for
>~~ the statement:
>~~
>~~ $val = (defined $val) ? $val : -1;
>~~
>~~ To me, this looks ugly. The || operator is fine for making
>~~ statements like:
>~~
>~~ $val ||= -1;
>~~
>~~ but $val will be set to -1 if $val is 0, which is not what I want
>~~ to do. Have I missed something? I'm surprised there is no way to do
>~~ the equivalent of:
>~~
>~~ $val def= -1;
>~~
>~~ where $val is set to -1 if $val is not defined.
>
>
>That has been beaten to death. Many people want it. Some people don't.
[...]
Sorry. Prior to posting, I didn't know this might touch off some
Perl jihad. I don't get a chance to read this newsgroup on a regular
basis.
Since my original post, as per suggestion, I took a look at the
defconfaq at www.perl.com and familiarized myself with the arguments
that surround the introduction of the ?? operator. As you might expect,
I didn't realize they were as involved as they are. On the surface,
use of a ?? as an initializer almost seems like a natural operator
given the || operator and the rich (perhaps too rich) syntactical
structure already present.
It looks to me that the majority of the debate surrounding the
introduction of the ?? operator centers on its possible misuse in
situations that are non-assigning, like "if ($a ?? $b)" and/or its
use in non-scalar context (@a = @b ?? @c). If this is the case,
then why not restrict use of ?? to only assignment-type operations
in scalar context? One could warn if used otherwise, or flat out
deny its syntax. This seems like an adequate compromise to allow
those who think that:
$a = $b ?? $c ?? $d;
is a much more elegant syntax than what Perl currently offers.
This is my opinion, but I defer to those with a much deeper insight
into the intervals of the matter. Certainly what I must write now
is not *that* unwieldy.
--
World's Greatest Living Poster
------------------------------
Date: Mon, 17 Jul 2000 23:51:52 GMT
From: Vinod K. Menon <anuragmenon@my-deja.com>
Subject: String and Hash question...rather urgent
Message-Id: <8l066h$js5$1@nnrp1.deja.com>
this is probably extremely elementary - but I am kinda new to perl and
am trying to get something done in a hurry and hopefully will get a
speedy reply - anyway, this is what I want to do.
1. Read in a string (String1)
2. Initialize a hash(Hash1) with a set of values
3. for every character in String1 in order from the first to the last,
extract the corresponding value from Hash1 using that character as
they key
4. concatenate the values extracted, in order,with a comma seperateing
the values, to form a new string.
For example if I have initialized the hash as
%hash1 = qw(a "10101"
b "20202");
and the input string is ab,
the output should be "10101,20202"
I am sure the code is very very short..but for some reason, I am really
having problems with it..
I appreciate all help..
Vinod.re
the result of the perl script should be "10101
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: 17 Jul 2000 19:06:38 -0500
From: logan@cs.utexas.edu (Logan Shaw)
Subject: Re: String and Hash question...rather urgent
Message-Id: <8l072e$nne$1@provolone.cs.utexas.edu>
In article <8l066h$js5$1@nnrp1.deja.com>,
Vinod K. Menon <anuragmenon@my-deja.com> wrote:
>this is probably extremely elementary - but I am kinda new to perl and
>am trying to get something done in a hurry and hopefully will get a
>speedy reply - anyway, this is what I want to do.
>
>1. Read in a string (String1)
>2. Initialize a hash(Hash1) with a set of values
>3. for every character in String1 in order from the first to the last,
> extract the corresponding value from Hash1 using that character as
> they key
>4. concatenate the values extracted, in order,with a comma seperateing
>the values, to form a new string.
>
>For example if I have initialized the hash as
>
>%hash1 = qw(a "10101"
> b "20202");
>
>and the input string is ab,
>the output should be "10101,20202"
Step 1:
$string = <>;
chomp $string;
Step 2:
%lookup_table = ( a => "10101", b => "20202" );
Step 3 and 4:
print join (",", @lookup_table{split (//, $string)}), "\n";
Note that my way of doing it uses a special perl feature, which is the
ability to use a list (instead of a single value) as the index to a
hash. I build the list by splitting with an empty pattern. I then
join the results of the array-indexed hash lookup using join() so that
I don't have to worry with appending commas to all but the last element
of a list or something.
- Logan
------------------------------
Date: 18 Jul 2000 02:11:02 +0200
From: Jakob Schmidt <sumus@aut.dk>
Subject: Re: String and Hash question...rather urgent
Message-Id: <8zv0ti09.fsf@macforce.sumus.dk>
Vinod K. Menon <anuragmenon@my-deja.com> writes:
> %hash1 = qw(a "10101"
> b "20202");
using qw() you probably mean
%hash1 = qw( a 10101
b 20202 ); # no extra quotes...
>
> and the input string is ab,
> the output should be "10101,20202"
print join( ',', @hash1{ split( '', $string1 ) } ), "\n";
or
$output = join ',', @hash1{ split( '', $string1 ) };
--
Jakob
------------------------------
Date: 17 Jul 2000 19:53:22 -0400
From: catfood@apk.net (Mark W. Schumann)
Subject: Re: stupid perl question
Message-Id: <8l069i$e85@junior.apk.net>
In article <396B1C42.2F1B027B@hotmail.com>,
EPROM <eprom007@hotmail.com> wrote:
>I find that most man pages are worse than the books (usually). Wouldn't you
>agree?
Leaving aside the question of books being bad, the perl manpages are
extremely detailed and well written. The things you can't learn from
the manpages are, IMO, obscure features that a new Perl programmer is
unlikely to care about.
Start with "man perl" and work your way through the parts that look
interesting when you have a spare hour or two.
------------------------------
Date: 18 Jul 2000 00:41:23 +0200
From: Jakob Schmidt <sumus@aut.dk>
Subject: Re: Suggestion for syntax change
Message-Id: <d7kctm5o.fsf@macforce.sumus.dk>
"Keith G. Murphy" <keithmur@mindspring.com> writes:
> In the following chunk of code:
[...]
> print join(@list[0..-1]) . "\n";
>
> outputting:
[...]
> (blank line)
>
> wouldn't it make more sense if the last line were:
>
> apple,boy,cow
You are aware of course that the .. is an operator in it's own right and not
specifically connected with the indexing of arrays?
Your wish would require that the .. operator behaved in a different manner
when it finds itself used in array indexing than in other contexts. Isn't
that a bit... erm... ugly?
--
Jakob
------------------------------
Date: Mon, 17 Jul 2000 15:40:18 -0700
From: Larry Rosler <lr@hpl.hp.com>
Subject: Re: Suggestion for syntax change
Message-Id: <MPG.13dd2b31426bd50898abdc@nntp.hpl.hp.com>
In article <39738240.AEA38FF1@mindspring.com> on Mon, 17 Jul 2000
17:01:37 -0500, Keith G. Murphy <keithmur@mindspring.com> says...
+ In the following chunk of code:
+
+ my @list = qw(apple boy cow);
+ print $list[0] . "\n";
+ print $list[2] . "\n";
+ print join(',', @list[0..2]) . "\n";
+ print $list[0] . "\n";
+ print $list[-1] . "\n";
+ print join(@list[0..-1]) . "\n";
+
+ outputting:
+
+ apple
+ cow
+ apple,boy,cow
+ apple
+ cow
+ (blank line)
+
+ wouldn't it make more sense if the last line were:
+
+ apple,boy,cow
+
+ ?
+
+ I.e., letting you use the negative subscripts (meaning distance from
+ end of the string) inside a slice range might be rather nice.
The problem is that the scalar range operator .. only counts upwards,
and -1 is less than 0.
One way to do what you want would be to write:
print join(@list[0 .. @list - 1]) . "\n";
--
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com
------------------------------
Date: Mon, 17 Jul 2000 22:49:13 GMT
From: elephant@squirrelgroup.com (jason)
Subject: Re: Suggestion for syntax change
Message-Id: <MPG.13de2aba7199e6a69896d9@news>
Keith G. Murphy wrote ..
>In the following chunk of code:
>
>my @list = qw(apple boy cow);
>print $list[0] . "\n";
>print $list[2] . "\n";
>print join(',', @list[0..2]) . "\n";
>print $list[0] . "\n";
>print $list[-1] . "\n";
>print join(@list[0..-1]) . "\n";
>
>outputting:
>
>apple
>cow
>apple,boy,cow
>apple
>cow
>(blank line)
>
>wouldn't it make more sense if the last line were:
>
>apple,boy,cow
>
>?
>
>I.e., letting you use the negative subscripts (meaning distance from end
>of the string) inside a slice range might be rather nice.
while I disagree that 0..-1 should produce any output - I have often
wondered why the '..' operator doesn't work in both directions (at least
on 5.005_03 on Win32) .. the documentation is vague saying that
"In list context, it returns an array of values counting (by ones)
from the left value to the right value."
which doesn't discount counting from 10 to 1 .. but certainly 10..1
doesn't work .. all of the examples involve increasing values
btw .. my problem with 0..-1 is that it's some sort of special case for
negative numbers and how they relate to arrays .. IMHO $#array..0 should
work
--
jason -- elephant@squirrelgroup.com --
------------------------------
Date: Mon, 17 Jul 2000 23:10:54 GMT
From: elephant@squirrelgroup.com (jason)
Subject: Re: Suggestion for syntax change
Message-Id: <MPG.13de2fd46d79875b9896db@news>
jason wrote ..
>Keith G. Murphy wrote ..
>>In the following chunk of code:
>>
>>my @list = qw(apple boy cow);
>>print $list[0] . "\n";
>>print $list[2] . "\n";
>>print join(',', @list[0..2]) . "\n";
>>print $list[0] . "\n";
>>print $list[-1] . "\n";
>>print join(@list[0..-1]) . "\n";
>>
>>outputting:
>>
>>apple
>>cow
>>apple,boy,cow
>>apple
>>cow
>>(blank line)
>>
>>wouldn't it make more sense if the last line were:
>>
>>apple,boy,cow
>>
>>?
>>
>>I.e., letting you use the negative subscripts (meaning distance from end
>>of the string) inside a slice range might be rather nice.
>
>while I disagree that 0..-1 should produce any output
actually sorry - that's not clear .. I meant that the originator's code
where it used 0..-1 shouldn't produce any output (because the join is
joining $_ which is empty) .. the 0..-1 operator in my new '..' world
when used as I'm sure the originator meant to write ...
print join','=>@list[0..-1];
should produce
apple,cow
in case my other post hasn't surfaced yet .. the new '..' world is one
where '..' works for both incrementing and decrementing between it's
first and second argument .. so @list[0..-1] is the same as @list[0,-1]
--
jason -- elephant@squirrelgroup.com --
------------------------------
Date: Tue, 18 Jul 2000 01:26:56 +0200
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: Suggestion for syntax change
Message-Id: <se57nsctuu3na7uvm2n1i1oequn8vi4t7a@4ax.com>
Jakob Schmidt wrote:
(about ".." inside @ary[0..-1])
>Your wish would require that the .. operator behaved in a different manner
>when it finds itself used in array indexing than in other contexts. Isn't
>that a bit... erm... ugly?
You mean, like context sensitive? Gee, there's a novel idea. No, in Perl
there's absolutely nothing that is context sensitive.
Doh...
--
Bart.
------------------------------
Date: 18 Jul 2000 01:42:27 +0200
From: Jakob Schmidt <sumus@aut.dk>
Subject: Re: Suggestion for syntax change
Message-Id: <aefgtjbw.fsf@macforce.sumus.dk>
Bart Lateur <bart.lateur@skynet.be> writes:
> Jakob Schmidt wrote:
>
> >Your wish would require that the .. operator behaved in a different manner
> >when it finds itself used in array indexing than in other contexts. Isn't
> >that a bit... erm... ugly?
>
> You mean, like context sensitive? Gee, there's a novel idea. No, in Perl
> there's absolutely nothing that is context sensitive.
I deliberately didn't say that. I just asked if this specific example wouldn't
be ugly.
Well, wouldn't it?
--
Jakob
------------------------------
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 3699
**************************************