[25215] in Perl-Users-Digest
Perl-Users Digest, Issue: 7460 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Nov 29 09:06:05 2004
Date: Mon, 29 Nov 2004 06:05:08 -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 Mon, 29 Nov 2004 Volume: 10 Number: 7460
Today's topics:
$SIG{IO} example <sppNOSPAM@monaco377.com>
Re: $SIG{IO} example (Anno Siegel)
Re: $SIG{IO} example <sppNOSPAM@monaco377.com>
Re: $SIG{IO} example (Anno Siegel)
Re: $SIG{IO} example <apeiron@comcast.net>
Re: $SIG{IO} example <sppNOSPAM@libello.com>
Re: $SIG{IO} example <do-not-use@invalid.net>
Re: $SIG{IO} example (Anno Siegel)
Re: $SIG{IO} example <wyzelli@yahoo.com>
Re: 500 Can't connect to search.cpan.org:80 (Bad protoc <wyzelli@yahoo.com>
Re: 500 Can't connect to search.cpan.org:80 (Bad protoc <bik.mido@tiscalinet.it>
Re: 500 Can't connect to search.cpan.org:80 (Bad protoc <wyzelli@yahoo.com>
Re: escape whitespace in qw/ / (Anno Siegel)
FAQ 8.24: Why can't I get the output of a command with <comdog@panix.com>
Re: hashing function <someone@example.com>
Re: hex to binary conversion <someone@example.com>
MLDBM error <z3r0.00 @ gmail.com>
Re: Need some problemsolving-cgi/xml <spamtrap@dot-app.org>
Re: perl trim function <do-not-use@invalid.net>
Reading/writing wide characters <josef.moellers@fujitsu-siemens.com>
Re: Reading/writing wide characters <flavell@ph.gla.ac.uk>
Re: Unix commands and perl <vek@station02.ohout.pharmapartners.nl>
Re: Unix commands and perl <bik.mido@tiscalinet.it>
Re: Win32API::Registry, RegOpenKeyEx fails [The paramet <ThomasKratz@REMOVEwebCAPS.de>
Re: Win32API::Registry, RegOpenKeyEx fails [The paramet <ThomasKratz@REMOVEwebCAPS.de>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Mon, 29 Nov 2004 11:31:23 +0100
From: =?ISO-8859-15?Q?S=E9bastien?= Cottalorda <sppNOSPAM@monaco377.com>
Subject: $SIG{IO} example
Message-Id: <41aafa7e$0$2090$626a14ce@news.free.fr>
Hi all,
I'm planning to make a script that, on socket reception, do reception, but
the rest of time do something else.
#======================================================================
#!/usr/bin/perl -w
use IO::Select;
use IO::Socket;
unless ($socket = IO::Socket::INET->new(PeerAddr=> $adr_ip,
PeerPort=> $port,
Proto=> "tcp",
Timeout=>10,
Type=> SOCK_STREAM)){
die "Unable to create a tcp server $!";
}
$s->add($socket);
$SIG{IO}=\$do_reception;
while(1) {
#
# do something ...
# even sending datas throught the socket
#
}
sub do_reception{
if ($s->can_read(10)){
&logmsg("Reception ...\n");
if (defined $socket->recv($data_work,1024,0)){
print "< $data_work\n";
}
else {
print "Unable to receive\n";
}
}
else {
print "Timeout Receiving\n";
}
}
I've made that but it doesn't seem to work.
Do you have a SIG{IO} exemple program
Thanks in advance for any kind of help.
Sébastien Cottalorda
--
[ retirer NOSPAM pour répondre directement
remove NOSPAM to reply directly ]
------------------------------
Date: 29 Nov 2004 10:44:01 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: $SIG{IO} example
Message-Id: <coeuhh$8in$1@mamenchi.zrz.TU-Berlin.DE>
Sébastien Cottalorda <sppNOSPAM@monaco377.com> wrote in comp.lang.perl.misc:
> Hi all,
>
> I'm planning to make a script that, on socket reception, do reception, but
> the rest of time do something else.
[...]
> $SIG{IO}=\$do_reception;
What makes you think $SIG{IO} does anything useful?
Anno
------------------------------
Date: Mon, 29 Nov 2004 11:57:59 +0100
From: =?ISO-8859-15?Q?S=E9bastien?= Cottalorda <sppNOSPAM@monaco377.com>
Subject: Re: $SIG{IO} example
Message-Id: <41ab00b9$0$2118$626a14ce@news.free.fr>
Anno Siegel wrote:
> Sébastien Cottalorda <sppNOSPAM@monaco377.com> wrote in
> comp.lang.perl.misc:
>> Hi all,
>>
>> I'm planning to make a script that, on socket reception, do reception,
>> but the rest of time do something else.
>
> [...]
>
>> $SIG{IO}=\$do_reception;
>
> What makes you think $SIG{IO} does anything useful?
>
> Anno
Someone, who as used SIG{IO} in C programming, told me that catching that
signal can solve my problem.
How can I manage to do want I need ?
using IO::Select to check, in non blocking mode, if I can read ?
Thanks for you help.
Sébastien Cottalorda
--
[ retirer NOSPAM pour répondre directement
remove NOSPAM to reply directly ]
------------------------------
Date: 29 Nov 2004 11:21:50 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: $SIG{IO} example
Message-Id: <cof0oe$8in$2@mamenchi.zrz.TU-Berlin.DE>
Sébastien Cottalorda <sppNOSPAM@monaco377.com> wrote in comp.lang.perl.misc:
> Anno Siegel wrote:
>
> > Sébastien Cottalorda <sppNOSPAM@monaco377.com> wrote in
> > comp.lang.perl.misc:
> >> Hi all,
> >>
> >> I'm planning to make a script that, on socket reception, do reception,
> >> but the rest of time do something else.
> >
> > [...]
> >
> >> $SIG{IO}=\$do_reception;
> >
> > What makes you think $SIG{IO} does anything useful?
> >
> > Anno
>
> Someone, who as used SIG{IO} in C programming, told me that catching that
> signal can solve my problem.
Huh? SIGIO doesn't exist on any system I know.
> How can I manage to do want I need ?
> using IO::Select to check, in non blocking mode, if I can read ?
Read perldoc IO::Select. If you have specific questions, ask.
Anno
------------------------------
Date: 29 Nov 2004 11:36:27 GMT
From: Christopher Nehren <apeiron@comcast.net>
Subject: Re: $SIG{IO} example
Message-Id: <slrncqm2dr.1s69.apeiron@prophecy.dyndns.org>
On 2004-11-29, Anno Siegel scribbled these
curious markings:
> Huh? SIGIO doesn't exist on any system I know.
% kill -l
hup int quit ill trap abrt emt fpe kill bus segv sys pipe alrm term urg
stop tstp cont chld ttin ttou io xcpu xfsz vtalrm prof winch info usr1
^^
usr2
% uname -rs
FreeBSD 5.3-STABLE
Same on OpenBSD 3.6-STABLE, except tr[a-z][A-Z].
--
I abhor a system designed for the "user", if that word is a coded
pejorative meaning "stupid and unsophisticated". -- Ken Thompson
Linux: "How rebellious ... in a conformist sort of way."
Unix is user friendly. However, it isn't idiot friendly.
------------------------------
Date: Mon, 29 Nov 2004 13:06:48 +0100
From: =?ISO-8859-15?Q?S=E9bastien?= Cottalorda <sppNOSPAM@libello.com>
Subject: Re: $SIG{IO} example
Message-Id: <41ab10da$0$2109$626a14ce@news.free.fr>
Anno Siegel wrote:
> Sébastien Cottalorda <sppNOSPAM@monaco377.com> wrote in
> comp.lang.perl.misc:
>> Anno Siegel wrote:
>>
>> > Sébastien Cottalorda <sppNOSPAM@monaco377.com> wrote in
>> > comp.lang.perl.misc:
>> >> Hi all,
>> >>
>> >> I'm planning to make a script that, on socket reception, do reception,
>> >> but the rest of time do something else.
>> >
>> > [...]
>> >
>> >> $SIG{IO}=\$do_reception;
>> >
>> > What makes you think $SIG{IO} does anything useful?
>> >
>> > Anno
>>
>> Someone, who as used SIG{IO} in C programming, told me that catching that
>> signal can solve my problem.
>
> Huh? SIGIO doesn't exist on any system I know.
>
>> How can I manage to do want I need ?
>> using IO::Select to check, in non blocking mode, if I can read ?
>
> Read perldoc IO::Select. If you have specific questions, ask.
>
> Anno
# uname -a
Linux pc_seb 2.4.21-0.13mdk #1 Fri Mar 14 15:08:06 EST 2003 i686 unknown
unknown GNU/Linux
# kill -l
[snip]
29) SIGIO
[snip]
My program is a real time program:
- it need to receive asynchronous datas and reply immediately.
- it need to send regularily datas throught the socket (equipment check)
My problem is:
* If I wait for reading datas, I cannot send regularily anymore.
* If I make a non blocking loop:
while (1) {
if ($s->can_read(1)){
# ...
}
if ($s->can_write(1)){
# process that can take time
}
}
I'm frightened to make a infinite loop if I did'nt have nothing to send and
if I don't have to receive something.
That solution could not work either because if I take too long time to send
datas, I lost the real time on the reception.
That's why the best idea is, if possible, to catch a signal (I though
SIG{IO}), and make the reception immediately, then return to the normal
process.
Regards
Sebastien Cottalorda
--
[ retirer NOSPAM pour répondre directement
remove NOSPAM to reply directly ]
------------------------------
Date: 29 Nov 2004 13:07:42 +0100
From: Arndt Jonasson <do-not-use@invalid.net>
Subject: Re: $SIG{IO} example
Message-Id: <yzdu0r8n9ip.fsf@invalid.net>
Christopher Nehren <apeiron@comcast.net> writes:
> On 2004-11-29, Anno Siegel scribbled these
> curious markings:
> > Huh? SIGIO doesn't exist on any system I know.
>
> % kill -l
> hup int quit ill trap abrt emt fpe kill bus segv sys pipe alrm term urg
> stop tstp cont chld ttin ttou io xcpu xfsz vtalrm prof winch info usr1
> ^^
> usr2
> % uname -rs
> FreeBSD 5.3-STABLE
>
> Same on OpenBSD 3.6-STABLE, except tr[a-z][A-Z].
For what it's worth, SIGIO exists on HP-UX and AIX too. Of course, it
remains the case that using SIGIO is not a portable way to do I/O.
------------------------------
Date: 29 Nov 2004 12:19:22 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: $SIG{IO} example
Message-Id: <cof44a$cq3$1@mamenchi.zrz.TU-Berlin.DE>
Arndt Jonasson <do-not-use@invalid.net> wrote in comp.lang.perl.misc:
>
> Christopher Nehren <apeiron@comcast.net> writes:
> > On 2004-11-29, Anno Siegel scribbled these
> > curious markings:
> > > Huh? SIGIO doesn't exist on any system I know.
> >
> > % kill -l
> > hup int quit ill trap abrt emt fpe kill bus segv sys pipe alrm term urg
> > stop tstp cont chld ttin ttou io xcpu xfsz vtalrm prof winch info usr1
> > ^^
> > usr2
> > % uname -rs
> > FreeBSD 5.3-STABLE
> >
> > Same on OpenBSD 3.6-STABLE, except tr[a-z][A-Z].
>
> For what it's worth, SIGIO exists on HP-UX and AIX too.
I see. I never noticed.
> Of course, it
> remains the case that using SIGIO is not a portable way to do I/O.
Maybe a good reason not to notice :)
Anno
------------------------------
Date: Mon, 29 Nov 2004 12:25:44 GMT
From: "Peter Wyzl" <wyzelli@yahoo.com>
Subject: Re: $SIG{IO} example
Message-Id: <czEqd.52637$K7.5338@news-server.bigpond.net.au>
"Sébastien Cottalorda" <sppNOSPAM@libello.com> wrote in message
news:41ab10da$0$2109$626a14ce@news.free.fr...
: Anno Siegel wrote:
<snip>
:
: My program is a real time program:
: - it need to receive asynchronous datas and reply immediately.
: - it need to send regularily datas throught the socket (equipment
check)
: My problem is:
: * If I wait for reading datas, I cannot send regularily anymore.
: * If I make a non blocking loop:
: while (1) {
: if ($s->can_read(1)){
: # ...
: }
: if ($s->can_write(1)){
: # process that can take time
: }
: }
: I'm frightened to make a infinite loop if I did'nt have nothing to
send and
: if I don't have to receive something.
: That solution could not work either because if I take too long time
to send
: datas, I lost the real time on the reception.
: That's why the best idea is, if possible, to catch a signal (I though
: SIG{IO}), and make the reception immediately, then return to the normal
: process.
I would approach this as two separate programs communicating with each other
with some form of IPC (perhaps even simple file updating).
The reading program can handle the 'instant response' and the writing
program can be regular.
Then I would look at possible threads (one for each task) or maybe a forked
process once I had the other part working fine.
--
Wyzelli
------------------------------
Date: Mon, 29 Nov 2004 08:47:52 GMT
From: "Peter Wyzl" <wyzelli@yahoo.com>
Subject: Re: 500 Can't connect to search.cpan.org:80 (Bad protocol 'tcp') at web.plline 24.
Message-Id: <YmBqd.52083$K7.12011@news-server.bigpond.net.au>
"Bob Walton" <see@sig.invalid> wrote in message
news:41aa8e4c$1_5@127.0.0.1...
: Peter Wyzl wrote:
:
: > "Bob Walton" <see@sig.invalid> wrote in message
: > news:41a95acb$1_4@127.0.0.1...
: > : Nirvana wrote:
: ...
: > command.com and cmd.exe both understand / as well as \ for directory
: > seperators.
:
: Bull****. A / does not work as a directory separator in DOS or Windoze,
: and never has -- it is a command options or "switch" designator:
:
: D:\junk>dir d:/junk
: Invalid switch - "junk".
:
: D:\junk>ver
:
: Microsoft Windows XP [Version 5.1.2600]
I beg to differ... the problem you have is with the dir command, not
cmd.exe.
you can 'cd' to /junk
you can cd to /junk/junk2 etc
open (IN, 'c:/junk/junk2/file.txt') or die "Can't $!\n";
works perfectly fine as well.
Since we are dealing with Perl, the context of the comment is important, in
that a forward slash works perfectly well, in all instances except accessing
the root of a drive directly, where I have found that c:\\ is more reliable
(particularly with File::Find which is a little inconsistent with what it
reports for files and directories).
--
Wyzelli
(tested the above???)
------------------------------
Date: Mon, 29 Nov 2004 12:21:19 +0100
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: 500 Can't connect to search.cpan.org:80 (Bad protocol 'tcp') at web.plline 24.
Message-Id: <ih0mq0t6g8nsng397s94s39dkqd3mc2b9m@4ax.com>
On Mon, 29 Nov 2004 08:47:52 GMT, "Peter Wyzl" <wyzelli@yahoo.com>
wrote:
>: > command.com and cmd.exe both understand / as well as \ for directory
>: > seperators.
>:
>: Bull****. A / does not work as a directory separator in DOS or Windoze,
>: and never has -- it is a command options or "switch" designator:
[...]
>I beg to differ... the problem you have is with the dir command, not
>cmd.exe.
>
>you can 'cd' to /junk
>
>you can cd to /junk/junk2 etc
>
>open (IN, 'c:/junk/junk2/file.txt') or die "Can't $!\n";
>
>works perfectly fine as well.
I beg to differ... what you wrote is still BS, since it has nothing to
do with command.com and/or cmd.exe: indeed Windows *APIs* do support
both '/' and '\' as directory separators. You can even mix them in a
single specification.
>Since we are dealing with Perl, the context of the comment is important, in
>that a forward slash works perfectly well, in all instances except accessing
It works perfectly *within* perl[1]. Still this has NOTHING to do with
either command.com or cmd.exe! Whatever the context of the comment can
be, whatever we're dealing with, what you wrote about command.com and
cmd.exe is WRONG, period.
The examples you gave are wrong and misleading as they have nothing to
do with any shell (apart a possible ambiguity with C<cd>, that could
be interpreted as an internal Perl command or a shell one).
[1] no matter if by means of some magic it does or directly by means
of Windows APIs capabilities. I don't know which of the two is true,
BTW...
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: Mon, 29 Nov 2004 12:02:54 GMT
From: "Peter Wyzl" <wyzelli@yahoo.com>
Subject: Re: 500 Can't connect to search.cpan.org:80 (Bad protocol 'tcp') at web.plline 24.
Message-Id: <OdEqd.52600$K7.51574@news-server.bigpond.net.au>
"Michele Dondi" <bik.mido@tiscalinet.it> wrote in message
news:ih0mq0t6g8nsng397s94s39dkqd3mc2b9m@4ax.com...
: On Mon, 29 Nov 2004 08:47:52 GMT, "Peter Wyzl" <wyzelli@yahoo.com>
: wrote:
:
: >: > command.com and cmd.exe both understand / as well as \ for directory
: >: > seperators.
: >:
: >: Bull****. A / does not work as a directory separator in DOS or
Windoze,
: >: and never has -- it is a command options or "switch" designator:
: [...]
: >I beg to differ... the problem you have is with the dir command, not
: >cmd.exe.
: >
: >you can 'cd' to /junk
: >
: >you can cd to /junk/junk2 etc
: >
: >open (IN, 'c:/junk/junk2/file.txt') or die "Can't $!\n";
: >
: >works perfectly fine as well.
:
: I beg to differ... what you wrote is still BS, since it has nothing to
: do with command.com and/or cmd.exe: indeed Windows *APIs* do support
: both '/' and '\' as directory separators. You can even mix them in a
: single specification.
:
: >Since we are dealing with Perl, the context of the comment is important,
in
: >that a forward slash works perfectly well, in all instances except
accessing
:
: It works perfectly *within* perl[1]. Still this has NOTHING to do with
: either command.com or cmd.exe! Whatever the context of the comment can
: be, whatever we're dealing with, what you wrote about command.com and
: cmd.exe is WRONG, period.
:
: The examples you gave are wrong and misleading as they have nothing to
: do with any shell (apart a possible ambiguity with C<cd>, that could
: be interpreted as an internal Perl command or a shell one).
:
:
: [1] no matter if by means of some magic it does or directly by means
: of Windows APIs capabilities. I don't know which of the two is true,
: BTW...
Windows API.
To get back to the original comment, Bob said that as far as he knew it had
to have a literal backslash if Windows was looking at it. I countered that
this is not true. There are cases where Windows requires a literal
backslash (File::Find suffers from it) but it is not universally true. Bob
gave an example where a forward slash is not accepted (/ being a switch
delimiter) and I gave an example where it is. Within Perl / is accepted
because perl does the right thing. Stating that 'Windows requires a literal
backslash' is what was incorrect.
However, this was not intended to be a discussion about Windows or cmd.exe.
It WAS intended to be a discussion about what happens within [Pp]erl and
that / can be used as much as \\ in programs written in Perl. This enhances
readability and portability.
What I wrote about cmd.exe is not wrong, I gave an example that supported
that statement. This is NOT universal, and is not even the difference
between internal/external commands. However, the point I was making was
(trying to make?) is that / works in perl. Why you have to tell me I wrote
BS and then state the same thing is a little confusing to me.
--
Wyzelli
if (-e 'c:/windows/win.ini'){print 'Just another Perl Hacker'};
------------------------------
Date: 29 Nov 2004 13:52:40 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: escape whitespace in qw/ /
Message-Id: <cof9j8$hgm$1@mamenchi.zrz.TU-Berlin.DE>
Leon <eon@hotmail.com> wrote in comp.lang.perl.misc:
> "chris" <nadsinoz@hotmail.com> wrote in message
> news:b8996f29.0411250741.66020368@posting.google.com...
> > I have a whitespace separated list where some of the fields actually
> > should have a extra whitespace character. Is there a way I can escape
> > this space so I can use qw// to create the list:
> >
> > @list = qw/ 1.0 UK Y 2.5 /;
> >
> > where UK is actually 'UK ' (without the quotes).
>
> @list = ('1.0', 'UK ', 'Y', '2.5');
>
> >
> > Is this possible?
No. qw// is simply q// followed by a split on whitespace. No way
to conserve blanks.
Anno
------------------------------
Date: Mon, 29 Nov 2004 11:03:02 +0000 (UTC)
From: PerlFAQ Server <comdog@panix.com>
Subject: FAQ 8.24: Why can't I get the output of a command with system()?
Message-Id: <coevl6$iho$1@reader1.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.
--------------------------------------------------------------------
8.24: Why can't I get the output of a command with system()?
You're confusing the purpose of system() and backticks (``). system()
runs a command and returns exit status information (as a 16 bit value:
the low 7 bits are the signal the process died from, if any, and the
high 8 bits are the actual exit value). Backticks (``) run a command and
return what it sent to STDOUT.
$exit_status = system("mail-users");
$output_string = `ls`;
--------------------------------------------------------------------
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: Mon, 29 Nov 2004 10:27:42 GMT
From: "John W. Krahn" <someone@example.com>
Subject: Re: hashing function
Message-Id: <yQCqd.203550$df2.195860@edtnps89>
Dan Jones wrote:
> I'm working with some large (several hundred megs) flat database files. I
> need to examine the records for duplicates. Obviously, I don't want to
> store several hundred megs of data in a hash. What I'd like to do is to
> read each record, generate a hash value for the record, store that hash
> value and an index key rather than storing the entire record, and look for
> collisions in the hash value.
>
> Perl obviously uses an internal hashing function to create it's hash
> variables. Is it possible to access this function or to get the actual
> hash value it produces? If not, any pointers to a module or information on
> writing a hashing function in Perl would be appreciated. Hashing functions
> usually involve low level bit twiddling. While it's probably possible to
> do this directly in Perl (what isn't?), I don't know enough Perl to do it.
> Right now, I'm looking at using a C function, then having to integrate that
> with Perl. I'd really prefer to keep this a pure Perl script if I can.
>
> I've been through the Camel, the Panther, and the Ram without finding
> anything relevant. The Cookbook does mention that using hashes to search
> for dupes is memory intensive if you have large records but doesn't provide
> any alternatives that I could find. Searching for information on hashing
> functions and Perl on the web has proven to be an exercise in futility due
> to the naming collision with the variable type.
Here is an example using Digest::MD5 that may suit your needs:
#!/usr/bin/perl
use warnings;
use strict;
use Digest::MD5 'md5';
my $file = 'database.file';
my ( $loc, %data ) = 0;
@ARGV = $file;
while ( <> ) {
push @{ $data{ md5 $_ } }, $loc;
$loc = tell ARGV;
}
close ARGV;
# remove all duplicates except the first one
my @dups = sort { $a <=> $b } map splice( @$_, 1 ), values %data;
# or alternately remove all except the last one
# my @dups = sort { $a <=> $b } map splice( @$_, 0, $#$_ ), values %data;
( $loc, $^I, @ARGV ) = ( 0, '.bck', $file );
while ( <> ) {
if ( @dups and $loc == $dups[ 0 ] ) {
shift @dups;
next;
}
print;
$loc = tell ARGV;
}
__END__
John
--
use Perl;
program
fulfillment
------------------------------
Date: Mon, 29 Nov 2004 10:47:12 GMT
From: "John W. Krahn" <someone@example.com>
Subject: Re: hex to binary conversion
Message-Id: <Q6Dqd.203876$df2.176179@edtnps89>
Jeffrey Ross wrote:
> I can convert "414243" to "ABC" using awk (see below) but wonder if there's
> a simpler way of doing it in Perl.
> perl -e 'printf "%c", hex("41")' # works for a single
> hard-coded 2-character string
>
> How do I do it for lines of arbitrary length?
$ perl -le' $_ = pack "H*", "414243"; print '
ABC
John
--
use Perl;
program
fulfillment
------------------------------
Date: Tue, 30 Nov 2004 12:34:45 +1100
From: Mark Ng <z3r0.00 @ gmail.com>
Subject: MLDBM error
Message-Id: <pan.2004.11.30.01.34.40.190130@gmail.com>
Hi,
I got a file that was created using MLDBM (DB_File Storable) a couple of
years ago. Now, when I tried to load it I get this error:
MLDBM error: Second level tie failed, "" at data.pm line 290
Any suggestions on how I can read the file ?
I am using perl 5.8.4 on Debian.
Thanks,
mark
------------------------------
Date: Mon, 29 Nov 2004 04:16:53 -0500
From: Sherm Pendley <spamtrap@dot-app.org>
Subject: Re: Need some problemsolving-cgi/xml
Message-Id: <WbCdnQSsnsGYdDfcRVn-pA@adelphia.com>
lievemario wrote:
> Hope I get some solution.
You *did* get answers. Three of 'em, last week when you posted this
question the first time. You've been given some very good advice - you
really should follow it.
BTW, have you read the posting guidelines that appear here often?
sherm--
--
Cocoa programming in Perl: http://camelbones.sourceforge.net
Hire me! My resume: http://www.dot-app.org
------------------------------
Date: 29 Nov 2004 12:41:14 +0100
From: Arndt Jonasson <do-not-use@invalid.net>
Subject: Re: perl trim function
Message-Id: <yzdy8gknaqt.fsf@invalid.net>
"Tassilo v. Parseval" <tassilo.von.parseval@rwth-aachen.de> writes:
> sub trim ($) {
> if (! defined wantarray) {
> $_[0] =~ s/^\s+//;
> $_[0] =~ s/\s+$//;
> return;
> }
> my $string = shift;
> $string =~ s/^\s+//;
> $string =~ s/\s+$//;
> return $string;
> }
I think it's a good idea to always try to avoid duplicated code
(*). Using an auxiliary function and sending \$_[0] and \$string to
it, respectively, as below, seems to work. Since I'm new to Perl,
I have to ask: is it a good way? Are there other ways?
(If speed is important, one has to do benchmark tests and see if the
overhead of the extra function is acceptable.)
sub trim1 ($) {
my $r = shift;
$$r =~ s/^\s+//;
$$r =~ s/\s+$//;
}
sub trim ($) {
if (! defined wantarray) {
trim1 \$_[0];
return;
}
my $string = shift;
trim1 \$string;
return $string;
}
(*) Not that much can go wrong in this function as it stands, but if it
grows and changes semantics, the same logic will have to be entered in
two places every time, and one may easily miss something.
------------------------------
Date: Mon, 29 Nov 2004 09:25:14 +0100
From: Josef Moellers <josef.moellers@fujitsu-siemens.com>
Subject: Reading/writing wide characters
Message-Id: <coem8k$kof$1@nntp.fujitsu-siemens.com>
Hi,
I have an MP3 player (an iPod clone?) which stores its playlist with=20
wide (16 bit) characters. I'd like to manipulate the playlist using=20
perl. Is there a way to transparently handle wide characters so I can=20
read other, non-wide, files and write wide characters to the playlist?
TIA,
Josef
--=20
Josef M=F6llers (Pinguinpfleger bei FSC)
If failure had no penalty success would not be a prize
-- T. Pratchett
------------------------------
Date: Mon, 29 Nov 2004 09:42:29 +0000
From: "Alan J. Flavell" <flavell@ph.gla.ac.uk>
Subject: Re: Reading/writing wide characters
Message-Id: <Pine.LNX.4.61.0411290934480.23737@ppepc56.ph.gla.ac.uk>
On Mon, 29 Nov 2004, Josef Moellers wrote:
> I have an MP3 player (an iPod clone?) which stores its playlist with
> wide (16 bit) characters.
Possibly utf-16 (of one or other endianness)?
> I'd like to manipulate the playlist using perl. Is there a way to
> transparently handle wide characters so I can read other, non-wide,
> files and write wide characters to the playlist?
Yes. Look into encode layers in 5.8.*, or explicit Encode calls if
in 5.6 (but better to upgrade).
Start with perluniintro and work out from there (perlunicode,
encoding, Encode ...)
Once you've assured that you can read-in what you've got, to Perl's
natural internal format, then it should be plain sailing (output
should just be the converse).
------------------------------
Date: 29 Nov 2004 08:24:18 GMT
From: Villy Kruse <vek@station02.ohout.pharmapartners.nl>
Subject: Re: Unix commands and perl
Message-Id: <slrncqln5i.q9.vek@station02.ohout.pharmapartners.nl>
On Sun, 28 Nov 2004 18:40:16 -0500,
Sherm Pendley <spamtrap@dot-app.org> wrote:
> AS wrote:
>
>> I need to take the output of one command put it into the next one use
>> that ooutput in a third command. e.g.,
>> system ('id | awk '{print $2}' | cut -d\( -f2 | cut -d\) -f1');
>
> Is that your real code? If so, you have the quoting mixed up - that
> doesn't even parse.
>
> Fix the quoting by escaping the inner set of single quotes like this:
> '... | awk \'{print $2}\' | ...'
>
Guess the OP never heard about q// quoting?
system (q[id | awk '{print $2}' | cut -d\( -f2 | cut -d\) -f1]);
Villy
------------------------------
Date: Mon, 29 Nov 2004 12:21:21 +0100
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: Unix commands and perl
Message-Id: <qc1mq0d0n8077janilt46q9k1pg24alb9e@4ax.com>
On 28 Nov 2004 14:45:58 -0800, solanki1961@yahoo.com (AS) wrote:
>I need to take the output of one command put it into the next one use
>that ooutput in a third command. e.g.,
>system ('id | awk '{print $2}' | cut -d\( -f2 | cut -d\) -f1');
Incidentally it's very very poor programming to use clumsy constructs
calling external programs to do something that perl can do more
reliably, clearly and fast in the first place.
In other words, no need and (no gain!) to use perl like shell
scripting: use shell scripting if you really want that...
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: Mon, 29 Nov 2004 11:32:35 +0100
From: Thomas Kratz <ThomasKratz@REMOVEwebCAPS.de>
Subject: Re: Win32API::Registry, RegOpenKeyEx fails [The parameter is incorrect]
Message-Id: <41aafac1$0$17095$bb690d87@news.main-rheiner.de>
Brian McCauley wrote:
> I suggest you avoid the low level module and use the higher level
> Tie::Registry. Not only because it's a lot simpler and this is what the
> documentation of Win32API::Registry suggests but also because the
> Win32API::* documentation is so full of errors and contradictions that
> it's nigh on imposible to tell if you are using them correctly.
I fully agree, but like to mention the module is called
Win32::TieRegistry
Thomas
--
$/=$,,$_=<DATA>,s,(.*),$1,see;__END__
s,^(.*\043),,mg,@_=map{[split'']}split;{#>J~.>_an~>>e~......>r~
$_=$_[$%][$"];y,<~>^,-++-,?{$/=--$|?'"':#..u.t.^.o.P.r.>ha~.e..
'%',s,(.),\$$/$1=1,,$;=$_}:/\w/?{y,_, ,,#..>s^~ht<._..._..c....
print}:y,.,,||last,,,,,,$_=$;;eval,redo}#.....>.e.r^.>l^..>k^.-
------------------------------
Date: Mon, 29 Nov 2004 11:40:09 +0100
From: Thomas Kratz <ThomasKratz@REMOVEwebCAPS.de>
Subject: Re: Win32API::Registry, RegOpenKeyEx fails [The parameter is incorrect]
Message-Id: <41aafc89$0$17095$bb690d87@news.main-rheiner.de>
Thomas Kratz wrote:
> Brian McCauley wrote:
>
>> I suggest you avoid the low level module and use the higher level
>> Tie::Registry. Not only because it's a lot simpler and this is what
>> the documentation of Win32API::Registry suggests but also because the
>> Win32API::* documentation is so full of errors and contradictions that
>> it's nigh on imposible to tell if you are using them correctly.
>
>
> I fully agree, but like to mention the module is called
>
> Win32::TieRegistry
I just had a look at CPAN and there is indeed a module called
Tie::Registry that seems to be an early predecessor of Win32::TieRegistry.
Perhaps the author (Tye McQueen) should withdraw it from the Tie hierarchy.
Thomas
--
$/=$,,$_=<DATA>,s,(.*),$1,see;__END__
s,^(.*\043),,mg,@_=map{[split'']}split;{#>J~.>_an~>>e~......>r~
$_=$_[$%][$"];y,<~>^,-++-,?{$/=--$|?'"':#..u.t.^.o.P.r.>ha~.e..
'%',s,(.),\$$/$1=1,,$;=$_}:/\w/?{y,_, ,,#..>s^~ht<._..._..c....
print}:y,.,,||last,,,,,,$_=$;;eval,redo}#.....>.e.r^.>l^..>k^.-
------------------------------
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 7460
***************************************