[19421] in Perl-Users-Digest
Perl-Users Digest, Issue: 1616 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sun Aug 26 09:05:32 2001
Date: Sun, 26 Aug 2001 06:05:11 -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: <998831111-v10-i1616@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Sun, 26 Aug 2001 Volume: 10 Number: 1616
Today's topics:
Re: $1 as subroutine parameter - problems <bart.lateur@skynet.be>
Re: Check subroutine data from other process <cave@pertus.com.pl>
Re: Check subroutine data from other process <ilya@martynov.org>
Re: Dropping array duplicate values <goldbb2@earthlink.net>
Re: Editor Question <gnarinn@hotmail.com>
Re: Extract the relative sorting of items from multiple (Abigail)
Re: How to copy MID, GIF, JPEG files correctly? <pne-news-20010826@newton.digitalspace.net>
Re: Is element in array (Tim Hammerquist)
It's to AM for me to think <hafatel@netpci.com>
Re: It's to AM for me to think (Logan Shaw)
Re: It's to AM for me to think <Tassilo.Parseval@post.rwth-aachen.de>
Re: It's to AM for me to think <bcaligari@fireforged.com>
Re: It's to AM for me to think <gnarinn@hotmail.com>
Re: one character at a time (Yves Orton)
Re: one character at a time (Yves Orton)
Re: Openning a file (Abigail)
Re: Openning a file <Tassilo.Parseval@post.rwth-aachen.de>
Re: Openning a file <pne-news-20010826@newton.digitalspace.net>
Re: Openning a file <pne-news-20010826@newton.digitalspace.net>
Re: pl or not pl, that is the question (Tim Hammerquist)
Re: pl or not pl, that is the question (Tim Hammerquist)
Problems with fixed-length random access databases. <dscarlett@optushome.com.au>
Re: Problems with fixed-length random access databases. <dscarlett@optushome.com.au>
Re: Problems with fixed-length random access databases. <gnarinn@hotmail.com>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Sun, 26 Aug 2001 09:16:19 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: $1 as subroutine parameter - problems
Message-Id: <l6fhot065nkk90ep6k511kdjb4u9n59go2@4ax.com>
Markus Laire wrote:
>When I use $1 as parameter to subroutine, which does some regexp for that
>parameter and then tries to use parameter again, it is changed by that
>regexp because $_[0] seems to reference $1 which was given as parameter.
Eh, yes. That is the problem with local() on global variables.
>I can avoid this problem by calling subroutine as test(my $temp = $1)
>instead of test($1).
>
>My question is then: Is there any other (more elegant/better ?) way to
>counter this problem than to create a temporary scalar ?
test("$1")
will make a temporary copy of it.
>I know that 'my ($param) = @_;' in subroutine avoids this problem, but I
>want it to be optimized and tight.
>This is illustrated by the following example.
>sub test($) {
> $_[0] =~ /(...)/;
> print "Begin: $1 of $_[0]\n";
>}
That's not "optimised an tight". Even though you make no copy of the
original argument, you do "calculate" the index of the argument (0), and
get that element from the array, twice. A straight scalar likely is
faster. A bit.
Yes, you do look like you're searching into micro-optimizations. As
Abigail would say: if execution speed matters that much to you, you
shouldn't be using Perl.
--
Bart.
------------------------------
Date: Sun, 26 Aug 2001 09:09:44 +0200
From: Mirek Rewak <cave@pertus.com.pl>
Subject: Re: Check subroutine data from other process
Message-Id: <mt6hot8in0foajeb10djccc2fjrqb2f84a@4ax.com>
On 25 Aug 2001 18:49:02 +0400, Ilya Martynov <ilya@martynov.org>
wrote:
>Look here:
>
>while(1) {
> my $state =3D check_state;
>
> if($state) {
> do_something
> }
>}
>
>This is simplified representation of your skelet of main
>program. Since most time $state is false this loop is just empty
>loop. It will consume all available CPU time.
I know, but do I have to worry about it (it is normal?)? Or maybe it
can be done in other way, in which process will get less processor
time. I dont' want that may program consume all available resources.
Maybe I should let the process to block on select and to "long time
processing" fork other process (but there be other problem with
exchange data between forked process and forking process).
PS I thoght also about simplest solution: create a file, to which long
time process will update its status, other processes will read the
file. But how updating a file in loop in the best way? In loop I'will
have to always opening and flocking, because of that other processes
wil have a chance to read it. Is there a=20
Thanks for your answers.
Pozdrowienia
Mirek Rewak
cave@pertus.com.pl
------------------------------
Date: 26 Aug 2001 13:10:58 +0400
From: Ilya Martynov <ilya@martynov.org>
Subject: Re: Check subroutine data from other process
Message-Id: <87n14np4nx.fsf@abra.ru>
>>>>> On Sun, 26 Aug 2001 09:09:44 +0200, Mirek Rewak <cave@pertus.com.pl> said:
MR> I know, but do I have to worry about it (it is normal?)? Or maybe it
MR> can be done in other way, in which process will get less processor
MR> time. I dont' want that may program consume all available resources.
MR> Maybe I should let the process to block on select and to "long time
MR> processing" fork other process (but there be other problem with
MR> exchange data between forked process and forking process).
Of course program which takes 100% CPU doing nothing is not ok. Your
program should have such logic that it will consume CPU only when it
requires it. You supposed to add some data processing into the body of
cycle. Right? Should it run all time and take CPU? Then it is ok to
take 100% by this data processing. If you don't need to do data
processing all time in your program but only do it on some external
event then use blocking select (i.e. select with timeout). If for some
periods your program should do data processing but in some periods it
should wait for external events then switch blocking and non-blocking
select when it is required.
MR> PS I thoght also about simplest solution: create a file, to which long
MR> time process will update its status, other processes will read the
MR> file. But how updating a file in loop in the best way? In loop I'will
MR> have to always opening and flocking, because of that other processes
MR> wil have a chance to read it. Is there a
You can do IPC via file as long as all processes flock it and your OS
and filesystem support it. But beware: your code will have almost same
loop (while(1) { check_if_file_changed; ....} ) and you will have to
deal with same problem (i.e. consume CPU only when it is required).
--
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
| Ilya Martynov (http://martynov.org/) |
| GnuPG 1024D/323BDEE6 D7F7 561E 4C1D 8A15 8E80 E4AE BE1A 53EB 323B DEE6 |
| AGAVA Software Company (http://www.agava.com/) |
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
------------------------------
Date: Sun, 26 Aug 2001 03:32:36 -0400
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: Dropping array duplicate values
Message-Id: <3B88A614.915E9AAD@earthlink.net>
Paul Schnell wrote:
>
> Hi, The following sub takes input via a post from an
> HTML form using CGI.pm, picks up all params whose
> keys start with 'band_' and maps the values to @new,
> drops any duplicates and then saves results. It works
> fine but I was wondering if there is a way of checking
> for duplicates without the %seen and grep line.
>
> ...just out of interest.
>
> my $cgi = new CGI;
>
> sub update {
>
> my @new = map { $cgi->param($_) if /^band_/ } $cgi->param;
>
> # drop duplicates [Perl Cookbook]
> my %seen;
> @new = grep { !$seen{$_}++ } @new;
> save_bands( \@new );
> }
Sounds to me like you've got a bunch of fields, some of which start with
"band_", and you want to print just those... However, when you did the
map, you ended up with a bunch of undef values in @new, and you want to
get rid of all of them.
The solution is *not* to do a uniqifiying operation on the result.
The solution is to not get all those undefs in the first place, buy
doing the grep before the map, rather than after.
sub update {
save_bands( \
map { $cgi->param($_) },
grep /^band_/, $cgi->param()
);
}
Note that the \ there is *not* there to indicate a continuation of the
line, but to take a reference to the array which is returned.
You may want to keep the keys in the list there, so you can use it as a
hash:
sub update {
save_bands( {
map { $_ => $cgi->param($_) },
grep /^band_/, $cgi->param()
} );
}
Here, update will get one argument, a hashref, which have band_* items
as keys, and cgi params as values.
If you really did want to do a uniq type operation on the *values* of
the params, then you might do it as something like this:
save_bands( \do { my %seen;
grep !$seen{$_}++,
map { $cgi->param($_) },
grep { /^band_/ }, $cgi->param()
} );
You still need to grep with %seen, but the do-block limits the scope of
it to as small as possible.
--
I'm not a programmer but I play one on TV...
------------------------------
Date: Sun, 26 Aug 2001 09:46:31 +0000
From: gnari <gnarinn@hotmail.com>
Subject: Re: Editor Question
Message-Id: <998819191.91251528263092.gnarinn@hotmail.com>
In article <998792003.911558@elaine.furryape.com>,
Alan Barclay <gorilla@elaine.furryape.com> wrote:
>In article <998686028.740761307999492.gnarinn@hotmail.com>,
>gnari <gnarinn@hotmail.com> wrote:
>>In article <_Huh7.797$qq2.382426@typhoon1.gnilink.net>,
>>Mark Riehl <mark.riehl@agilecommunications.com> wrote:
>>>All - Anyone using XEmacs? I'm running 21.4p3 on Win2k, and it is having
>>>fits with the indents on the following code. I can't seem to get it right,
>>>can't find a matching brace, etc.
>>
>>but that is because there your braces dont match, because braces
>>in strings are not matched. your real problem is that your quotes
>>do not match and you have what is call a runaway multi-line string.
>>
>>> # print RESULTS "Accuracy:
>>>${$RxTxData{$key}{statistics}{$key2}}[1]\n";
>> ^
>> a string starts here ------------------^
>
>No it doesn't. You missed the " on the previous line.
i did not miss it. the parser missed it, because the previous line is
commented out. i quoted that line too, so i thought that would be obvious
i believe i also suggested testing the code with 'perl -wc', which
would have shown the code to be invalid and given clues.
gnari
------------------------------
Date: 26 Aug 2001 11:46:16 GMT
From: abigail@foad.org (Abigail)
Subject: Re: Extract the relative sorting of items from multiple lists
Message-Id: <slrn9ohocf.o74.abigail@alexandra.xs4all.nl>
Steven Smolinski (steven.smolinski@sympatico.ca) wrote on MMCMXVII
September MCMXCIII in <URL:news:S__h7.62610$wX5.4893352@news20.bellglobal.com>:
'' Abigail <abigail@foad.org> wrote:
'' >
'' > Knuth has been working at Stanford for decades. He has had a website
'' > for eons. He has announced his plans for Volume 4 and how he will make
'' > it available for at least 5 years on his website.
''
'' Plus, for those of us peripherally interested, there was a story on
'' slashdot. ;-)
Yeah, but who would want to admit to reading slashdot?
Abigail
--
perl -le 's[$,][join$,,(split$,,($!=85))[(q[0006143730380126152532042307].
q[41342211132019313505])=~m[..]g]]e and y[yIbp][HJkP] and print'
------------------------------
Date: Sun, 26 Aug 2001 14:41:44 +0200
From: Philip Newton <pne-news-20010826@newton.digitalspace.net>
Subject: Re: How to copy MID, GIF, JPEG files correctly?
Message-Id: <fjrhotsnumftursejpauln65dndmk2e2ln@4ax.com>
On Sun, 26 Aug 2001 06:46:26 GMT, Zoom Zoom Zoom <satnic@home.com>
wrote:
> binmode did the trick.
Congratulations.
(I still recommend File::Copy, however.)
Cheers,
Philip
--
Philip Newton <nospam.newton@gmx.li>
That really is my address; no need to remove anything to reply.
If you're not part of the solution, you're part of the precipitate.
------------------------------
Date: Sun, 26 Aug 2001 10:49:09 GMT
From: tim@vegeta.ath.cx (Tim Hammerquist)
Subject: Re: Is element in array
Message-Id: <slrn9ohln5.1j1.tim@vegeta.ath.cx>
Me parece que Guy <guymal@__NOSPAM__hotmail.com> dijo:
> How can test a scalar to see if it is an element in a given array?
> Example:
> @bla=("one","two","three");
>
> if ("two" IS IN @bla) #returns true
> {
> #this code would be executed
> ....
> }
>
> if ("four" IS IN @bla)#returns false
> {
> #this code would not be executed
> }
You have three basic choices:
1. grep the list; often inefficient
2. foreach loop -> last at match; more efficient.
3. more complex algorithm, esp. if list/array is sorted
For example, here's the output of a simple program profiling 3 search
algorithms. The code follows.
You'll notice that the binary search ranges between 14 and 16 iterations
before finding the target word. Note that even doubling the size of the
array will only increase the necessary iterations by one. (ie, it will
search a list of 90,000 words in 15-17 iterations average) The largest
drawback to the binary search is it only works on sorted lists, and it's
not worth implementing on some smaller lists.
$ profile_search machine zoom apple
Dictionary is '/usr/dict/words' (45402 words)
Searching for 'machine'...
grep = 45402 elements searched
break = 24972 elements searched
binary = 15 elements searched
Searching for 'zoom'...
grep = 45402 elements searched
break = 45394 elements searched
binary = 14 elements searched
Searching for 'apple'...
grep = 45402 elements searched
break = 2310 elements searched
binary = 15 elements searched
$ cat profile_search
#!/usr/bin/perl -w
my $dictfile = '/usr/dict/words';
my $dict;
open DICT, "< $dictfile" or die;
chomp(@$dict = <DICT>);
close DICT or die;
my $word_count = scalar @$dict;
print "Dictionary is '$dictfile' ($word_count words)\n";
for my $target (@ARGV) {
local @_ = ($target, $dict);
print <<EOT;
Searching for '$target'...
grep = @{[&test_grep]} elements searched
break = @{[&test_last]} elements searched
binary = @{[&test_binary]} elements searched
EOT
}
sub test_grep {
my ($count, $target, $dict) = (0, @_);
grep {$count++ and $_ eq $target} @$dict;
$count;
}
sub test_last {
my ($count, $target, $dict) = (0, @_);
for (@$dict) {
$count++;
last if $_ eq $target;
}
$count;
}
sub test_binary {
use integer;
my ($target, $dict) = @_;
my ($count, $min, $max) = (0, 0, @$dict - 1);
while ($min <= $max) {
$count++;
my $idx = ($min + $max) / 2;
my $cur = lc($dict->[$idx]);
return $count if $cur eq $target;
$min = $idx + 1 and next if $cur lt lc($target);
$max = $idx - 1 and next if $cur gt lc($target);
return -2;
}
return -1;
}
--
C combines all the power of assembly language with all
the ease of use of assembly language.
-- trad
------------------------------
Date: Sun, 26 Aug 2001 17:16:22 +1000
From: "Michael McPherson Pierotti" <hafatel@netpci.com>
Subject: It's to AM for me to think
Message-Id: <9ma9fe02asm@enews4.newsguy.com>
I need to figure out what item in a list has the greatest value.
my $item;
my $times = 0;
for $item(@total_time){
$times = $item + $times;
}
my $min = $times / 60;
print "\nTotal Minutes Billed = $min\n";
This code gives me a total but I need to figure out which item in the array
has the greatest value.
TYIA
------------------------------
Date: 26 Aug 2001 03:28:15 -0500
From: logan@cs.utexas.edu (Logan Shaw)
Subject: Re: It's to AM for me to think
Message-Id: <9mabuv$1o0$1@charity.cs.utexas.edu>
In article <9ma9fe02asm@enews4.newsguy.com>,
Michael McPherson Pierotti <hafatel@netpci.com> wrote:
>I need to figure out what item in a list has the greatest value.
Just go through each item in the list. Keep track of the largest one
you've seen so far, and if you see something larger, record it as the
largest one you've seen, and then keep going:
$largest = undef;
foreach my $item (@list)
{
if (not defined $largest)
{
$largest = $item;
next;
}
$largest = $item if $item > $largest;
}
Hope that helps.
- Logan
--
"Our grandkids love that we get Roadrunner and digital cable."
(Advertisement for Time Warner cable TV and internet access, July 2001)
------------------------------
Date: Sun, 26 Aug 2001 10:34:39 +0200
From: Tassilo von Parseval <Tassilo.Parseval@post.rwth-aachen.de>
Subject: Re: It's to AM for me to think
Message-Id: <3B88B49F.5010200@post.rwth-aachen.de>
Logan Shaw wrote:
> In article <9ma9fe02asm@enews4.newsguy.com>,
> Michael McPherson Pierotti <hafatel@netpci.com> wrote:
>
>>I need to figure out what item in a list has the greatest value.
>>
>
> Just go through each item in the list. Keep track of the largest one
> you've seen so far, and if you see something larger, record it as the
> largest one you've seen, and then keep going:
And why not just sort it?
$largest = (sort { $b <=> $a } @a) [0];
Admittedly, this may be slower on very large arrays - O(n log(n)) -
while yours is O(n)....though I am not sure whether Perl's optimizations
would make up for that.
Tassilo
--
$a=[(74,116)];$b=[($a->[1]-1,$a->[1]++,0x20)];$c=[(97,110)];$d=[($c->
[1]+1,$b->[1],"her")];for(@{[$a,$b,$c,$d]}){for(@{$_}){$_=~/\d+/?print
(chr($_)):print;}}$c=sub{$l=shift;[(0x20+$l-1,0x50,0x65,0x73-0x01,108
),(0x20,0x68,0x61,)]};print(map{chr($_)}@{($c->(1))});$h={a=>33*3,b=>
10**2+7,c=>"1"."0"."1",d=>0162};@h=sort(keys(%$h));for(@h){print(chr(
ord(chr($h->{$_}))))};
------------------------------
Date: Sun, 26 Aug 2001 08:58:06 -0000
From: "Brendon Caligari" <bcaligari@fireforged.com>
Subject: Re: It's to AM for me to think
Message-Id: <9madb306hr@enews1.newsguy.com>
"Michael McPherson Pierotti" <hafatel@netpci.com> wrote in message
news:9ma9fe02asm@enews4.newsguy.com...
> I need to figure out what item in a list has the greatest value.
>
> my $item;
> my $times = 0;
my $highest = 0;
> for $item(@total_time){
> $times = $item + $times;
$highest = $item if ($item > $highest);
> }
>
> my $min = $times / 60;
> print "\nTotal Minutes Billed = $min\n";
This is assuming that all your values are > 0
B
------------------------------
Date: Sun, 26 Aug 2001 12:06:41 +0000
From: gnari <gnarinn@hotmail.com>
Subject: Re: It's to AM for me to think
Message-Id: <998827601.317737208679318.gnarinn@hotmail.com>
In article <9ma9fe02asm@enews4.newsguy.com>,
Michael McPherson Pierotti <hafatel@netpci.com> wrote:
>I need to figure out what item in a list has the greatest value.
>
>my $item;
>my $times = 0;
>for $item(@total_time){
> $times = $item + $times;
>}
>
>my $min = $times / 60;
>print "\nTotal Minutes Billed = $min\n";
>
>This code gives me a total but I need to figure out which item in the array
>has the greatest value.
what have you tried?
as you loop through the items, just compare the value with the highest
value you have seen so far. if it is higher, then that is the higest so far.
gnari
------------------------------
Date: 26 Aug 2001 05:22:47 -0700
From: demerphq@hotmail.com (Yves Orton)
Subject: Re: one character at a time
Message-Id: <74f348f7.0108260422.e14bb09@posting.google.com>
"Godzilla!" <godzilla@stomp.stomp.tokyo> wrote in message news:<3B882097.75967D96@stomp.stomp.tokyo>...
> Bart Lateur wrote:
>
> > Godzilla! wrote:
>
> > >$string = "my little string";
>
> > $string = '543210';
>
> > >do
> > > { print substr ($string, 0, 1, ""), "¦"; }
> > >until (!$string);
>
> > So where's my zero?
>
> > Checking length($string) is safer.
>
>
> Irrelevant. Your comments do not comply with
> the originating author's stated parameters.
Godzilla. Is it really that hard for you to say something like:
'Oh! Good point. Thanks,'
??????
Yves
------------------------------
Date: 26 Aug 2001 05:41:32 -0700
From: demerphq@hotmail.com (Yves Orton)
Subject: Re: one character at a time
Message-Id: <74f348f7.0108260441.24f3c04@posting.google.com>
Dave Tweed <dtweed@acm.org> wrote in message news:<3B881426.12703264@acm.org>...
> Ken wrote:
> > I have the string "my little string". I need to loop through and pull
> > out first the 'm', then the 'y', then the ' ', then the 'l', etc.
>
> TIMTOWTDI:
>
> for $ch (unpack ('C*', $string)) {
> # do whatever with $ch
> }
> This is probably the most efficient option.
Yes I believe so. I have modified the lizards test script to use your
version, her fixed version (with length()) and the regexp one from
Ben. The unpack is by far the fastest.
Incidentally I really dont trust whatever Benchmark does to determine
'wallclock' seconds. Consider the lines (n= stuff removed)
substr: 4 wallclock secs ( 4.25 usr + 0.00 sys = 4.25 CPU) @
23546.03/s
unpack: 4 wallclock secs ( 3.22 usr + 0.00 sys = 3.22 CPU) @
31007.75/s
So they both show 4 wallclock seconds, even though unpack is more than
a second faster. And then from the second run
substr: 4 wallclock secs ( 4.22 usr + 0.00 sys = 4.22 CPU) @
23713.54/s
unpack: 2 wallclock secs ( 3.23 usr + 0.00 sys = 3.23 CPU) @
31007.75/s
This time the unpack is 0.01 seconds longer, but shows TWO full
wallclock seconds less than substr. This is a bug I am sure.
Yves
#!perl
use strict;
use warnings;
use Benchmark 'cmpthese';
for (qw(One Two Three)) {
print "\nRun $_:\n";
Time(100_000);
}
sub Time {
my $count=shift;
cmpthese ($count,
{
'substr' =>sub {
my $string = "my little 0 string";
my @output;
push @output,substr ($string, 0, 1, "")
while length($string);
},
'regexp' =>sub{
my $string = "my little 0 string";
my @output;
push @output,$1
while ($string=~/(.)/gs );
},
'unpack' =>sub{
my $string = "my little 0 string";
my @output;
push @output,$_
foreach (unpack ("C*", $string));
},
} );
}
__END__
Run One:
Benchmark: timing 100000 iterations of regexp, substr, unpack...
regexp: 8 wallclock secs ( 7.65 usr + 0.00 sys = 7.65 CPU) @
13070.19/s (n=100000)
substr: 4 wallclock secs ( 4.25 usr + 0.00 sys = 4.25 CPU) @
23546.03/s (n=100000)
unpack: 4 wallclock secs ( 3.22 usr + 0.00 sys = 3.22 CPU) @
31007.75/s (n=100000)
Rate regexp substr unpack
regexp 13070/s -- -44% -58%
substr 23546/s 80% -- -24%
unpack 31008/s 137% 32% --
Run Two:
Benchmark: timing 100000 iterations of regexp, substr, unpack...
regexp: 8 wallclock secs ( 7.54 usr + 0.00 sys = 7.54 CPU) @
13260.84/s (n=100000)
substr: 4 wallclock secs ( 4.22 usr + 0.00 sys = 4.22 CPU) @
23713.54/s (n=100000)
unpack: 2 wallclock secs ( 3.23 usr + 0.00 sys = 3.23 CPU) @
31007.75/s (n=100000)
Rate regexp substr unpack
regexp 13261/s -- -44% -57%
substr 23714/s 79% -- -24%
unpack 31008/s 134% 31% --
Run Three:
Benchmark: timing 100000 iterations of regexp, substr, unpack...
regexp: 8 wallclock secs ( 7.60 usr + 0.00 sys = 7.60 CPU) @
13156.16/s (n=100000)
substr: 5 wallclock secs ( 4.23 usr + 0.00 sys = 4.23 CPU) @
23612.75/s (n=100000)
unpack: 3 wallclock secs ( 3.21 usr + 0.00 sys = 3.21 CPU) @
31104.20/s (n=100000)
Rate regexp substr unpack
regexp 13156/s -- -44% -58%
substr 23613/s 79% -- -24%
unpack 31104/s 136% 32% --
------------------------------
Date: 26 Aug 2001 11:43:54 GMT
From: abigail@foad.org (Abigail)
Subject: Re: Openning a file
Message-Id: <slrn9oho81.o74.abigail@alexandra.xs4all.nl>
Tassilo von Parseval (Tassilo.Parseval@post.rwth-aachen.de) wrote on
MMCMXVI September MCMXCIII in <URL:news:3B882A37.70806@post.rwth-aachen.de>:
:: Abigail wrote:
::
:: [lists allegedly in scalar context]
::
:: > Perhaps there can be. You know, in a debate "no, it can't", "yes, it can",
:: > the person argueing the "yes, it can" case has a real big advantage over
:: > the "no, it can't" person.
:: >
:: > All the person needs to do is come with an example. Just one.
:: >
:: > I'm waiting.
::
:: Well, there was this qw() example. You can assign that to a scalar
:: variable. This eventually assigns the last element of this list to this
:: variable. But, alas, I am no longer so sure about it whether one could
:: call this scalar context after flicking through some perldocs and doing
:: some quick tests.
It's scalar context alright. But what you have isn't a list, it's a
comma operator. But that was pointed out before, wasn't it?
Abigail
--
$_ = "\nrekcaH lreP rehtona tsuJ"; my $chop; $chop = sub {print chop; $chop};
$chop -> () -> () -> () -> () -> () -> () -> () -> () -> () -> () -> () -> ()
-> () -> () -> () -> () -> () -> () -> () -> () -> () -> () -> () -> () -> ()
------------------------------
Date: Sun, 26 Aug 2001 14:08:21 +0200
From: Tassilo von Parseval <Tassilo.Parseval@post.rwth-aachen.de>
Subject: Re: Openning a file
Message-Id: <3B88E6B5.2010900@post.rwth-aachen.de>
Abigail wrote:
> It's scalar context alright. But what you have isn't a list, it's a
> comma operator. But that was pointed out before, wasn't it?
Yes, and now it should be eot. I think it was you who suggested to send
a patch concerning the perlop-entry on qw() as for claiming this to be a
'true list'. That was the only reason for my confusion as I stumbled
over the contradictory things that the FAQ and perlop said.
So long, let us be bound for new issues now!
Tassilo
--
$a=[(74,116)];$b=[($a->[1]-1,$a->[1]++,0x20)];$c=[(97,110)];$d=[($c->
[1]+1,$b->[1],"her")];for(@{[$a,$b,$c,$d]}){for(@{$_}){$_=~/\d+/?print
(chr($_)):print;}}$c=sub{$l=shift;[(0x20+$l-1,0x50,0x65,0x73-0x01,108
),(0x20,0x68,0x61,)]};print(map{chr($_)}@{($c->(1))});$h={a=>33*3,b=>
10**2+7,c=>"1"."0"."1",d=>0162};@h=sort(keys(%$h));for(@h){print(chr(
ord(chr($h->{$_}))))};
------------------------------
Date: Sun, 26 Aug 2001 14:37:38 +0200
From: Philip Newton <pne-news-20010826@newton.digitalspace.net>
Subject: Re: Openning a file
Message-Id: <3brhot0vdqcldevl8k2vocc0opef6btoja@4ax.com>
On 23 Aug 2001 11:10:54 GMT, anno4000@lublin.zrz.tu-berlin.de (Anno
Siegel) wrote:
> A common case is
>
> for ( $i =0, $k=0; ...) {
Another fairly common case is
$var = value, next if $condition;
This avoids having to say
do { $var = value; next; } if $condition;
Cheers,
Philip
--
Philip Newton <nospam.newton@gmx.li>
That really is my address; no need to remove anything to reply.
If you're not part of the solution, you're part of the precipitate.
------------------------------
Date: Sun, 26 Aug 2001 14:39:05 +0200
From: Philip Newton <pne-news-20010826@newton.digitalspace.net>
Subject: Re: Openning a file
Message-Id: <bdrhotgb17nn1g11mlkov4gu138kpsp95t@4ax.com>
On Sun, 26 Aug 2001 08:04:09 +0200, Tassilo von Parseval
<Tassilo.Parseval@post.rwth-aachen.de> wrote:
> Till Perl, I never considered the comma an operator. For me it
> was just something to split arguments of function-calls in C.
It's both -- even in C. Here's an example where it's both:
foo( (1, 4), 5, 8 );
This calls foo() with three parameter: 4, 5, and 8. '4' is the result of
using the comma operator on 1 and 4.
Cheers,
Philip
--
Philip Newton <nospam.newton@gmx.li>
That really is my address; no need to remove anything to reply.
If you're not part of the solution, you're part of the precipitate.
------------------------------
Date: Sun, 26 Aug 2001 09:44:45 GMT
From: tim@vegeta.ath.cx (Tim Hammerquist)
Subject: Re: pl or not pl, that is the question
Message-Id: <slrn9ohhug.1j1.tim@vegeta.ath.cx>
Me parece que Ilya Martynov <ilya@martynov.org> dijo:
[ snippage ]
> Most webservers are configured in such way that it is
> possible to find easily if some url is bound to scripts. It will be
> either 'cgi', 'cgi-bin', some postfix or something simular in URL. And
> usually all programs on one webserver are written in one language.
Granted, this is true for most servers. However, here is one method I
like:
http://www.domain.com/books/a_book/toc.html
Where's the script that it calls? The answer is: 'books'.
books is a CGI or similar script w/o extension. '/a_book/toc.html' are
passed to it as an environment variable to be parsed and formed into an
SQL query.
> So
> if I were this hacker who found such breakage I would find easily what
> is common in URL's of scripts on webserver and I would try to break
> them all.
At least you're thorough. =)
my US$0.02 ;)
--
People get annoyed when you try to debug them.
-- Larry Wall, 1999
------------------------------
Date: Sun, 26 Aug 2001 09:54:42 GMT
From: tim@vegeta.ath.cx (Tim Hammerquist)
Subject: Re: pl or not pl, that is the question
Message-Id: <slrn9ohih4.1j1.tim@vegeta.ath.cx>
Me parece que Abigail <abigail@foad.org> dijo:
> Randal L. Schwartz (merlyn@stonehenge.com) wrote:
> !! Do you put .sh on the end of all your shell scripts, and .py on the
> !! end of all your python programs?
>
> Uhm, yes, I do.
I leave .py on Python files...at least where removing it would interfere
with loading it as a separate module. Shell scripts, however, almost
never have .sh extensions on my box.
[ snippage]
> Heh, why give your files descriptive names? For Unix, they're just inodes
> anyway!
Because you like efficiency.
Oh, that was sarcasm, wasn't it? Glad I noticed it before I posted
this.... Oops!^[:x^M
--
guru, n:
A computer owner who can read the manual.
------------------------------
Date: Sun, 26 Aug 2001 07:17:50 GMT
From: "David Scarlett" <dscarlett@optushome.com.au>
Subject: Problems with fixed-length random access databases.
Message-Id: <yo1i7.22829$A5.70124@news1.eburwd1.vic.optushome.com.au>
I'm trying to write a script here, which, each time it is run, should read
from a file with a bunch of IP addresses and ping times and write do a
database the IP address, port, sum of ping times so far and the number of
times pinged. However, each time I run it, the file I'm saving the results
in increases in size (10KB, 20KB, 30KB, 40KB, & so on).
Ideally, the script searches linearly through the database, looking for
records with the same IP & port, and if it finds one, it updates it. If it
does not find one, it creates a new one at the end of the file. However, I
think it may be always adding a new record to the end of the file rather
than updating records.....
Here's the subroutine used for writing (and variables declared/files opened
beforehand):
----------------
my($pstring) = "LSfC"; # Pack control string.
my($psize) = length($pstring); # Length of each record.
open(DB,"+>>ping.dat") || die "Error: Cannot open ping.dat. $!\n";
----------------
sub output { # @_ == (IP,PORT,PING)
my($ptotal,$n,$bytes,$buf) = (0,0);
seek(DB,0,0);
$bytes = read(DB,$buf,$psize);
SEARCH: while ($bytes == $psize) {
if (@_[0,1] == (unpack($pstring,$buf))[0,1]) { # Record found.
($ptotal,$n) = (unpack($pstring,$buf))[2,3];
break SEARCH;
}
$bytes = read(DB,$buf,$psize);
}
if ($bytes == $psize) { # Guess it didn't find the
record...
seek(DB,0,2);
} else { # Or did it?....
seek(DB,-$psize,1);
}
$n++;
$ptotal += $_[2];
print DB pack($pstring,$_[0],$_[1],$ptotal,$n);
return;
}
----------------
TiA,
--
David Scarlett
dscarlett@optushome.com.au
http://www.listen.to/artifice/
http://members.optushome.com.au/dscarlett/
"Is your feng-shui properly aligned? If so, take a hard look at your life.
Why would you know what feng-shui is, means or tastes like? If you truly
believe that placing a plant in the northeast corner of your power square
will foster financial prosperity, give up now. Believing that a dwarfed tree
is going to right all of your life's wrongs is simply desperation."
-FIGHT CLUB promotional catalogue
------------------------------
Date: Sun, 26 Aug 2001 07:21:45 GMT
From: "David Scarlett" <dscarlett@optushome.com.au>
Subject: Re: Problems with fixed-length random access databases.
Message-Id: <ds1i7.22831$A5.69799@news1.eburwd1.vic.optushome.com.au>
"David Scarlett" <dscarlett@optushome.com.au> wrote in message
news:yo1i7.22829$A5.70124@news1.eburwd1.vic.optushome.com.au...
> Here's the subroutine used for writing (and variables declared/files
opened
> beforehand):
> ----------------
> my($pstring) = "LSfC"; # Pack control string.
> my($psize) = length($pstring); # Length of each record.
> open(DB,"+>>ping.dat") || die "Error: Cannot open ping.dat. $!\n";
and "binmode(DB);" as well.
--
David Scarlett
dscarlett@optushome.com.au
http://www.listen.to/artifice/
http://members.optushome.com.au/dscarlett/
"Look, coupons. I can get 2 oil changes for the price of 1! Now if I could
only afford the one......... and a car."
-Dr Zoidberg, Futurama
------------------------------
Date: Sun, 26 Aug 2001 12:16:36 +0000
From: gnari <gnarinn@hotmail.com>
Subject: Re: Problems with fixed-length random access databases.
Message-Id: <998828196.696412585210055.gnarinn@hotmail.com>
In article <yo1i7.22829$A5.70124@news1.eburwd1.vic.optushome.com.au>,
David Scarlett <dscarlett@optushome.com.au> wrote:
>open(DB,"+>>ping.dat") || die "Error: Cannot open ping.dat. $!\n";
you should read the docs for open again
the mode '+>>' is not mentioned
maybe you wanted '+<'
gnari
------------------------------
Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 6 Apr 01)
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.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 V10 Issue 1616
***************************************