[17611] in Perl-Users-Digest
Perl-Users Digest, Issue: 5031 Volume: 9
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Dec 4 21:10:30 2000
Date: Mon, 4 Dec 2000 18:10:15 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <975982215-v9-i5031@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Mon, 4 Dec 2000 Volume: 9 Number: 5031
Today's topics:
Re: Sorting the result of a function <jrw32982@my-deja.com>
Re: Sorting the result of a function <jrw32982@my-deja.com>
Re: Sorting the result of a function (Garry Williams)
Re: Sorting the result of a function (Garry Williams)
Re: strings with a minus <johngros@Spam.bigpond.net.au>
Re: strings with a minus (Tad McClellan)
Re: substituting a hash value with a regex? <webqueen@my-deja.com>
Re: substituting a hash value with a regex? <uri@sysarch.com>
Re: substituting a hash value with a regex? (Tad McClellan)
Two dimensional array to file. <johngros@Spam.bigpond.net.au>
Re: Two dimensional array to file. <VincentMurphy@mediaone.net>
Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Mon, 04 Dec 2000 23:06:51 GMT
From: John Wiersba <jrw32982@my-deja.com>
Subject: Re: Sorting the result of a function
Message-Id: <90h827$qav$1@nnrp1.deja.com>
tadmc@metronet.com (Tad McClellan) wrote:
<from the perlfunc docs>
> ... If you use the parentheses, the simple (but occasionally
> surprising) rule is this: It I<looks> like a function, therefore it
> I<is> a function
Except for the universally startling exceptions: It I<looks> like a
function, therefore it's a function name followed by a list. E.g. sort
f(...). That's what's so ugly about this whole discussion: it darn well
looks like a function call, but not to the perl parser.
--
John Wiersba
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: Tue, 05 Dec 2000 00:32:29 GMT
From: John Wiersba <jrw32982@my-deja.com>
Subject: Re: Sorting the result of a function
Message-Id: <90hd2t$ua5$1@nnrp1.deja.com>
Wolfgang Hielscher <W.Hielscher@mssys.com> wrote:
> I do admit that the way perl interprets 'sort f ()' might seem
> counterintuitive at first glance, but thinking about it how should
> perl differentiate
> sort compare_fct @data; # want sort USERSUB LIST
> from
> sort data_modifying_fct @data; # want sort LIST
Well, the basic problem is that these two things look alike.
Unfortunately, that's what you get when you combine "no parentheses
required" syntax with the "direct object" syntax. It's nice to design
languages with unambiguous syntax.
However, since perl already uses quite a bit of DWIM parsing heuristics,
couldn't it make a special case for f(...) and recognize it as a
function call instead of treating it as a direct-object name plus a list
that someone perversely neglected to use whitespace to separate?
> I think the way perl interprets the sort function arguments is a
> little
> "price" to pay for the gain that no parentheses are needed around
> function arguments.
So, get rid of direct objects and use some other mechanism to pass
function names to functions like sort and grep.
> Well, if you think that '+f()' look like f is called in a scalar
> context, then you should read again about the unary plus. I haven't
> found anything that relates unary plus with providing a certain
> context.
This use of unary plus seems quite hackish, a la C++ (i.e. ah, here's a
bit of line noise which doesn't have any other meaning, so let's assign
it some new meaning totally unrelated to any other meanings of the
glyphs involved).
--
John Wiersba
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: Tue, 05 Dec 2000 01:41:35 GMT
From: garry@ifr.zvolve.net (Garry Williams)
Subject: Re: Sorting the result of a function
Message-Id: <jJXW5.576$Xq5.28550@eagle.america.net>
On Mon, 04 Dec 2000 14:34:06 GMT, John Wiersba <jrw32982@my-deja.com>
wrote:
>garry@zvolve.com wrote:
>> >How can I sort the (list) result of a function without assigning
>> >it to a temporary variable? ...
>> >
>> > perl -e 'sub f { (3,2,1) } @a = sort f() ; print "@a\n"'
>>
>> perl -wle 'sub f { (3,2,1) } print join " ", sort +f()'
>>
>> >Why doesn't sort produce the expected result
>>
>> Because sort interprets `f()' as a compare function.
>
>This is way counterintuitive since in virtually every other context,
>f() is a function call, not a function name.
But not with the sort() parameter prototype that is described in
perldoc -f sort:
--> sort SUBNAME LIST
sort BLOCK LIST
sort LIST
Sorts the LIST and returns the sorted list value.
If SUBNAME or BLOCK is omitted, `sort's in standard
string comparison order. If SUBNAME is specified,
it gives the name of a subroutine that returns an
integer less than, equal to, or greater than `0',
depending on how the elements of the list are to be
ordered.
...
Examples:
...
# sort using explicit subroutine name
sub byage {
$age{$a} <=> $age{$b}; # presuming numeric
}
@sortedclass = sort byage @class;
>I understand why &f() might help disambiguate what my intentions are.
>But, it makes no sense to me why +f() should work. It looks like
>+f() is calling the function f in scalar context and applying the
>unary plus operator to the result, but that can't be right.
The `+f()' is a term of a list (which is one element long in this
case). From the perlop manual page:
Terms and List Operators (Leftward)
...
Also note that
print ($foo & 255) + 1, "\n";
probably doesn't do what you expect at first glance.
[But sticking a leading `+' in front of the left parenthesis "fixes"
it to do what you expect.]
...
Symbolic Unary Operators
...
--> Unary "+" has no effect whatsoever, even on strings. It is
useful syntactically for separating a function name from a
parenthesized expression that would otherwise be interpreted
as the complete list of function arguments.
>> See the sort() entry in the perlfunc manual page.
>
>I don't see anything in there referring to this bizarre behavior.
See above; it's the first prototype that is listed.
--
Garry Williams
------------------------------
Date: Tue, 05 Dec 2000 01:44:52 GMT
From: garry@ifr.zvolve.net (Garry Williams)
Subject: Re: Sorting the result of a function
Message-Id: <oMXW5.577$Xq5.28550@eagle.america.net>
On Mon, 04 Dec 2000 14:34:06 GMT, John Wiersba <jrw32982@my-deja.com>
wrote:
>garry@zvolve.com wrote:
>> >How can I sort the (list) result of a function without assigning
>> >it to a temporary variable? ...
>> >
>> > perl -e 'sub f { (3,2,1) } @a = sort f() ; print "@a\n"'
>>
>> perl -wle 'sub f { (3,2,1) } print join " ", sort +f()'
>>
>> >Why doesn't sort produce the expected result
>>
>> Because sort interprets `f()' as a compare function.
>
>This is way counterintuitive since in virtually every other context, f()
>is a function call, not a function name.
`sort f() ...' looks like `sort SUBNAME LIST' while `sort +f() ...'
looks like `sort LIST'.
--
Garry Williams
------------------------------
Date: Tue, 05 Dec 2000 00:39:57 GMT
From: "John Boy Walton" <johngros@Spam.bigpond.net.au>
Subject: Re: strings with a minus
Message-Id: <xPWW5.4248$xW4.39735@news-server.bigpond.net.au>
"Tad McClellan" <tadmc@metronet.com> wrote in message
news:slrn92m06r.jt8.tadmc@magna.metronet.com...
> John Boy Walton <johngros@Spam.bigpond.net.au> wrote:
> >Sorry to be so long with this but probs with my ISP had me shutout of
news.
>
> >"Tad McClellan" <tadmc@metronet.com> wrote in message
> >news:slrn92ga8i.as9.tadmc@magna.metronet.com...
>
>
> Do not expect me to read Jeopardy quoted posts.
>
> I did not read the article I'm following up to, maybe someone
> else can help with whatever it was about.
>
>
> --
> Tad McClellan SGML consulting
> tadmc@metronet.com Perl programming
> Fort Worth, Texas
Tad could you explain "Jeopardy quoted posts"?
If it means top posting rather than bottom someone got up me about that
yesterday.
------------------------------
Date: Mon, 4 Dec 2000 19:14:28 -0500
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: strings with a minus
Message-Id: <slrn92ocr4.m87.tadmc@magna.metronet.com>
John Boy Walton <johngros@Spam.bigpond.net.au> wrote:
>
>"Tad McClellan" <tadmc@metronet.com> wrote in message
>> Do not expect me to read Jeopardy quoted posts.
>> --
>> Tad McClellan SGML consulting
>> tadmc@metronet.com Perl programming
>> Fort Worth, Texas
You should not quote entire articles.
You should not quote .signatures.
>Tad could you explain "Jeopardy quoted posts"?
http://www.geocities.com/nnqweb/nquote.html
--
Tad McClellan SGML consulting
tadmc@metronet.com Perl programming
Fort Worth, Texas
------------------------------
Date: Mon, 04 Dec 2000 23:23:35 GMT
From: webqueen, queen of the web <webqueen@my-deja.com>
Subject: Re: substituting a hash value with a regex?
Message-Id: <90h91g$r04$1@nnrp1.deja.com>
Hmm guess this one was a real puzzler eh?
-WQ
In article <8vmi46$eij$1@nnrp1.deja.com>,
webqueen, queen of the web <webqueen@my-deja.com> wrote:
>
>
> $cat=s/dog/$h{k}/;
> nor
> $cat=s/dog/$h\{k\}/;
>
> produce the desired substitution, and man perlre seems to offer no
> illumination. I'm using:
>
> $h=$h{k};
> $cat=s/dog/$h/;
>
> Surely the gurus herein can enlighten this wayward PerlChild?
>
> --
> Time is nature's way of preventing everything from happening at once.
>
> Sent via Deja.com http://www.deja.com/
> Before you buy.
>
--
Time is nature's way of preventing everything from happening at once.
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: Mon, 04 Dec 2000 23:50:31 GMT
From: Uri Guttman <uri@sysarch.com>
Subject: Re: substituting a hash value with a regex?
Message-Id: <x7zoibwxtl.fsf@home.sysarch.com>
>>>>> "wqotw" == webqueen, queen of the web <webqueen@my-deja.com> writes:
wqotw> Hmm guess this one was a real puzzler eh? -WQ
i never saw the original post. and insulting (even humorously) the
regulars here is not a good idea.
>> $cat=s/dog/$h{k}/; nor $cat=s/dog/$h\{k\}/;
and you don't show any data and results. the former should work fine,
the latter makes no sense.
do you have data in $h{k}?
uri
--
Uri Guttman --------- uri@sysarch.com ---------- http://www.sysarch.com
SYStems ARCHitecture, Software Engineering, Perl, Internet, UNIX Consulting
The Perl Books Page ----------- http://www.sysarch.com/cgi-bin/perl_books
The Best Search Engine on the Net ---------- http://www.northernlight.com
------------------------------
Date: Mon, 4 Dec 2000 18:12:23 -0500
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: substituting a hash value with a regex?
Message-Id: <slrn92o96n.m5a.tadmc@magna.metronet.com>
webqueen, queen of the web <webqueen@my-deja.com> wrote:
>Hmm guess this one was a real puzzler eh?
Perhaps if you used the correct operators it would
errr, operate more like you expect?
>In article <8vmi46$eij$1@nnrp1.deja.com>,
> webqueen, queen of the web <webqueen@my-deja.com> wrote:
>>
>>
>> $cat=s/dog/$h{k}/;
^
$cat =~ s/dog/$h{k}/;
^^
>> nor
>> $cat=s/dog/$h\{k\}/;
That one is nonsense, even if it did use the correct binding operator.
>> produce the desired substitution, and man perlre seems to offer no
>> illumination. I'm using:
>>
>> $h=$h{k};
>> $cat=s/dog/$h/;
^^^
That doesn't work either, but you seem to be saying that it
_does_ work. Is that what you are saying?
--
Tad McClellan SGML consulting
tadmc@metronet.com Perl programming
Fort Worth, Texas
------------------------------
Date: Tue, 05 Dec 2000 01:56:27 GMT
From: "John Boy Walton" <johngros@Spam.bigpond.net.au>
Subject: Two dimensional array to file.
Message-Id: <fXXW5.4298$xW4.40830@news-server.bigpond.net.au>
I have been trying to write a two dimensional array to file.
I have tried writing each of the elements into one array and writing the
array and I have tried coalescing the second dimension arrays into an array
and writing the array. The closest I have gotten is having the file read
ARRAY(0x176f194)
My code is as follows: # I have not used strict because it causes a need for
declaring a package name and I could not figure it out.
#!e:/millenium programs/perl/bin/perl -w
$path = "C:/Program Files/G6FTP/";
$file = $path."Users.ini";
open BOGUS,"$file";
$array = 0;
while (<BOGUS>){
if (/\[/){
$flag = 1;
$i = 0;
print $_;
}elsif (/^\$/){
$flag = 0;
$temp = $data[$array][2];
$temp =~ s/Pass=//;
if ({time - $temp} / 86400 < 31){
$array++;
}
}elsif ($flag){
$data[$array][$i] = $_;
$i++;
}
}
open BOGUS,">$file";
for ($array = 0; $array < @data; $array++){
@temp = (@temp, $data[@array], "\n");
}
foreach $line (@temp){
print BOGUS $line;
}
close BOGUS;
------------------------------
Date: Tue, 05 Dec 2000 02:04:45 GMT
From: Vinny Murphy <VincentMurphy@mediaone.net>
Subject: Re: Two dimensional array to file.
Message-Id: <m3ofyrpo0k.fsf@vmurphy-hnt1.athome.net>
John> I have been trying to write a two dimensional array to file.
John> I have tried writing each of the elements into one array and writing the
John> array and I have tried coalescing the second dimension arrays into an array
John> and writing the array. The closest I have gotten is having the file read
John> ARRAY(0x176f194)
Use the Data::Dumper module.
perldoc Data::Dumper
to dump the data structure you do
print FILEHANDLE Dumper( \@array_of_array);
to get it back you would do an eval on the data in the file.
HTH.
-vjm
------------------------------
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 5031
**************************************