[26424] in Perl-Users-Digest
Perl-Users Digest, Issue: 8594 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Nov 1 14:05:25 2005
Date: Tue, 1 Nov 2005 11: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 Tue, 1 Nov 2005 Volume: 10 Number: 8594
Today's topics:
Re: Bug in &= (bitwise or) (Anno Siegel)
FAQ 4.52 How do I sort an array by (anything)? <comdog@pair.com>
Re: List of references <tim@vegeta.ath.cx>
pack and unpack integer data <kim@schulz.dk>
Re: pack and unpack integer data xhoster@gmail.com
Re: pack and unpack integer data <jgibson@mail.arc.nasa.gov>
passing data <news@cutmeukjay.com>
Re: Perl equivalent of PHP and JSP: Mason? <stevenREMOVE.chapelTHESE@TOsbcglobalE-MAIL.netME>
Re: Regex Precedence <Kevin.Nechodom@spamlesshsc.utah.edu>
Re: RTF and UTF-8 files in Perl <scobloke2@infotop.co.uk>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 1 Nov 2005 17:42:01 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Bug in &= (bitwise or)
Message-Id: <dk89d9$sdc$1@mamenchi.zrz.TU-Berlin.DE>
Anno Siegel <anno4000@lublin.zrz.tu-berlin.de> wrote in comp.lang.perl.misc:
> Tassilo v. Parseval <tassilo.von.parseval@rwth-aachen.de> wrote in
> comp.lang.perl.misc:
>
> > Did someone already file a bugreport?
>
> I will. Want to check against bleadperl first. I'll also at least go
> through the motions of seeing if it has been reported before.
[Anno again]
The bug is still in perl-5.9.2, I've sent a report. Fun with perlbug, as
usual.
BTW, the combination of bitwise operations and regex matching that tickles
the bug isn't as exotic as it may seem. When you work with vec(), trailing
zero bytes in a string are essentially invisible -- strings behave as if
padded with infinitely many zeroes. Therefore trailing zeroes can make
strings look different (to eq) that are really the same as far as vec()
is concerned. To get rid of trailing zeroes, s/\0+$// offers itself,
particularly after &= which may have created them even if the operands
didn't have any.
Anno
--
If you want to post a followup via groups.google.com, don't use
the broken "Reply" link at the bottom of the article. Click on
"show options" at the top of the article, then click on the
"Reply" at the bottom of the article headers.
------------------------------
Date: Tue, 1 Nov 2005 17:03:00 +0000 (UTC)
From: PerlFAQ Server <comdog@pair.com>
Subject: FAQ 4.52 How do I sort an array by (anything)?
Message-Id: <dk8744$p2e$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.
--------------------------------------------------------------------
4.52: How do I sort an array by (anything)?
Supply a comparison function to sort() (described in "sort" in
perlfunc):
@list = sort { $a <=> $b } @list;
The default sort function is cmp, string comparison, which would sort
"(1, 2, 10)" into "(1, 10, 2)". "<=>", used above, is the numerical
comparison operator.
If you have a complicated function needed to pull out the part you want
to sort on, then don't do it inside the sort function. Pull it out
first, because the sort BLOCK can be called many times for the same
element. Here's an example of how to pull out the first word after the
first number on each item, and then sort those words case-insensitively.
@idx = ();
for (@data) {
($item) = /\d+\s*(\S+)/;
push @idx, uc($item);
}
@sorted = @data[ sort { $idx[$a] cmp $idx[$b] } 0 .. $#idx ];
which could also be written this way, using a trick that's come to be
known as the Schwartzian Transform:
@sorted = map { $_->[0] }
sort { $a->[1] cmp $b->[1] }
map { [ $_, uc( (/\d+\s*(\S+)/)[0]) ] } @data;
If you need to sort on several fields, the following paradigm is useful.
@sorted = sort { field1($a) <=> field1($b) ||
field2($a) cmp field2($b) ||
field3($a) cmp field3($b)
} @data;
This can be conveniently combined with precalculation of keys as given
above.
See the sort article in the "Far More Than You Ever Wanted To Know"
collection in http://www.cpan.org/misc/olddoc/FMTEYEWTK.tgz for more
about this approach.
See also the question below on sorting hashes.
--------------------------------------------------------------------
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: Tue, 01 Nov 2005 15:56:52 GMT
From: Tim Hammerquist <tim@vegeta.ath.cx>
Subject: Re: List of references
Message-Id: <slrndmf423.mbe.tim@vegeta.saiyix>
Anno Siegel <anno4000@lublin.zrz.tu-berlin.de> wrote:
> Tim Hammerquist <tim@vegeta.ath.cx> wrote in comp.lang.perl.misc:
> > ko <kuujinbo@hotmail.com> wrote:
>
> > > As a special case, \(@foo) returns a list of references to the contents
> > > of @foo, not a reference to @foo itself.
> >
> > This isn't what you did, however. You want this, like perlref
> > says.
> >
> > my @a = \(%a, %b); # special case as describe in perlref
> >
> > But you can't do:
> >
> > my @a = \my (%a, %b); # NOT A SPECIAL CASE!
> >
> > You're trying to both my() the %a and %b hashes, *and* invoke
> > the special case, but it won't happen. You'll have to my() the
> > hashes outside of the ref assignment:
> >
> > my (%a, %b);
> > my @a = \(%a, %b);
>
> That is not so.
>
> my @a = \ my( %a, %b);
>
> puts references to %a and %b in @a, just like
>
> my ( %a, %b);
> my @a = \ ( %a, %b);
Ok, I must have spaced out. I thought the OP was asking why his
code wouldn't work. And when I plugged it into the perl
debugger, indeed it didn't.
Please disregard my earlier post.
Tim Hammerquist
------------------------------
Date: Tue, 1 Nov 2005 17:14:52 +0100
From: Kim Schulz <kim@schulz.dk>
Subject: pack and unpack integer data
Message-Id: <20051101171452.206e1da9@h4217.s.cs.aau.dk>
Hi I'm working on doing a bit of simple compression of some datafiles I
have.
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.
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 seems to pack it fine, but then I want to unpack it again.
And cant seem to get that one working like it is supposed to.
Can anyone point me in the right direction? (yes I have looked at the
perldoc for unpack and pack but what I understood to be correct does
not work).
------------------------------
Date: 01 Nov 2005 16:49:55 GMT
From: xhoster@gmail.com
Subject: Re: pack and unpack integer data
Message-Id: <20051101114955.557$KG@newsreader.com>
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)?
> 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?
>
> 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?
> 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.
Xho
--
-------------------- http://NewsReader.Com/ --------------------
Usenet Newsgroup Service $9.95/Month 30GB
------------------------------
Date: Tue, 01 Nov 2005 10:07:12 -0800
From: Jim Gibson <jgibson@mail.arc.nasa.gov>
Subject: Re: pack and unpack integer data
Message-Id: <011120051007125054%jgibson@mail.arc.nasa.gov>
In article <20051101171452.206e1da9@h4217.s.cs.aau.dk>, Kim Schulz
<kim@schulz.dk> wrote:
> Hi I'm working on doing a bit of simple compression of some datafiles I
> have.
> 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.
>
> 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 seems to pack it fine, but then I want to unpack it again.
> And cant seem to get that one working like it is supposed to.
>
> Can anyone point me in the right direction? (yes I have looked at the
> perldoc for unpack and pack but what I understood to be correct does
> not work).
>
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.
------------------------------
Date: Tue, 1 Nov 2005 18:26:18 -0000
From: "PhEaSaNt PLuCKeR" <news@cutmeukjay.com>
Subject: passing data
Message-Id: <dk8c08$5j2$1@newsg4.svr.pol.co.uk>
Keywords: scripts
Hello
How do I get two running perl scripts to pass data to each other?
Another quickie, Is it possible to open a web page from a perl script, but
be able to run the
script viewable in a dos shell and also see data passed from that script to
a web page?
Has anyone done this?
If so any hints or tips Please.
--
James (Ukjay)
------------------------------
Date: Tue, 01 Nov 2005 15:51:39 GMT
From: Steve Chapel <stevenREMOVE.chapelTHESE@TOsbcglobalE-MAIL.netME>
Subject: Re: Perl equivalent of PHP and JSP: Mason?
Message-Id: <faM9f.4216$Y61.2800@newssvr33.news.prodigy.com>
Thanks for the replies. In the absence of any strong negative comments
about Mason, I think I'll try it. Since my first post, I found a very
good comparison of different ways of using Perl on web pages in Advanced
Perl Programming, 2nd edition by Simon Cozens
<http://www.oreilly.com/catalog/advperl2/chapter/ch03.pdf>. He prefers
Mason, but likes the Template Toolkit as well.
------------------------------
Date: Tue, 1 Nov 2005 10:01:28 -0700
From: "Kevin Nechodom" <Kevin.Nechodom@spamlesshsc.utah.edu>
Subject: Re: Regex Precedence
Message-Id: <dk8719$5tc$1@vegh.ks.cc.utah.edu>
>>> Matt Garrish<matthew.garrish@sympatico.ca> 10/31/2005
6:43 PM >>>
"Kevin Nechodom" <Kevin.Nechodom@nospam.hsc.utah.edu> wrote
in message
news:dk6c0q$sc6$1@vegh.ks.cc.utah.edu...
>> So I'm trying to match it with:
>> s/(\w*)(?: |-|\#)*(\w*)/$1-$2/
>> But when I come to the case of '632', it returns '-632'
instead of '632-'.
>> How do I change
>> this to return '632-'? I dont' understand regex
precedence here.
>Please do not post html messages to usenet, and vcf files
are equally
>unwanted.
I'll do my best, but I won't see it (HTML) Please let me
know if the problem persists.
>Without seeing any of the actual data you're working with,
however, I'm not
>going to speculate at what will or will not fix your
problem.
My bad! Text was being interpreted, so rhat '632-' was
veing displayed -632.
>Matt
Thanks,
--
Kevin Nechodom
University of Utah Hospital and Clinics
Kevin dit Nechodom ack hsc dit utah dit edu
"Call me paranoid, but I think you are reading what I'm
writing!"
------------------------------
Date: Tue, 1 Nov 2005 15:47:17 +0000 (UTC)
From: Ian Wilson <scobloke2@infotop.co.uk>
Subject: Re: RTF and UTF-8 files in Perl
Message-Id: <dk82m2$cse$1@nwrdmz01.dmz.ncs.ea.ibs-infra.bt.com>
V S Rawat wrote:
> Ian Wilson wrote:
>
>>AIUI, it shouldn't be necessary to do this since Perl can work
>>with Unicode characters in UTF8 form.
>
<snip: OP downloaded latest unicode-able Activestate Perl>
>
> However, the display in MSDOS window is not the correct Unicode
> character. How do I get a correct display in MSDOS window?
This is getting off-topic but ...
You can't, at least I don't know how. I think the Windows "Command
Prompt" window in Windows XP is severely limited as to which fonts you
can choose in it's "properties" dialog. I imagine this has something to
do with its legacy MSDOS ancestry, history of use with bitmap fonts and
backwards compatibility.
You'd have to reencode your Unicode output into a character set for
which you have a font usable in a "Command Prompt" window. Good luck
finding such a font with your glyph in it!
It may be easier to think about Tk/Perl, HTML or some other output
method that doesn't involve Windows "Command Prompt" window and can
therefore use arbitrary TrueType/OpenType fonts with Unicode support.
>
>>AIUI, you should just be able to use any UTF8 capable editor
>>(e.g. VIM) to write perl code where literal strings contain
>>the unicode characters you want, just like typing ASCII or
>>Latin-1 characters. These should display correctly on any UTF8
>>compatible operating system/display with the appropriate font.
>>
>> #!/usr/bin/perl
>> use strict;
>> use warnings;
>> print "Unicode glyph at code point 0x0964 is [ред] \n";
>>
>
> My XanaNews reader shows the correct character in above. I had
> to copy paste the above in word and save as a .pl file with
> UTF-8 encoding. That file duly ran in perl, and though the MSDOS
> display was not correct, on redirecting the display to a disc
> file, and opening that in word shown the correct unicode
> character.
>
> I have downloaded Crimson Editor that I am now using for per.
> Though it says that encoding is there, the option does not seem
> to work and I could not see any text in unicode character.
Ask in comp.editors?
>
> Could someone please suggest some free editor for Perl?
I like gvim on Windows. It has syntax highlighting for Perl and (IME)
does the right thing with UTF8 encoded Unicode files. However, gvim is
based on vi and so has vi's steep learning curve (but consider "cream" -
a user interface to gvim for people who can't get along with vi).
> btw, Is there any free download of script availablable anywhere
> which does ASCII font conversion (actually Adobe Type Manager's
> pfb/pfm font) conversion to Unicode font?
I don't understand the question - you might like to ask a better one in
comp.fonts.
------------------------------
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 8594
***************************************