[26428] in Perl-Users-Digest
Perl-Users Digest, Issue: 8597 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Nov 2 06:05:16 2005
Date: Wed, 2 Nov 2005 03:05:06 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Wed, 2 Nov 2005 Volume: 10 Number: 8597
Today's topics:
Re: Bug in &= (bitwise or) <abigail@abigail.nl>
Re: Bug in &= (bitwise or) <nospam-abuse@ilyaz.org>
Re: Bug in &= (bitwise or) <tassilo.von.parseval@rwth-aachen.de>
FAQ 3.24 Can I write useful Perl programs on the comman <comdog@pair.com>
How to use string as two dimensional array <info@toplice.com.remove>
Re: How to use string as two dimensional array <noreply@gunnar.cc>
Re: How to use string as two dimensional array <someone@example.com>
Re: IIS 5.1 + Perl <kuujinbo@hotmail.com>
Re: pack and unpack integer data <kim@schulz.dk>
Re: pack and unpack integer data <kim@schulz.dk>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 02 Nov 2005 08:32:44 GMT
From: Abigail <abigail@abigail.nl>
Subject: Re: Bug in &= (bitwise or)
Message-Id: <slrndmgudc.jik.abigail@alexandra.abigail.nl>
Tassilo v. Parseval (tassilo.von.parseval@rwth-aachen.de) wrote on
MMMMCDXLVI September MCMXCIII in <URL:news:3sr8rnFppq7qU1@news.dfncis.de>:
'' Also sprach Ilya Zakharevich:
''
'' ><tassilo.von.parseval@rwth-aachen.de>], who wrote in article <3snf0uFotcprU1@news.dfncis.de>:
'' >
'' >> Then I am not sure myself what the result of
'' >>
'' >> $s = 'aa' & 'a'
'' >>
'' >> should be.
'' >
'' > I think the current result is both correct and intuitive enough
'' > (modulo two bugs which comprise this problem). It is compatible with
'' > both
'' >
'' > a) junk-in-junk-out ("what is after end of 'a' is junk")
'' > b) strings behave as if followed by infinitely many \0s.
'' >
'' > By (b), the output string should also be considered as having
'' > infinitely many \0s; the question is where to stop this flow. And (a)
'' > looks as a reasonable argument to choose this cut-off point.
''
'' What are those two bugs you mentioned? For me the real bug is that an
'' 'impossible' string value can be constructed thus. I would expect:
''
'' ('aa' & 'a') eq "a\0"
''
'' Taking (b) into account, the smaller string should be padded with '\0'
'' which, on bit-wise ANDing, should yield '\0'.
But that's not how & is documented to work:
If the operands to a binary bitwise op are strings of
different sizes, | and ^ ops act as though the shorter
operand had additional zero bits on the right, while the &
op acts as though the longer operand were truncated to the
length of the shorter. The granularity for such extension
or truncation is one or more bytes.
According to the documentation,
('aa' & 'a') eq 'a'
because first 'aa' is truncated to 'a', and 'a' & 'a' equals 'a'.
And that's indeed what happens if you do 'aa' & 'a', as your example
shows below.
'' There's another oddity:
''
'' $ perl -MDevel::Peek -e 'my $a = 'aa'; $a &= 'a'; Dump($a)'
'' SV = PV(0x814ce90) at 0x814cc6c
'' REFCNT = 1
'' FLAGS = (PADBUSY,PADMY,POK,pPOK)
'' PV = 0x815d628 "a"
'' CUR = 1
'' LEN = 3
''
'' $ perl -MDevel::Peek -e 'my $a = 'aa' & 'a'; Dump($a)'
'' SV = PV(0x814cf20) at 0x814cc6c
'' REFCNT = 1
'' FLAGS = (PADBUSY,PADMY,POK,pPOK)
'' PV = 0x815c0e8 "a"\0
'' CUR = 1
'' LEN = 2
''
'' Why are those two not equivalent?
Well, that's the bug, isn't? ;-)
Abigail
--
perl -we 'print q{print q{print q{print q{print q{print q{print q{print q{print
qq{Just Another Perl Hacker\n}}}}}}}}}' |\
perl -w | perl -w | perl -w | perl -w | perl -w | perl -w | perl -w | perl -w
------------------------------
Date: Wed, 2 Nov 2005 09:10:45 +0000 (UTC)
From: Ilya Zakharevich <nospam-abuse@ilyaz.org>
Subject: Re: Bug in &= (bitwise or)
Message-Id: <dk9vql$163a$1@agate.berkeley.edu>
[A complimentary Cc of this posting was sent to
Tassilo v. Parseval
<tassilo.von.parseval@rwth-aachen.de>], who wrote in article <3sr8rnFppq7qU1@news.dfncis.de>:
> Also sprach Ilya Zakharevich:
>
> ><tassilo.von.parseval@rwth-aachen.de>], who wrote in article <3snf0uFotcprU1@news.dfncis.de>:
> >> For testing what the raw string looks like after the bitwise-and, you
> >> can use:
> >
> > Is not it much easier to parse the output of Devel::Peek, and read the
> > PV by unpack()?
>
> No, it wasn't for me. :-)
>
> Can you give an example how to do it with unpack? I feel the 'P'
> template is needed but I never know how to use that one.
You are right: I thought that one can easily get the result of Dump
into a variable. Probably not easy... So to do it without fork()
would not be easy:
#!/usr/bin/perl -wl
use strict;
use Devel::Peek;
# Prepare what to inspect
my $a = 'aa';
$a &= 'a';
defined (my $pid = open my $p, '-|') or die "Can't fork() to self-pipe: $!";
if ($pid) { # parent
my $out;
{
local $/;
$out = <$p>;
close $p or die;
}
# Parse output of Dump using the expected format below:
my ($addr, $len) = ($out =~ m/
^ \s+ PV \s* = \s* (0x[[:xdigit:]]+) \b
.*?
^ \s+ LEN \s* = \s* (\d+) \b
/xsm);
die "unexpected format of output of Dump" unless $addr and $len;
my $buff = unpack "P$len", pack 'J', hex $addr;
print ord for split //, $buff;
} else { # kid
open STDERR, '>&', \*STDOUT or die;
Dump $a;
###SV = PV(0x40c64) at 0x40a24
### REFCNT = 1
### FLAGS = (PADBUSY,PADMY,POK,pPOK)
### PV = 0x42020 "a"
### CUR = 1
### LEN = 3
}
__END__
> What are those two bugs you mentioned? For me the real bug is that an
> 'impossible' string value can be constructed thus.
Well, the REx engine operates in terms of start-of-string and
end-of-string. It should not read behind.
Moreover, IMO, it is important to support variables which are not
\0-terminated as wide as possible. E.g., this way one could do
substr() with copy-on-modify semantic.
> I would expect:
>
> ('aa' & 'a') eq "a\0"
>
> Taking (b) into account, the smaller string should be padded with '\0'
> which, on bit-wise ANDing, should yield '\0'.
... And, since this \0 comes from "extrapolated" values, it should be
"deextrapotated"; in other words, stripped.
> There's another oddity:
> $ perl -MDevel::Peek -e 'my $a = 'aa'; $a &= 'a'; Dump($a)'
> SV = PV(0x814ce90) at 0x814cc6c
> REFCNT = 1
> FLAGS = (PADBUSY,PADMY,POK,pPOK)
> PV = 0x815d628 "a"
> CUR = 1
> LEN = 3
We know this already...
> $ perl -MDevel::Peek -e 'my $a = 'aa' & 'a'; Dump($a)'
> SV = PV(0x814cf20) at 0x814cc6c
> REFCNT = 1
> FLAGS = (PADBUSY,PADMY,POK,pPOK)
> PV = 0x815c0e8 "a"\0
> CUR = 1
> LEN = 2
Here 'aa' & 'a' is a temporary; most probably not \0-terminated. Now
the assignment operator fills $a from the values in the temporary; as
any well-behaved Perl operator, it does not care whether there is a
trailing \0. So it does not know that the temporary is "buggy".
Hope this helps,
Ilya
------------------------------
Date: Wed, 2 Nov 2005 11:38:41 +0100
From: "Tassilo v. Parseval" <tassilo.von.parseval@rwth-aachen.de>
Subject: Re: Bug in &= (bitwise or)
Message-Id: <3srj9jFpot6oU1@news.dfncis.de>
Also sprach Ilya Zakharevich:
> [A complimentary Cc of this posting was sent to
> Tassilo v. Parseval
><tassilo.von.parseval@rwth-aachen.de>], who wrote in article <3sr8rnFppq7qU1@news.dfncis.de>:
>> Also sprach Ilya Zakharevich:
>>
>> ><tassilo.von.parseval@rwth-aachen.de>], who wrote in article <3snf0uFotcprU1@news.dfncis.de>:
>> >> For testing what the raw string looks like after the bitwise-and, you
>> >> can use:
>> >
>> > Is not it much easier to parse the output of Devel::Peek, and read the
>> > PV by unpack()?
>>
>> No, it wasn't for me. :-)
>>
>> Can you give an example how to do it with unpack? I feel the 'P'
>> template is needed but I never know how to use that one.
>
> You are right: I thought that one can easily get the result of Dump
> into a variable. Probably not easy... So to do it without fork()
> would not be easy:
[...]
Ah, thank you. I have to make a mental note that the p/P templates work
on memory addresses (I don't like the term 'pointer' which is used in
`perldoc -f pack`).
>> What are those two bugs you mentioned? For me the real bug is that an
>> 'impossible' string value can be constructed thus.
>
> Well, the REx engine operates in terms of start-of-string and
> end-of-string. It should not read behind.
Agreed.
> Moreover, IMO, it is important to support variables which are not
> \0-terminated as wide as possible. E.g., this way one could do
> substr() with copy-on-modify semantic.
Is that the current state of the affairs or rather an item on the
wishlist.
>> I would expect:
>>
>> ('aa' & 'a') eq "a\0"
>>
>> Taking (b) into account, the smaller string should be padded with '\0'
>> which, on bit-wise ANDing, should yield '\0'.
>
> ... And, since this \0 comes from "extrapolated" values, it should be
> "deextrapotated"; in other words, stripped.
I have to admit that I never really read what perlop has to say on the
bit-wise AND for strings of differing length. Now that Abigail spelled
it out for me in that parallel posting I see it a little more clearly.
>> There's another oddity:
>
>> $ perl -MDevel::Peek -e 'my $a = 'aa'; $a &= 'a'; Dump($a)'
>> SV = PV(0x814ce90) at 0x814cc6c
>> REFCNT = 1
>> FLAGS = (PADBUSY,PADMY,POK,pPOK)
>> PV = 0x815d628 "a"
>> CUR = 1
>> LEN = 3
>
> We know this already...
>
>> $ perl -MDevel::Peek -e 'my $a = 'aa' & 'a'; Dump($a)'
>> SV = PV(0x814cf20) at 0x814cc6c
>> REFCNT = 1
>> FLAGS = (PADBUSY,PADMY,POK,pPOK)
>> PV = 0x815c0e8 "a"\0
>> CUR = 1
>> LEN = 2
>
> Here 'aa' & 'a' is a temporary; most probably not \0-terminated. Now
> the assignment operator fills $a from the values in the temporary; as
> any well-behaved Perl operator, it does not care whether there is a
> trailing \0. So it does not know that the temporary is "buggy".
That can't be the explanation, because:
$ perl -MDevel::Peek -e 'my ($b, $c) = qw/aa a/; my $a = $b & $c; Dump($a)'
SV = PV(0x814ce78) at 0x8160d28
REFCNT = 1
FLAGS = (PADBUSY,PADMY,POK,pPOK)
PV = 0x8166520 "a"\0
CUR = 1
LEN = 2
and:
$ perl -MDevel::Peek -e 'my $b = q/aa/; my $a = $b & 'a'; Dump($a)'
SV = PV(0x814cf38) at 0x8160cd8
REFCNT = 1
FLAGS = (PADBUSY,PADMY,POK,pPOK)
PV = 0x8163d48 "a"\0
CUR = 1
LEN = 2
Tassilo
--
use bigint;
$n=71423350343770280161397026330337371139054411854220053437565440;
$m=-8,;;$_=$n&(0xff)<<$m,,$_>>=$m,,print+chr,,while(($m+=8)<=200);
------------------------------
Date: Wed, 2 Nov 2005 11:03:01 +0000 (UTC)
From: PerlFAQ Server <comdog@pair.com>
Subject: FAQ 3.24 Can I write useful Perl programs on the command line?
Message-Id: <dka6d5$ldm$1@reader2.panix.com>
This message is one of several periodic postings to comp.lang.perl.misc
intended to make it easier for perl programmers to find answers to
common questions. The core of this message represents an excerpt
from the documentation provided with Perl.
--------------------------------------------------------------------
3.24: Can I write useful Perl programs on the command line?
Yes. Read perlrun for more information. Some examples follow. (These
assume standard Unix shell quoting rules.)
# sum first and last fields
perl -lane 'print $F[0] + $F[-1]' *
# identify text files
perl -le 'for(@ARGV) {print if -f && -T _}' *
# remove (most) comments from C program
perl -0777 -pe 's{/\*.*?\*/}{}gs' foo.c
# make file a month younger than today, defeating reaper daemons
perl -e '$X=24*60*60; utime(time(),time() + 30 * $X,@ARGV)' *
# find first unused uid
perl -le '$i++ while getpwuid($i); print $i'
# display reasonable manpath
echo $PATH | perl -nl -072 -e '
s![^/+]*$!man!&&-d&&!$s{$_}++&&push@m,$_;END{print"@m"}'
OK, the last one was actually an Obfuscated Perl Contest entry. :-)
--------------------------------------------------------------------
Documents such as this have been called "Answers to Frequently
Asked Questions" or FAQ for short. They represent an important
part of the Usenet tradition. They serve to reduce the volume of
redundant traffic on a news group by providing quality answers to
questions that keep coming up.
If you are some how irritated by seeing these postings you are free
to ignore them or add the sender to your killfile. If you find
errors or other problems with these postings please send corrections
or comments to the posting email address or to the maintainers as
directed in the perlfaq manual page.
Note that the FAQ text posted by this server may have been modified
from that distributed in the stable Perl release. It may have been
edited to reflect the additions, changes and corrections provided
by respondents, reviewers, and critics to previous postings of
these FAQ. Complete text of these FAQ are available on request.
The perlfaq manual page contains the following copyright notice.
AUTHOR AND COPYRIGHT
Copyright (c) 1997-2002 Tom Christiansen and Nathan
Torkington, and other contributors as noted. All rights
reserved.
This posting is provided in the hope that it will be useful but
does not represent a commitment or contract of any kind on the part
of the contributers, authors or their agents.
------------------------------
Date: Wed, 2 Nov 2005 11:01:46 +0100
From: "toplicanac" <info@toplice.com.remove>
Subject: How to use string as two dimensional array
Message-Id: <dka2oi$ua$1@ss405.t-com.hr>
How to use string as two dimensional array
e.g.:
I have string
$string="123456abc";
-------------------------------------------
I want to read it like this
$mat(1,1) = "1"
$mat(2,1) = "2"
$mat(3,1) = "3"
$mat(1,2) = "4"
$mat(2,2) = "5"
$mat(3,2) = "6"
$mat(3,1) = "a"
$mat(3,2) = "b"
$mat(3,3) = "c"
But array can be 5x5, 10x10, or biger size.
What is easiest way to do it in Perl?
------------------------------
Date: Wed, 02 Nov 2005 11:13:31 +0100
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: How to use string as two dimensional array
Message-Id: <3srhmiFpptdnU1@individual.net>
toplicanac wrote:
> How to use string as two dimensional array
>
> e.g.:
> I have string
>
> $string="123456abc";
> -------------------------------------------
> I want to read it like this
>
> $mat(1,1) = "1"
> $mat(2,1) = "2"
> $mat(3,1) = "3"
> $mat(1,2) = "4"
> $mat(2,2) = "5"
> $mat(3,2) = "6"
> $mat(3,1) = "a"
> $mat(3,2) = "b"
> $mat(3,3) = "c"
Which programming language is that?
> But array can be 5x5, 10x10, or biger size.
> What is easiest way to do it in Perl?
Which ways have you considered?
Please study the posting guidelines for this group:
http://mail.augustmail.com/~tadmc/clpmisc/clpmisc_guidelines.html
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
------------------------------
Date: Wed, 02 Nov 2005 10:54:02 GMT
From: "John W. Krahn" <someone@example.com>
Subject: Re: How to use string as two dimensional array
Message-Id: <eV0af.96632$ir4.46813@edtnps90>
toplicanac wrote:
> How to use string as two dimensional array
>
> e.g.:
> I have string
>
> $string="123456abc";
> -------------------------------------------
> I want to read it like this
>
> $mat(1,1) = "1"
> $mat(2,1) = "2"
> $mat(3,1) = "3"
> $mat(1,2) = "4"
> $mat(2,2) = "5"
> $mat(3,2) = "6"
> $mat(3,1) = "a"
> $mat(3,2) = "b"
> $mat(3,3) = "c"
$ perl -le'
my $string = q!123456abc!;
print for
map substr( $string, ($_->[1] - 1) * 3 + ($_->[0] - 1), 1 ),
[1,1],[2,1],[3,1],[1,2],[2,2],[3,2],[1,3],[2,3],[3,3];
'
1
2
3
4
5
6
a
b
c
John
--
use Perl;
program
fulfillment
------------------------------
Date: Wed, 02 Nov 2005 19:28:47 +0900
From: ko <kuujinbo@hotmail.com>
Subject: Re: IIS 5.1 + Perl
Message-Id: <dka4d2$3ck$1@pin3.tky.plala.or.jp>
John Bokma wrote:
> Hi,
>
> I managed to get IIS 5.1 [1] running my hello.pl script in Firefox.
> However, IE wants me to download it.
>
> I added .pl, pointing to C:\perl\bin\perl.exe with "%s" %s added in the
> mappings.
>
> The ActiveState install seems to come with an IISmapping script, but I have
> no clue on how to use it.
>
> Any help is very welcome,
>
>
> [1] Windows XP, SP2, default install.
>
CGI:
http://aspn.activestate.com/ASPN/docs/ActivePerl/5.8/faq/Windows/
ActivePerl-Winfaq6.html#microsoft_web_servers
ASP:
http://aspn.activestate.com/ASPN/docs/ActivePerl/5.8/Windows/
ActiveServerPages.html
HTH - keith
------------------------------
Date: Wed, 2 Nov 2005 11:25:53 +0100
From: Kim Schulz <kim@schulz.dk>
Subject: Re: pack and unpack integer data
Message-Id: <20051102112553.55bc8cc0@h4217.s.cs.aau.dk>
On 01 Nov 2005 16:49:55 GMT
xhoster@gmail.com wrote:
> Kim Schulz <kim@schulz.dk> wrote:
> > Hi I'm working on doing a bit of simple compression of some
> > datafiles I have.
>
> Have you considered using a general purpose module/tool (like gzip)?
Yes, but this is for the purpose of learning only, so that would be the
easy way out.
> > Right now I have files like:
> > 1 2 5 4 3 23 6 5 34 455 6 3 22 1 1 1 22 .... etc.
> >
> > I would like to read the numbers one by one (no problem) and then
> > pack them into the smalles binary representation I can get.
>
> How do you know what the smallest representation will be if you don't
> know what the largest possible number you will see will be?
in generel it is bound by a parameter I have which currently is found
by finding the largest number in the file.
> >
> > The idea is that I later on would like to be able to unpack them
> > again.
> >
> > I have been looking at pack/unpack and tried pack("b*", $num) where
> > $num is one of the numbers "represented as a string".
>
> That will ignore all but the least significant bit of every byte
> (character?) in the sting representation of $num. Hardly what you
> want.
> > That seems to pack it fine, but then I want to unpack it again.
>
> On what basis do you say that it seems to pack it fine? If you can't
> get it unpacked, how do you know if the error is in the packing or the
> unpacking?
you are right. and thats why I asked.
> > And cant seem to get that one working like it is supposed to.
>
> We don't know how you think it is supposed to work.
>
> >
> > Can anyone point me in the right direction?
>
> Post the code that does both the packing and unpacking, the input, the
> actual output, and what you thought the output would be.
> > (yes I have looked at the
> > perldoc for unpack and pack but what I understood to be correct does
> > not work).
>
> You misunderstood something. If you showed is the code, or gave us
> some indication of your understanding, perhaps we could help you
> figure out what it is you misunderstood.
I will do that when Im back on my laptop again.
------------------------------
Date: Wed, 2 Nov 2005 11:26:33 +0100
From: Kim Schulz <kim@schulz.dk>
Subject: Re: pack and unpack integer data
Message-Id: <20051102112633.0a44f73e@h4217.s.cs.aau.dk>
On Tue, 01 Nov 2005 10:07:12 -0800
Jim Gibson <jgibson@mail.arc.nasa.gov> wrote:
> Unless you are doing this as a learning exercise, there is no need to
> re-invent the wheel. Data compression is a well-studied subject. zlib
> is a good, free implementation of a good compression algorithm. The
> Compress::Zlib module, available on CPAN, gives a Perl program access
> to zlib. There are also many other Compress:: modules on CPAN. One of
> them will surely satisfy your requirements.
yep....it's for the purpose of learning.
------------------------------
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.
NOTE: due to the current flood of worm email banging on ruby, the smtp
server on ruby has been shut off until further notice.
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 8597
***************************************