[29451] in Perl-Users-Digest
Perl-Users Digest, Issue: 695 Volume: 11
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sat Jul 28 16:09:42 2007
Date: Sat, 28 Jul 2007 13:09:07 -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 Sat, 28 Jul 2007 Volume: 11 Number: 695
Today's topics:
Re: Assignments with $_ using substitution <RedGrittyBrick@SpamWeary.foo>
Re: ERR: 13: Missing right $] <pp@mm.org>
Re: ERR: 13: Missing right $] <noreply@gunnar.cc>
getting arguments <frytaz@gmail.com>
new CPAN modules on Sat Jul 28 2007 (Randal Schwartz)
Re: Objects/Structures in Perl <olson_ord@yahoo.it>
Re: Objects/Structures in Perl <olson_ord@yahoo.it>
query regarding perl module installation in local direc contactviswa@gmail.com
Re: Reading from stdin then launching a program that re <stefano.sabatini-lala@poste.it>
Re: Reading from stdin then launching a program that re <hjp-usenet2@hjp.at>
Re: Reading from stdin then launching a program that re <hjp-usenet2@hjp.at>
spell checking...capitalization of proper names <jbl02NO@SPAMgoogle.com>
Re: String::CRC crc function returns incorrect result, <joe@inwap.com>
Re: whether large hash might leak? <chemiestor@gmail.com>
Re: whether large hash might leak? <chemiestor@gmail.com>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Sat, 28 Jul 2007 15:32:38 +0100
From: RedGrittyBrick <RedGrittyBrick@SpamWeary.foo>
Subject: Re: Assignments with $_ using substitution
Message-Id: <zL6dnUEw8bn2zjbbRVnyjAA@bt.com>
TonyV wrote:
> Hi all,
>
> If I want to assign the result of a substitution in $_ to a variable,
> I can do something like this:
>
> foreach (@foo) {
> if (m/old text/) {
> ($a = $_) =~ s/old/new/; # Assign 'new text' to $a
> }
> # Do more stuff...
> }
>
> Of course, one of the nice things about using $_ is that it is the
> default variable used in operations such as matches and
> substitutions. I'd like to be able to do something like this instead:
>
> foreach (@foo) {
> if (m/old text/) {
> $a = s/old/new/; # This does not work
> }
> # Do more stuff...
> }
>
> What's happening is that the substitution is occurring in $_ and the
> number of substitutions (1, in this case) is being assigned to $a. Is
> there some more elegant way to assign the result of the substitution
> to $a without explicitly assigning $_ to it?
>
Did you want to do something like this?
#!perl
use strict;
use warnings;
my @foo = qw(oldnews oldhat bleh oldold);
foreach my $foo (@foo) {
$foo =~ s/old/new/;
print "$foo\n";
}
It is best to avoid $a as a variable name. I've used $foo instead.
------------------------------
Date: Sat, 28 Jul 2007 18:25:27 +1000
From: pp <pp@mm.org>
Subject: Re: ERR: 13: Missing right $]
Message-Id: <13alvbp1g9t2a81@corp.supernews.com>
Alan Curry wrote:
> In article <5mfja35hsbkv6646k9qce9vnks11nuroj8@4ax.com>,
> Michele Dondi <bik.mido@tiscalinet.it> wrote:
>> On Fri, 27 Jul 2007 19:18:09 +1000, pp <pp@mm.org> wrote:
>>
>>> Subject: ERR: 13: Missing right $]
>> How strange! Actually that doesn't look like a Perl error at all, if
>> it's intended to be verbatim.
>
> It appears to be the format of an error message from Embperl.
>
yeah, you are right, I have built in embperl in aparche.
Do you know how to solve this problem?
Thanks
Sam
>>> Can anyone tell me how to fix this error in perl?
>>> The above error point to the following line or perl code.
>> Sometimes errors are not reported to the *exact* they happen.
>>
>>> %UN_MONTH= map { lc($MONTH[$_]), $_ } 0..$#MONTH ; # look up by month
>> This line of Perl code is syntactically fine, and I can't even see how
>> could it fail at runtime.
>
> Embperl uses [$ and $] as a matching pair of delimiters. It must have seen
> the [$ and decided it wanted a $] then got upset when it didn't get one.
>
------------------------------
Date: Sat, 28 Jul 2007 12:00:15 +0200
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: ERR: 13: Missing right $]
Message-Id: <5h0ijsF3ihut9U1@mid.individual.net>
pp wrote:
> Alan Curry wrote:
>> In article <5mfja35hsbkv6646k9qce9vnks11nuroj8@4ax.com>,
>> Michele Dondi <bik.mido@tiscalinet.it> wrote:
>>> On Fri, 27 Jul 2007 19:18:09 +1000, pp <pp@mm.org> wrote:
>>>> Subject: ERR: 13: Missing right $]
>>> How strange! Actually that doesn't look like a Perl error at all, if
>>> it's intended to be verbatim.
>>
>> It appears to be the format of an error message from Embperl.
>
> yeah, you are right, I have built in embperl in aparche.
> Do you know how to solve this problem?
I know nothing about Embperl, but try adding a space:
lc($MONTH[ $_ ])
--------------^
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
------------------------------
Date: Sat, 28 Jul 2007 13:01:03 -0700
From: "frytaz@gmail.com" <frytaz@gmail.com>
Subject: getting arguments
Message-Id: <1185652863.987273.29910@o61g2000hsh.googlegroups.com>
Hi there
I want to run my per script with arguments, for instance:
./script.pl -one value one text 1 -two value two text 2 -three value
three text 3
and i want to get those arguments in
$one = value one text 1
$two = value two text 2
$three = value three text 3
i tried with regular expression m/-one (.+?) -two (.+?) -three (.+?)/
and it works but when i mix-up arguments like:
./script.pl -two value two text 2 -three value three text 3 -one value
one text 1
then i need to use different regex.
Someone know other solution ?
Thanks in advance
------------------------------
Date: Sat, 28 Jul 2007 04:42:15 GMT
From: merlyn@stonehenge.com (Randal Schwartz)
Subject: new CPAN modules on Sat Jul 28 2007
Message-Id: <JLvH2F.217x@zorch.sf-bay.org>
The following modules have recently been added to or updated in the
Comprehensive Perl Archive Network (CPAN). You can install them using the
instructions in the 'perlmodinstall' page included with your Perl
distribution.
Apache-SWIT-0.28
http://search.cpan.org/~bosu/Apache-SWIT-0.28/
mod_perl based application server with integrated testing.
----
Bio-Das-Lite-1.053
http://search.cpan.org/~rpettett/Bio-Das-Lite-1.053/
Perl extension for the DAS (HTTP+XML) Protocol (http://biodas.org/)
----
Bundle-Interchange-1.03
http://search.cpan.org/~mikeh/Bundle-Interchange-1.03/
A bundle of the modules nice to have for Interchange 5.
----
Bundle-InterchangeKitchenSink-1.04
http://search.cpan.org/~mikeh/Bundle-InterchangeKitchenSink-1.04/
A bundle of most all the modules nice to have for Interchange. A lot of stuff.
----
Config-Model-0.612
http://search.cpan.org/~ddumont/Config-Model-0.612/
Model to create configuration validation tool
----
DBIx-MoCo-0.14
http://search.cpan.org/~jkondo/DBIx-MoCo-0.14/
Light & Fast Model Component
----
Date-EzDate-1.09
http://search.cpan.org/~miko/Date-EzDate-1.09/
Date and time manipulation made easy
----
DateTime-Event-MultiCron-0.01.1
http://search.cpan.org/~neves/DateTime-Event-MultiCron-0.01.1/
Extension for DateTime::Event::Cron that allows multiple cron schedules for the same event.
----
HTML-Tested-0.25
http://search.cpan.org/~bosu/HTML-Tested-0.25/
Provides HTML widgets with the built-in means of testing.
----
IO-Zlib-1.07
http://search.cpan.org/~tomhughes/IO-Zlib-1.07/
IO:: style interface to Compress::Zlib
----
Linux-Input-1.03
http://search.cpan.org/~beppu/Linux-Input-1.03/
Linux input event interface
----
Net-XMPP2-0.05
http://search.cpan.org/~elmex/Net-XMPP2-0.05/
An implementation of the XMPP Protocol
----
OAI-Harvester-1.1
http://search.cpan.org/~esummers/OAI-Harvester-1.1/
----
OAI-Harvester-1.11
http://search.cpan.org/~esummers/OAI-Harvester-1.11/
----
OODoc-Template-0.11
http://search.cpan.org/~markov/OODoc-Template-0.11/
Simple template system
----
POE-Component-Client-Pastebot-0.04
http://search.cpan.org/~bingos/POE-Component-Client-Pastebot-0.04/
Interact with Bot::Pastebot web services from POE.
----
POE-Component-Client-Whois-1.10
http://search.cpan.org/~bingos/POE-Component-Client-Whois-1.10/
A one shot non-blocking RFC 812 WHOIS query.
----
POE-Filter-IRCD-2.31
http://search.cpan.org/~bingos/POE-Filter-IRCD-2.31/
A POE-based parser for the IRC protocol.
----
Params-Util-0.26
http://search.cpan.org/~adamk/Params-Util-0.26/
Simple, compact and correct param-checking functions
----
Perl-Critic-Lax-0.006
http://search.cpan.org/~rjbs/Perl-Critic-Lax-0.006/
policies that let you slide on common exceptions
----
Shell-Perl-0.0015
http://search.cpan.org/~ferreira/Shell-Perl-0.0015/
A read-eval-print loop in Perl
----
Slay-Makefile-0.04
http://search.cpan.org/~nodine/Slay-Makefile-0.04/
Wrapper to Slay::Maker that reads the rules from a file
----
TeX-Encode-0.10
http://search.cpan.org/~timbrody/TeX-Encode-0.10/
Encode/decode Perl utf-8 strings into TeX
----
Test-AskAnExpert-0.03
http://search.cpan.org/~trizor/Test-AskAnExpert-0.03/
Automatically test things that require Human Intelligence (by asking someone).
----
Test-BinaryData-0.004
http://search.cpan.org/~rjbs/Test-BinaryData-0.004/
compare two things, give hex dumps if they differ
----
Tk-Pod-0.9935
http://search.cpan.org/~srezic/Tk-Pod-0.9935/
Pod browser toplevel widget
----
URI-ParseSearchString-More-0.03
http://search.cpan.org/~oalders/URI-ParseSearchString-More-0.03/
Extract search strings from more referrers.
----
Variable-Magic-0.02
http://search.cpan.org/~vpit/Variable-Magic-0.02/
Associate user-defined magic to variables from Perl.
----
WWW-Scraper-ISBN-Amazon_Driver-0.10
http://search.cpan.org/~barbie/WWW-Scraper-ISBN-Amazon_Driver-0.10/
----
WebService-TRIPIT-Thesaurus-0.01
http://search.cpan.org/~zigorou/WebService-TRIPIT-Thesaurus-0.01/
The fantastic new WebService::TRIPIT::Thesaurus!
----
WebService-TRIPIT-Thesaurus-0.02
http://search.cpan.org/~zigorou/WebService-TRIPIT-Thesaurus-0.02/
Perl wrapper for Japanese thesaurus search on labs.tripit.jp.
----
Win32-Process-CommandLine-0.01
http://search.cpan.org/~kxj/Win32-Process-CommandLine-0.01/
Perl extension for getting win32 process command line parameters
----
XML-MyXML-0.09805
http://search.cpan.org/~karjala/XML-MyXML-0.09805/
A simple-to-use XML module, for parsing and creating XML documents
----
asterisk-perl-0.10
http://search.cpan.org/~jamesgol/asterisk-perl-0.10/
If you're an author of one of these modules, please submit a detailed
announcement to comp.lang.perl.announce, and we'll pass it along.
This message was generated by a Perl program described in my Linux
Magazine column, which can be found on-line (along with more than
200 other freely available past column articles) at
http://www.stonehenge.com/merlyn/LinuxMag/col82.html
print "Just another Perl hacker," # the original
--
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!
------------------------------
Date: Sat, 28 Jul 2007 09:54:06 -0700
From: "O. Olson" <olson_ord@yahoo.it>
Subject: Re: Objects/Structures in Perl
Message-Id: <1185641646.800620.217700@b79g2000hse.googlegroups.com>
Thanks Sinan.
I am not very familiar with Perl. I do not use it too often and when
I come back to it after some time I invariably forget a lot of stuff
that I had known before.
On Jul 27, 8:59 pm, "A. Sinan Unur" <1...@llenroc.ude.invalid> wrote:
>
> I fact, I would prefer not to put packages in the root namespace but
> instead adopt the following convention:
>
> package My::Time;
>
> To use this package, suppose your application is in
>
> C:\opt\mytime
>
> I would then put my custom package in c:\opt\mytime\lib\My\Time.pm
>
> That file would start with the package declaration:
>
> package My::Time;
>
Thanks for this suggestion. I am not yet a professional developer - so
I would simply go with 'MyTime.pm'.
> There two schools of thought on being able to call new on the class and
> the object. I subscribe to the camp that thinks this is unnecessary.
>
> sub new {
> my $class = shift;
>
I think I agree with you here - because that's how C++/Java do it. But
anyway that new concept by Perl is nice to know.
Thank you for your other comments. I think Jens post clarified my
other questions.
Regards,
O.O.
------------------------------
Date: Sat, 28 Jul 2007 10:02:06 -0700
From: "O. Olson" <olson_ord@yahoo.it>
Subject: Re: Objects/Structures in Perl
Message-Id: <1185642126.155581.269910@22g2000hsm.googlegroups.com>
Dear Jens,
Thank you for all of your detailed explanations. I think I have got
everything to work now.
On Jul 27, 9:03 pm, j...@toerring.de (Jens Thoms Toerring) wrote:
> It's not "my" clever way, it's copied staight from the Camel
> book, "Programming Perl";-)
>
I found this method described in perltoot - I don't know how I missed
this earlier.
> No, @time is just a simple array that is used locally to this
> function. There's nothing "magic" about it.
>
I overlooked the @time variable here. I don't know how this happened.
>
> That's what ties it all together. Up to this line $self was
> just a simple reference to an anonymous hash. But we want
> it to be a bit more, a real object, and that's what the
> bless function makes out of it - it makes $self an object
> of the class MyTime (and returns the new object which we
> then return to the caller. Only because of this you can
> use it later with all the object-oriented bells and wistles
> like calling
>
> my $string = $a->as_text;
>
> If you would leave out the call of bless you would get a
> error message like "Can't call method "new" on unblessed
> reference".
>
I am totally new to "bless" - this is the first time I would be using
it. Thanks for the explanation.
> > I would also like to know if every file in Perl should end with a 1; -
> > I did not know this before - but only learnt about it when you used
> > it.
>
> Yes, every package and module needs to end in '1;' (or something
> else that indicates success, so e.g. '"a";' would also do).
I did not know this. I would be using this from now on.
>
> Regards, Jens
I think I have some more questions regarding subroutines and OO
programming in Perl - but I think I would start a new thread for that
as it is a bit unrelated to my current thread.
vielen Danke,
O.O.
------------------------------
Date: Sat, 28 Jul 2007 13:08:10 -0700
From: contactviswa@gmail.com
Subject: query regarding perl module installation in local directory
Message-Id: <1185653290.135156.131390@i13g2000prf.googlegroups.com>
I am a beginner in perl. I have been trying to install perl modules
XML::RegExp in my local directory. I followed a lot of literature on
the web. I used the sequence given by all of them: 1. Download and
untar and unzip the module 2. cd to the directory /home/daitav/xml/
temp/XML-RegExp-0.03 3. perl Makefile.PL PREFIX=/home/daitav/xml/temp
With this I tried LIB=/home/daitav/xml/temp once and INSTALLDIRS=/temp
options at different time. 4. make 5. make test 6. make install. When
I executed the last command I am always getting an error that I am
unable to write to the the place where actual perl libraries are
sitting and this does not point to my local directory(I donot recall
the path but these were what I found to be present in the @INC
variable). I tried finding out installation directory after using
PREFIX=/home/daitav/xml/temp. I got an 'undefined' for the
installuserbindirs. If I use the INSTALLDIR cmd line option then I get
make error that pure_temp_install rule was not found by pure_install
which is called in Makemaker.pm. I am unable to figure out where I am
going wrong or what I doing incorrect? Could you please let me know
what is the mistake I have committed? I am in an urgent need to use
this. Looking forward to your early responses, Thanks, Viswa.
------------------------------
Date: Sat, 28 Jul 2007 08:48:08 +0200 (CEST)
From: Stefano Sabatini <stefano.sabatini-lala@poste.it>
Subject: Re: Reading from stdin then launching a program that reads from stdin strange behaviour
Message-Id: <slrnfalpc6.jcv.stefano.sabatini-lala@santefisi.caos.org>
On 2007-07-27, Klaus <klaus03@gmail.com> wrote:
> On Jul 27, 12:50 pm, Stefano Sabatini <stefano.sabatini-l...@poste.it>
> wrote:
>> I'm writing a perl script which reads from stdin, then launch an
>> interactive session of gnuplot.
>
>> open(FH, "/dev/stdin");
>> # filter stdin
>> while (<FH>) {
>> ;}
>>
>> close(FH);
>
> So far so good, but at this point, after closing FH, you should also
> close STDIN:
>
> close STDIN;
>
> Now, before launching an interactive application, you want to re-open
> STDIN:
>
> open STDIN, '<&1' or die "Error open STDIN: $!";
>
>> print "Launching gnuplot...\n";
>> # and now launch a gnuplot interactive session
>> system "gnuplot -";
Thank you guys, you saved my day!
Here it is the complete solution.
-----------------------------
while (<>) {
;
}
close (STDIN);
open STDIN, '<&1' or die "Error open STDIN: $!";
system("gnuplot", "-");
------------------------------
Cheers!
--
Stefano Sabatini
Linux user number 337176 (see http://counter.li.org)
------------------------------
Date: Sat, 28 Jul 2007 13:54:15 +0200
From: "Peter J. Holzer" <hjp-usenet2@hjp.at>
Subject: Re: Reading from stdin then launching a program that reads from stdin strange behaviour
Message-Id: <slrnfambj7.m15.hjp-usenet2@zeno.hjp.at>
On 2007-07-27 10:50, Stefano Sabatini <stefano.sabatini-lala@poste.it> wrote:
> I'm writing a perl script which reads from stdin, then launch an
> interactive session of gnuplot. I'm on a gnu-linux system, perl 5.8.
[...]
> If I feed the script with a file, like this:
> cat file.txt | perl gnuplot-launcher.pl
>
> gnuplot exits immediately from the interactive session.
>
> If I filter a regular file (like "file.txt") or type interactively on
> stdin like this:
> cat - | gnuplot-launcher.pl
> I'm writing
> interactively
> on
> stdin
> ^D
>
> then the gnuplot interactive mode seems to work.
I don't see how this can work. It's completely equivalent to the
previous example, as far as gnuplot-launcher.pl is concerned:
cat reads from stdin until it a read returns 0 bytes (this happens on
EOF on a file, or when the user types ^D on a terminal). It copies all
input to the pipe, then exits.
gnuplot-launcher.pl reads from the pipe until the write-end of the pipe
is closed (i.e. cat has exited). Then it launches "gnuplot -", which
will still try to read from a pipe with no writer, so it gets EOF
immediately and exits.
Now invoking gnuplot-launcher.pl with stdin from a terminal is a bit
different. In this case it will read until the user presses ^D, then
launch gnuplot, which will again run until the user presses ^D. This is
because a terminal doesn't really have an "end of file", it can only
return 0 bytes to a read which is interpreted as end of file by most
programs - and it can do that as often as necessary, of course.
> All I want to do is to be able to access to an interactive session of
> gnuplot from perl, but I'm evidently missing something.
open(STDIN, '<', '/dev/tty') or die "cannot open /dev/tty: $!";
should work if the process has a controlling tty (otherwise it gets
tricky: You could start gnuplot in an xterm if $DISPLAY is set).
hp
--
_ | Peter J. Holzer | I know I'd be respectful of a pirate
|_|_) | Sysadmin WSR | with an emu on his shoulder.
| | | hjp@hjp.at |
__/ | http://www.hjp.at/ | -- Sam in "Freefall"
------------------------------
Date: Sat, 28 Jul 2007 13:57:29 +0200
From: "Peter J. Holzer" <hjp-usenet2@hjp.at>
Subject: Re: Reading from stdin then launching a program that reads from stdin strange behaviour
Message-Id: <slrnfambp9.m15.hjp-usenet2@zeno.hjp.at>
On 2007-07-27 23:45, Klaus <klaus03@gmail.com> wrote:
> On Jul 27, 12:50 pm, Stefano Sabatini <stefano.sabatini-l...@poste.it>
> wrote:
>> I'm writing a perl script which reads from stdin, then launch an
>> interactive session of gnuplot.
>
> Now, before launching an interactive application, you want to re-open
> STDIN:
>
> open STDIN, '<&1' or die "Error open STDIN: $!";
You are duplicating STDIN from STDOUT here. It is not guaranteed that
STDOUT is readable. Consider:
./gnuplot-launcher < foo > bar
hp
--
_ | Peter J. Holzer | I know I'd be respectful of a pirate
|_|_) | Sysadmin WSR | with an emu on his shoulder.
| | | hjp@hjp.at |
__/ | http://www.hjp.at/ | -- Sam in "Freefall"
------------------------------
Date: Sat, 28 Jul 2007 06:54:48 -0500
From: JackL <jbl02NO@SPAMgoogle.com>
Subject: spell checking...capitalization of proper names
Message-Id: <7s8ma3h8lgojej50gc9560i4nr264l0c0h@4ax.com>
I am looking for an efficient way to check for capitalization of
proper names. I am currently using a perl script with quite a lot of
regexes and it works fine, but.... Rather than re-invent the wheel, I
thought there probably was something already out there, or maybe just
a better method of doing it. I do this each day and find that I am
adding 15-30 new words to the regex list each day.
Currently the script has 1500 regexes looking for individual words or
2-3 word phrases. (New York City, for example)
$data =~ s/[ ][Nn]ew([ ]*)(\[\d+:\d+:\d+][ ]*)*[Yy]ork([
]*)(\[\d+:\d+:\d+][ ]*)*[Cc]ity/ New$1$2York$3$4City/msg;
The text is actually a television newscast closed captioning script
that is formatted like the following lines. 70% local Kansas City, MO
news and 30% national US news.
<snip>
[17:16:32] Since the first gulf war --
[17:16:33] Cliff Standby has been
[17:16:35] receiving knee treatment at Walter
[17:16:36] Reed Army Medical
[17:16:38] Center. And within the last
<snip>
The goofy looking first regex below will look for 'walter reed' either
on 1 line or split across two lines. The remainder of them just simply
check for a certain word and capitilize them.
$data is the text of the entire file. The files average 500-800 lines
of text.
<snip>
$data =~ s/[ ][Ww]alter([ ]*)(\[\d+:\d+:\d+][ ]*)*[Rr]eed/
Walter$1$2Reed/msg;
$data =~ s/[ ]ward([ .!?:,;\'-])/ Ward$1/msg; $data =~ s/[ ]warner([
.!?:,;\'-])/ Warner$1/msg; $data =~ s/[ ]warren([ .!?:,;\'-])/
Warren$1/msg; <snip>
I have just begun to look at
http://search.cpan.org/~hank/Text-Aspell/Aspell.pm
It appears that it will just take a string, a word at a time and
check, then suggest, correct or incorrect. Maybe I am not grasping
it's capabilities.
I would appreciate any suggestions.
jbl
------------------------------
Date: Sat, 28 Jul 2007 13:01:05 -0700
From: Joe Smith <joe@inwap.com>
Subject: Re: String::CRC crc function returns incorrect result, why?
Message-Id: <z4WdncP-PLcLPTbbnZ2dnUVZ_hqdnZ2d@comcast.com>
`Zidane Tribal wrote:
> it would appear that using the command 'crc("data")' from the String::CRC
> returns incorrect results
No, it's not. crc != cksum; there are many different CRC algorithms.
> for example, this script.....
>
> #!/usr/bin/perl -w
> use strict;
> use String::CRC;
> print "crc: " . crc($ARGV[0]) . " " . length($ARGV[0]) . "\n";
>
> produces this output:
>
> zidane@bluemist:~/ps2/dev/crccheck$ ./crctest.pl 12345
> crc: 3817467633 5
> zidane@bluemist:~/ps2/dev/crccheck$
>
> whereas this command:
>
> zidane@bluemist:~/ps2/dev/crccheck$ echo -n "12345" | cksum
> 3288622155 5
> zidane@bluemist:~/ps2/dev/crccheck$
>
> produces a different crc value.
The String::CRC::Cksum module calculates a 32 bit CRC, generating
the same CRC value as the POSIX cksum program.
linux% cat cksum.pl
#!/usr/bin/perl -w
use strict;
use String::CRC::Cksum qw(cksum);
print "cksum: " . cksum($ARGV[0]) . " " . length($ARGV[0]) . "\n";
linux% perl cksum.pl 12345
cksum: 3288622155 5
-Joe
P.S. The newsgroup comp.lang.perl is defunct; use comp.lang.perl.misc instead.
------------------------------
Date: Fri, 27 Jul 2007 22:16:59 -0700
From: Kimia <chemiestor@gmail.com>
Subject: Re: whether large hash might leak?
Message-Id: <1185599819.859633.277890@x35g2000prf.googlegroups.com>
On 27 juil, 15:45, Mirco Wahab <wahab-m...@gmx.net> wrote:
> Kimia wrote:
> > ?????????????????????????????*2834
> > ------------------------
> > Where '?' is \0xff, when viewed as binary file.
> > I'm sure that the input contains no char as: \0xff. Most of lines
> > are tens of char long, few exceeds 100 and none exceeds 1000.
>
> This might depend on the properties of the input file,
> which encoding does it use, UTF8/16 or plain ASCII?
>
> What system do you working on, what Perl version is installed?
>
> Regards
>
> M.
the file is encoded with gb2312, which is ASCII-compatibe and that is
used in P.R. China.
------------------------------
Date: Fri, 27 Jul 2007 23:07:41 -0700
From: Kimia <chemiestor@gmail.com>
Subject: Re: whether large hash might leak?
Message-Id: <1185602861.398832.48990@x35g2000prf.googlegroups.com>
>On 28 juil, 03:12, xhos...@gmail.com wrote:
> Kimia <chemies...@gmail.com> wrote:
> > hi, girls and dudes,
>
> > ....I doubt whether hash might leak when it comprises of a large
> > amount of pairs.
> > Recently I have been asked to do some statitic work over large
> > files. All I wanted to do is to find the duplicated lines of a file
> > and I wrote the snippet as below:
> > code:
> > mysort.pl
> > ------------------------
> > #!/usr/bin/perl
>
> > use strict;
> > use warnings;
> > my %in;
> > my $cnt = 0;
> > while(<>){
> > chomp;
> > $_ or ++$cnt, next;
> > ++$in{$_};
> > }
> > foreach(sort keys %in){
> > $cnt += $in{$_};
> > print "$_*$in{$_}\n";
> > }
>
> What is the stuff with $cnt?
>
>
>
> > However, when I used it for a large file, which contains 10M lines, it
> > failed.
>
> It doesn't fail. I gives you output you didn't expect.
>
>
>
>
>
> > $ ./mysort <TenLinesInput.dat >out
> > $ echo $?
> > 0
> > $ tail out -n 5
> > ------------------------
> > ??????????????*2
> > ????????????????*1
> > ??????????????????*1
> > ?????????????????????????????*2834
> > ?????????????????????????????????????????????????????????????????????????
> > ?????????????????????????????????????????????????????????????????????????
> > ?????????????????????????????????????????????????????????????????????????
> > ????????????????????? *1
> > ------------------------
> > Where '?' is \0xff, when viewed as binary file.
> > I'm sure that the input contains no char as: \0xff.
>
> I am not sure of that. Try this and see what it gives, and if
> it consistently gives the same thing:
>
> perl -lne 'print $. unless -1==index $_, chr(0xff)' TenLinesInput.dat
>
> > Most of lines
> > are tens of char long, few exceeds 100 and none exceeds 1000.
> > The other output lines, except last 10, all are as expected.
>
> > Then I tried it for a input file conprised of one million lines
> > and it failed with the same error;
>
> It didn't fail with an error. The value of $? shows that. (And I don't
> see anything suggestive of a "leak", either.) It seems like what it comes
> down to is that you and Perl disagree over what is in your file.
>
> Xho
>
> --
> --------------------http://NewsReader.Com/--------------------
> Usenet Newsgroup Service $9.95/Month 30GB
thanks, xho. I've found the bug, which, of course, I've made.
The output file is perfectly correct. The input file does contains
lines
of ????.
Before debugging, I have tryed with:
$perl -lne 'print if /^\0xff/'
and the output was none. Then I assured myself with the assumption.
However, the regex should be : /^\xff/
It was part of the volumnious log-file processing that I was asked
to do.
\0xff should not exist in normal encoding and should be generated in
some
uncertain situation.
The code that I posted was written for debugging when I found
exceptions in
other processing. However, I did not succeed in it, and it was so
stupid~
Befor debugging would expel error, it does import stupidness:)
Thanks for all your help.
ps:
> perl -lne 'print $. unless -1==index $_, chr(0xff)' TenLinesInput.dat
I tried this lines and it does help me.
--
fous, c'est un mot qu'on dirait invent'e pour nous.
------------------------------
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 V11 Issue 695
**************************************