[28438] in Perl-Users-Digest
Perl-Users Digest, Issue: 9802 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Oct 4 09:06:00 2006
Date: Wed, 4 Oct 2006 06:05:10 -0700 (PDT)
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, 4 Oct 2006 Volume: 10 Number: 9802
Today's topics:
AES-CTR <keith.willis@aah.co.uk>
Archive::Zip - how to create huge zip files ? <lev.weissman@creo.com>
Re: Archive::Zip - how to create huge zip files ? anno4000@radom.zrz.tu-berlin.de
Re: How to delete temporary file after displaying in br <bart@nijlen.com>
How to start Internet Explorer from Perl Script? <moreno@tututico.it>
LWP and 302 redirects <whoami@whereami.com>
Re: LWP and Unicode <dale.gerdemann@googlemail.com>
Re: LWP and Unicode <dale.gerdemann@googlemail.com>
Re: LWP and Unicode <dale.gerdemann@googlemail.com>
Re: My first socket question <bik.mido@tiscalinet.it>
Re: Perl Async .10 anno4000@radom.zrz.tu-berlin.de
Re: perl flawed or my fault <tadmc@augustmail.com>
Re: Questions about Inline::C <january.weiner@gmail.com>
Re: Questions about Inline::C <nospam-abuse@ilyaz.org>
Re: Spliting values and reversing a hash <bik.mido@tiscalinet.it>
Re: Spliting values and reversing a hash <peace.is.our.profession@gmx.de>
Re: Spliting values and reversing a hash <bik.mido@tiscalinet.it>
Re: Spliting values and reversing a hash <peace.is.our.profession@gmx.de>
Re: Spliting values and reversing a hash anno4000@radom.zrz.tu-berlin.de
substitution question <darthmullet67@hotmail.com>
Re: substitution question <mritty@gmail.com>
Re: this is annoying <bik.mido@tiscalinet.it>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 4 Oct 2006 02:55:48 -0700
From: "bytebro" <keith.willis@aah.co.uk>
Subject: AES-CTR
Message-Id: <1159955748.817374.320170@i3g2000cwc.googlegroups.com>
Hi,
I have had a browse around CPAN, and can't quite find what I'm looking
for, so I was wondering if anyone might be able to point me in the
right direction.
I have a C program which does the following:
Given a pseudo-random salt (8 bytes) and user-supplied passphrase, it
uses RFC3686 (PKCS #5) to produce a 256-bit AES key, and a 16-byte IV.
The salt value is broadcast as a header to the ciphertext.
It encrypts the plaintext in CTR mode, XORing an 8-byte counter into
the IV to give a counter block prior to each encryption.
It appends a 16-byte MAC produced using OMAC1/CMAC to the ciphertext.
My quest is to find a module or set of modules which allow me to
duplicate this processing in Perl. The Rijndael modules I found don't
seem to support CTR mode, so I'd have to roll that myself in the body
of the code, I guess; the only other CTR-related module I found seems
not to support an 8-byte counter and confesses itself to be very slow.
I found a Digest::CMAC module, but nothing for the PKCS #5 key
derivation.
Any ideas, please?
------------------------------
Date: 4 Oct 2006 05:17:55 -0700
From: "MoshiachNow" <lev.weissman@creo.com>
Subject: Archive::Zip - how to create huge zip files ?
Message-Id: <1159964275.746749.87220@k70g2000cwa.googlegroups.com>
Hi,
My code is :
my $zip = Archive::Zip->new();
$zip->addFile("Updates.txt");
$zip->writeToFileNamed($NAME1);
However - If I'm zipping huge (20GB) database files into the zip - how
and when should I write (writeToFileNamed) this zip file?I beleive
Windows will not be able to keep this huge info in the memory...
Thanks
------------------------------
Date: 4 Oct 2006 12:32:30 GMT
From: anno4000@radom.zrz.tu-berlin.de
Subject: Re: Archive::Zip - how to create huge zip files ?
Message-Id: <4ohnuuFef19sU2@news.dfncis.de>
MoshiachNow <lev.weissman@creo.com> wrote in comp.lang.perl.misc:
> Hi,
> My code is :
>
> my $zip = Archive::Zip->new();
> $zip->addFile("Updates.txt");
> $zip->writeToFileNamed($NAME1);
>
> However - If I'm zipping huge (20GB) database files into the zip - how
> and when should I write (writeToFileNamed) this zip file?I beleive
> Windows will not be able to keep this huge info in the memory...
Read the documentation of the module you are using. The section
"OBJECT MODEL" explains that the object does *not* (necessarily)
hold the data.
Anno
------------------------------
Date: 4 Oct 2006 00:49:06 -0700
From: "Bart Van der Donck" <bart@nijlen.com>
Subject: Re: How to delete temporary file after displaying in browser ?
Message-Id: <1159948146.660744.137820@h48g2000cwc.googlegroups.com>
Yohan N Leder wrote:
> In article <1159881510.761411.243360@e3g2000cwe.googlegroups.com>,
> bart@nijlen.com says...
> > Or you could use GET with another encryption algorithm that guarantees
> > a URL that is short enough.
>
> What for example ?
I'm not sure if such a 'shortener' exists. If yes, it probably requires
quite some memory resources.
> [...]
> Humm, maybe an idea : I could write down name of temporary image in a
> log, then delete the one produced by previous session at the beginning
> of every new one.
A classical design mistake, I'm afraid. A process could unlink a file
from a previous process that is still reading the file (or even hasn't
start reading it, or is even writing the file, e.g. when the second
process deals with a light image and the first one with a heavy image).
--
Bart
------------------------------
Date: Wed, 4 Oct 2006 10:04:38 +0200
From: "Tutico" <moreno@tututico.it>
Subject: How to start Internet Explorer from Perl Script?
Message-Id: <efvput$b8m$1@ss408.t-com.hr>
a.. How to start Internet Explorer from Perl Script?
b.. How to send key to surf web with same Internet Explorer?
Thanks
------------------------------
Date: Wed, 4 Oct 2006 09:19:06 +0100
From: "IanW" <whoami@whereami.com>
Subject: LWP and 302 redirects
Message-Id: <efvqpq$khj$1@south.jnrs.ja.net>
Hi
I'm having trouble with LWP and 302 redirects. I found the
"$ua->requests_redirectable" parameter in the LWP documentation but it still
doesn't work. Here's my code:
use LWP::UserAgent;
my $ua = new LWP::UserAgent;
push @{ $ua->requests_redirectable },'POST';
my $request = HTTP::Request->new(POST => 'http://blah.blah');
$request->content_type('application/x-www-form-urlencoded');
$request->content("LOGIN1=$action&Y=$Y&p=$P");
my $resp = $ua->request($request);
Any ideas what I'm doing wrong?
Ian
------------------------------
Date: 4 Oct 2006 01:00:33 -0700
From: "Dale" <dale.gerdemann@googlemail.com>
Subject: Re: LWP and Unicode
Message-Id: <1159948833.432241.309590@e3g2000cwe.googlegroups.com>
Thanks Ben for the thorough answer. But there is still a difference
between "encoding 'utf8'" and "use utf8" that you are somehow missing.
Ben Morrow wrote:
> Quoth "Dale" <dale.gerdemann@googlemail.com>:
> > ...
> > Question 3: If you change the pragma "use utf8" to "use encoding
> > 'utf8'" then you don't need the call to "decode("utf8", ...)". Why
> > should this be? What's the difference between "use utf8" and "use
> > encoding 'utf8'"? The perldoc:perlunicode is no help here.
>
> The differences are
>
> 1. encoding supports many encodings.
> 2. encoding is probably negligbly slower.
> 3. encoding gives decent error recovery (as opposed to crashing
> perl).
> 4. encoding sets a default PerlIO layer on STDIN and STDOUT, unless
> you've already done so with the -C switch.
>
> I can see no reason why the two should give different results in this
> case; but perhaps your -CSDA is interfering.
I've eliminated the -CSDA and still get a major difference. Try this:
#!.../perl-5.8.8/bin/perl -w
# uncomment one of the following:
# use encoding 'utf8';
# use utf8;
use LWP;
use Encode;
use URI::Escape;
my $browser = LWP::UserAgent->new;
$browser->parse_head(0);
my $url =
'http://bg.wiktionary.org/wiki/%D0%A3%D0%B8%D0%BA%D0%B8%D1%80%D0%B5%D1%87%D0%BD%D0%B8%D0%BA:%D0%91%D1%8A%D0%BB%D0%B3%D0%B0%D1%80%D1%81%D0%BA%D0%B8/%D0%A2%D0%B8%D0%BF%D0%BE%D0%B2%D0%B5_%D0%B4%D1%83%D0%BC%D0%B8/%D0%93%D0%BB%D0%B0%D0%B3%D0%BE%D0%BB%D0%B8';
my $response = $browser->get($url);
my $content = uri_unescape($response->content);
print "$content\n";
---------------
The results are (for me) better with "use utf8'. In this case $content
is a character sequence with human-readable characters.
It appears that "use encoding 'utf8'" decodes the UTF-8 before the
call to uri_unescape and "use utf8" decodes after the
utf_unescape. But this is just my uneducated guess.
------------------------------
Date: 4 Oct 2006 01:02:52 -0700
From: "Dale" <dale.gerdemann@googlemail.com>
Subject: Re: LWP and Unicode
Message-Id: <1159948972.766402.43340@i3g2000cwc.googlegroups.com>
Parsing of undecoded UTF-8 will give garbage ...
I (Dale Gerdemann) wrote:
> Question 1: Why do I need the line that says
>
> $browser->parse_head(0);
And Ben Morrow answered:
> You don't. The docs for this are (surprisingly) in perldoc
> LWP::UserAgent.
And the perldoc says:
> $ua->parse_head
> $ua->parse_head( $boolean )
> Get/set a value indicating whether we should initialize response head-
> ers from the <head> section of HTML documents. The default is TRUE.
> Do not turn this off, unless you know what you are doing.
Okay, I admit that I don't know what I'm doing. But I do know that
without the line, you get a warning that says:
Parsing of undecoded UTF-8 will give garbage when decoding entities
at /afs/sfs/lehre/dg/myperl/lib/LWP/Protocol.pm line 114.
I'm just trying to make Perl happy.
Dale Gerdemann
------------------------------
Date: 4 Oct 2006 03:32:51 -0700
From: "Dale" <dale.gerdemann@googlemail.com>
Subject: Re: LWP and Unicode
Message-Id: <1159957971.071680.223240@i3g2000cwc.googlegroups.com>
Sorry to respond multiple time to my own question, but I keep testing
things and am getting results I can't explain.
Ben Morrow wrote (concerning "use 'utf8'" compared to "use encoding
'utf8'"):
>
> 1. encoding supports many encodings.
> 2. encoding is probably negligbly slower.
> 3. encoding gives decent error recovery (as opposed to crashing
> perl).
> 4. encoding sets a default PerlIO layer on STDIN and STDOUT, unless
> you've already done so with the -C switch.
>From this, I suppose that the -CIO switch and "use encoding 'utf8'"
should be interchangable, as long as there is no Unicode in the
program. The only point that is relevant here is number 4 from the
above list.
perldoc encoding says:
The encoding pragma also modifies the filehandle layers of STDIN
and STDOUT to the specified encoding. Therefore,
perldoc perlrun says:
The "-C" flag controls some Unicode of the Perl Unicode
features.
As of 5.8.1, the "-C" can be followed either by a number or
a list of option letters. The letters, their numeric
values, and effects are as follows; listing the letters is
equal to summing the numbers.
I 1 STDIN is assumed to be in UTF-8
O 2 STDOUT will be in UTF-8
BUT: Surprisingly, the two don't give the same results:
Here's my test program:
#!/afs/sfs/lehre/dg/perl-5.8.8/bin/perl # -CIO
# use encoding 'utf8';
use LWP;
use URI::Escape;
my $browser = LWP::UserAgent->new;
$browser->parse_head(0);
my $url =
'http://bg.wiktionary.org/wiki/%D0%A3%D0%B8%D0%BA%D0%B8%D1%80%D0%B5%D1%87%D0%BD%D0%B8%D0%BA:%D0%91%D1%8A%D0%BB%D0%B3%D0%B0%D1%80%D1%81%D0%BA%D0%B8/%D0%A2%D0%B8%D0%BF%D0%BE%D0%B2%D0%B5_%D0%B4%D1%83%D0%BC%D0%B8/%D0%93%D0%BB%D0%B0%D0%B3%D0%BE%D0%BB%D0%B8';
my $response = $browser->get($url);
my $content = uri_unescape($response->content);
print "$content\n";
-------------------
The -CIO switch and the encoding pragma are both commented out. There
are four possibilities to uncomment 0, 1 or 2 of these.
On the web page to be downloaded there is both:
1. utf8 encoded Unicode, and
2. escaped (percent encoded) utf8 encoded Unicode
So again there are 4 possibilities with one, the other, both or neither
of these Unicodes being correctly decoded.
And the results:
1. Using just the switch -CIO is a horrible failure. None of the
Unicode is decoded.
2. Using "use encoding 'utf8'" is better. The non-escaped Unicode is
decoded
3. Using both the switch -CIO and "use encoding 'utf8'" is the same as
just using the encoding pragma.
4. Using nothing at all gives the best result. All the Unicode is
correctly decoded.
Case 1 (the horrible failure) is in some ways better than cases 2 and
3. If none of the Unicode is decoded, then you can explicitly decode:
my $content = decode("utf8", uri_unescape($response->content));
In cases 2 and 3, this results in a failure:
Cannot decode string with wide characters at
/afs/sfs/lehre/dg/perl-5.8.8/lib/5.8.8/i686-linux/Encode.pm line 166.
Can anyone explain this behavior?
Dale Gerdemann
------------------------------
Date: 4 Oct 2006 10:51:41 +0200
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: My first socket question
Message-Id: <ucs6i2li4dlhc9fggp4iuu91dcs7o7vb6r@4ax.com>
On 03 Oct 2006 17:13:19 GMT, xhoster@gmail.com wrote:
>Ah, I see I should have explained that better. You would want to
>"can_read(0)". You would *not* want to "can_read(undef)". They do very
Strangely enough I had read and understood the documentation (but the
"registered" bit) but for some reson I thought you were suggesting the
latter, which is a fortunate coincidence for otherwise I may have
missed your excellent brief explanation. Thank you and Jim for your
courtesy and helpfulness.
Michele
--
{$_=pack'B8'x25,unpack'A8'x32,$a^=sub{pop^pop}->(map substr
(($a||=join'',map--$|x$_,(unpack'w',unpack'u','G^<R<Y]*YB='
.'KYU;*EVH[.FHF2W+#"\Z*5TI/ER<Z`S(G.DZZ9OX0Z')=~/./g)x2,$_,
256),7,249);s/[^\w,]/ /g;$ \=/^J/?$/:"\r";print,redo}#JAPH,
------------------------------
Date: 4 Oct 2006 09:38:46 GMT
From: anno4000@radom.zrz.tu-berlin.de
Subject: Re: Perl Async .10
Message-Id: <4ohdp6FemqbhU1@news.dfncis.de>
Todd English <toddenglish@gmail.com> wrote in comp.lang.perl.misc:
> > I think it's a bug in Async.pm that has to do with buffering.
> > Async uses a buffer of size 8192. If you make the output string
> > longer than that (printing only a bit of it), all processes will
> > return values. If it is much shorter, (half that size or so) gaps
> > will start to appear.
> >
> > Anno
>
> Anno,
>
> I'm not sure I follow you. As a test I returned really really long
> messages and I also tried changing the buffer size to in the perl
> module to 10. In either case, I still see the same behavior.
I had rather unambiguous results on a Mac, where I saw empty results
(gaps) like you're getting with a message size of up to 4096 but never
with a size of 4097 or more. Reducing the buffer size in Async.pm
does not change the behavior as you noted. If the problem is indeed
buffering it must be a different buffer.
I can't reproduce this behavior on the Linux system I'm sitting at now.
Instead I'm seeing "gaps" with message sizes much larger than 4096.
> I must admit that reading the perl in Async.pm is a little more
> advanced than my few days of using perl will allow me to comprehend.
> But if I am reading this correctly, the buffer you are talking about is
> the child's return data buffer.
I thought so, but more tests have shown I was wrong.
> I put some debug print commands into
> that area of the Async module; specifically I printed out the return
> value of sysread and value of buf. It turns out the sysread is
sysread()? My version (0.10) of Async uses read(), which goes against
the recommendation in "perldoc -f select":
WARNING: One should not attempt to mix buffered I/O (like
"read" or <FH>) with "select", except as permitted by POSIX,
and even then only on POSIX systems. You have to use "sysread"
instead.
However, changing read() to sysread() doesn't seem to make a difference
either.
> returning 0 for many of the calls. I'm now wondering if there is a
> problem with the system call getting interrupted and the child ready
> loop isn't handling it correctly. I'll look into that tonight.
That looks like a possibility. Putting this
$_ = sub { my $sig = shift; warn "signal $sig" } for values %SIG;
in the main program after the loop with "Async->new" (so the children's
%SIG is unaffected) shows a number of uncaught SIGCHLDs. I haven't
followed this further. See "perldoc perlvar" for %SIG.
Anno
------------------------------
Date: Tue, 3 Oct 2006 23:28:58 -0500
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: perl flawed or my fault
Message-Id: <slrnei6e4a.o3.tadmc@magna.augustmail.com>
Eric Schwartz <emschwar@pobox.com> wrote:
> I'd still use the if-else
> equivalent (and cuddle the else too! Bwahahahah!) just because I
^
> think it's more readable.
^^^^^
If you are the only person who reads your code, then that is
a very sensible criterion.
You are in an enviable position. Most of us have to consider
other programmers when we write programs, where the criterion
is what do most people think is more readable.
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Wed, 4 Oct 2006 10:40:21 +0200 (CEST)
From: January Weiner <january.weiner@gmail.com>
Subject: Re: Questions about Inline::C
Message-Id: <efvs1l$9li$1@sagnix.uni-muenster.de>
xhoster@gmail.com wrote:
> Will that fit as an automatic (I think that is the term) variable?
> double x[2000][2000];
Unfortunately, no, as I do not know how large the matrix is going to be.
> You don't need to use perl guts for each manipulation. You can get the
> char* to the start of the Perl sv string memory, and then cast that into
> whatever you want. Store that casted pointer, and use it just like there
> were no Perl involved from then on.
> my $x= pack "d*", @list_of_numbers;
> foo($x,scalar @list_of_numbers);
> __C__
> void foo (unsigned char* s, int num_doubles) {
> double * x = (double*) s;
> //now use x as any other double *, being sure not to go out of bounds.
> }
This is nice, thanks!
j.
--
------------------------------
Date: Wed, 4 Oct 2006 10:57:28 +0000 (UTC)
From: Ilya Zakharevich <nospam-abuse@ilyaz.org>
Subject: Re: Questions about Inline::C
Message-Id: <eg042o$15uu$1@agate.berkeley.edu>
[A complimentary Cc of this posting was sent to
<xhoster@gmail.com>], who wrote in article <20061001002747.059$qn@newsreader.com>:
> You don't need to use perl guts for each manipulation. You can get the
> char* to the start of the Perl sv string memory, and then cast that into
> whatever you want. Store that casted pointer, and use it just like there
> were no Perl involved from then on.
>
> my $x= pack "d*", @list_of_numbers;
> foo($x,scalar @list_of_numbers);
>
> __C__
>
> void foo (unsigned char* s, int num_doubles) {
> double * x = (double*) s;
> //now use x as any other double *, being sure not to go out of bounds.
> }
If this works, then by coincidence only. Memory alignment of SvPV()
and of double* is absolutely different.
Hope this helps,
Ilya
P.S. In *many* cases SvPV() will point at the start of malloc()ed
region of size
1 + sizeof(double) * scalar @list_of_numbers
Since this is not divisible by sizeof(double), some m_alloc()ers
may align it differently than requests for sizeof(double) * n.
Moreover, there is no guarantie that SvPV() points at start of
malloc()ed region.
------------------------------
Date: 4 Oct 2006 11:40:27 +0200
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: Spliting values and reversing a hash
Message-Id: <i207i29tsqfsit3b8o5tphtbea9jmh3vcm@4ax.com>
On 3 Oct 2006 17:18:42 -0700, mlwollman@gmail.com wrote:
>I have a hash with key value pairs like:
> 1 => Chocolate,Vanilla,Rocky Road
> 2 => Strawberry,Vanilla, Pistachio
> 3 => Cookie Dough,Chocolate
> 4 => Strawberry,Pistachio
First of all this is neither plain English nor valid Perl so it's hard
to understand whether your values are supposed to be arrayrefs, i.e.
if you have an HoA, or if they're plain strings. Below I assume the
latter, as it was slightly easier to copy, paste and make into a
working minimal example.
As a side note if your keys are numbers anyway, and not exceedingly
sparse, you should consider using an actual array instead of a hash.
>And I need to transform it to:
> Chocolate => 1,3
> Vanilla => 1,2
[snip]
Here's the minimal example, please note that the "reverse" hash is
somewhat inconsistent with the "direct" one since it is a HoA while
the latter is not. It's up to you to modify accordingly to your actual
needs.
#!/usr/bin/perl
use strict;
use warnings;
use Data::Dumper;
my %hash=(1 => 'Chocolate,Vanilla,Rocky Road',
2 => 'Strawberry,Vanilla, Pistachio',
3 => 'Cookie Dough,Chocolate',
4 => 'Strawberry,Pistachio');
my %rev;
for my $k (keys %hash) {
push @{ $rev{$_} }, $k for split /,/, $hash{$k};
}
print Dumper \%hash, \%rev;
__END__
Michele
--
{$_=pack'B8'x25,unpack'A8'x32,$a^=sub{pop^pop}->(map substr
(($a||=join'',map--$|x$_,(unpack'w',unpack'u','G^<R<Y]*YB='
.'KYU;*EVH[.FHF2W+#"\Z*5TI/ER<Z`S(G.DZZ9OX0Z')=~/./g)x2,$_,
256),7,249);s/[^\w,]/ /g;$ \=/^J/?$/:"\r";print,redo}#JAPH,
------------------------------
Date: Wed, 04 Oct 2006 12:23:15 +0200
From: Mirco Wahab <peace.is.our.profession@gmx.de>
Subject: Re: Spliting values and reversing a hash
Message-Id: <eg02af$ql8$1@mlucom4.urz.uni-halle.de>
Thus spoke Michele Dondi (on 2006-10-04 11:40):
> It's up to you to modify accordingly to your actual
> needs.
>
> my %rev;
> for my $k (keys %hash) {
> push @{ $rev{$_} }, $k for split /,/, $hash{$k};
> }
>
Hi Michele, to re-stringify the numbers array *is* just
major part of the fun ;-)
BTW: somebody *had* eventually to come up with it ...
my %h=(1 => 'Chocolate,Vanilla,Rocky Road',
2 => 'Strawberry,Vanilla, Pistachio',
3 => 'Cookie Dough,Chocolate',
4 => 'Strawberry,Pistachio');
my %r;
(($_=join '',%h)=~s/\s//g),s/(\d)([^\d]+)/ $r{$_}.=','x!!defined($r{$_}).$1for(split',',$2)/eg;
;-))
Regards
M.
------------------------------
Date: 4 Oct 2006 12:49:55 +0200
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: Spliting values and reversing a hash
Message-Id: <b647i2152ft8homu0p4tb4d75t9ka3bnh9@4ax.com>
On Wed, 04 Oct 2006 12:23:15 +0200, Mirco Wahab
<peace.is.our.profession@gmx.de> wrote:
>> push @{ $rev{$_} }, $k for split /,/, $hash{$k};
>> }
>>
>
>Hi Michele, to re-stringify the numbers array *is* just
>major part of the fun ;-)
It's not that hard to do so in the first place:
$rev{$_} .= defined $rev{$_} ? ",$k" : $k
for split /,/, $hash{$k};
Michele
--
{$_=pack'B8'x25,unpack'A8'x32,$a^=sub{pop^pop}->(map substr
(($a||=join'',map--$|x$_,(unpack'w',unpack'u','G^<R<Y]*YB='
.'KYU;*EVH[.FHF2W+#"\Z*5TI/ER<Z`S(G.DZZ9OX0Z')=~/./g)x2,$_,
256),7,249);s/[^\w,]/ /g;$ \=/^J/?$/:"\r";print,redo}#JAPH,
------------------------------
Date: Wed, 04 Oct 2006 13:53:56 +0200
From: Mirco Wahab <peace.is.our.profession@gmx.de>
Subject: Re: Spliting values and reversing a hash
Message-Id: <eg07kh$s69$1@mlucom4.urz.uni-halle.de>
Thus spoke Michele Dondi (on 2006-10-04 12:49):
> On Wed, 04 Oct 2006 12:23:15 +0200, Mirco Wahab
> <peace.is.our.profession@gmx.de> wrote:
>
>>> push @{ $rev{$_} }, $k for split /,/, $hash{$k};
>> re-stringify the numbers array
>
> It's not that hard to do so in the first place:
>
> $rev{$_} .= defined $rev{$_} ? ",$k" : $k
> for split /,/, $hash{$k};
Aehmm, you didn't pull the
leading \s+ from keys, eg. ' Pistachio'.
Why did you choose the explicit form of:
$rev{$_} .= ','x defined $rev{$_} . $k
I guess it's not always ok to expect that
'defined' gets evaluated to 0/1 !?
Regards
Mirco
BTW. some kind of a perlgolf version
anybody - for learning purpose? (the
hash has to be %h):
@_=%h;%h=(),($_="@_")
=~s/\s//g,s/(\d+)
([^\d]+)/$h{$_}
.=','x defined
($h{$_}).$1
for(split
',',$2)
/egx
;
------------------------------
Date: 4 Oct 2006 12:25:05 GMT
From: anno4000@radom.zrz.tu-berlin.de
Subject: Re: Spliting values and reversing a hash
Message-Id: <4ohnh1Fef19sU1@news.dfncis.de>
Mirco Wahab <peace.is.our.profession@gmx.de> wrote in comp.lang.perl.misc:
> Thus spoke Michele Dondi (on 2006-10-04 12:49):
> > On Wed, 04 Oct 2006 12:23:15 +0200, Mirco Wahab
> > <peace.is.our.profession@gmx.de> wrote:
> >
> >>> push @{ $rev{$_} }, $k for split /,/, $hash{$k};
> >> re-stringify the numbers array
> >
> > It's not that hard to do so in the first place:
> >
> > $rev{$_} .= defined $rev{$_} ? ",$k" : $k
> > for split /,/, $hash{$k};
>
> Aehmm, you didn't pull the
> leading \s+ from keys, eg. ' Pistachio'.
>
> Why did you choose the explicit form of:
Did you mean "Why did you *not* choose..."?
> $rev{$_} .= ','x defined $rev{$_} . $k
>
> I guess it's not always ok to expect that
> 'defined' gets evaluated to 0/1 !?
In Perl a boolean false is a dual-valued scalar. Used as a number it
is 0, used as a string it is "". A boolean true is indistinguishable
from 1. With this kind of boolean the construct works as intended.
The problem is that
- the behavior seems to be nowhere documented and
- there are exceptions: the short-circuiting boolean operators || and
&& can return anything.
Anno
------------------------------
Date: 4 Oct 2006 05:56:07 -0700
From: "matt" <darthmullet67@hotmail.com>
Subject: substitution question
Message-Id: <1159966567.717340.44030@m73g2000cwd.googlegroups.com>
I am parsing through a text file and trying the following substitution:
$_=~s/([(])"/$1\+37/g;
I am looking for times where there are (" in the text file and I need
those to be replaced with (+37
However, the substitution is replacing (" with (+3 7 <===space between
the 3 and the 7
What is wrong with this substitution?
Thanks in advance
Matt
------------------------------
Date: 4 Oct 2006 05:59:22 -0700
From: "Paul Lalli" <mritty@gmail.com>
Subject: Re: substitution question
Message-Id: <1159966762.686921.163280@h48g2000cwc.googlegroups.com>
matt wrote:
> I am parsing through a text file and trying the following substitution:
> $_=~s/([(])"/$1\+37/g;
>
> I am looking for times where there are (" in the text file and I need
> those to be replaced with (+37
>
> However, the substitution is replacing (" with (+3 7 <===space between
> the 3 and the 7
>
> What is wrong with this substitution?
Nothing.
Please post a SHORT but COMPLETE script that demonstrates this failure.
While the code you posted should work as you described, the following
looks much cleaner to me, and should do the same thing:
s/\("/(+37/g;
Paul Lalli
------------------------------
Date: 4 Oct 2006 11:21:57 +0200
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: this is annoying
Message-Id: <v7v6i2ha4u0v6hobjhiug3isngdi0a5uj1@4ax.com>
On 3 Oct 2006 19:00:16 GMT, anno4000@radom.zrz.tu-berlin.de wrote:
>That's a valiant attempt to justify MisterPerl's broken code, but even
>that won't work. The second argument of split() is evaluated in scalar
Indeed, I realized myself:
<news:r3c5i2hgrupb79ds1pocu4lfsk7sr06dvn@4ax.com>.
Michele
--
{$_=pack'B8'x25,unpack'A8'x32,$a^=sub{pop^pop}->(map substr
(($a||=join'',map--$|x$_,(unpack'w',unpack'u','G^<R<Y]*YB='
.'KYU;*EVH[.FHF2W+#"\Z*5TI/ER<Z`S(G.DZZ9OX0Z')=~/./g)x2,$_,
256),7,249);s/[^\w,]/ /g;$ \=/^J/?$/:"\r";print,redo}#JAPH,
------------------------------
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 9802
***************************************