[21834] in Perl-Users-Digest
Perl-Users Digest, Issue: 4038 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Oct 28 14:05:56 2002
Date: Mon, 28 Oct 2002 11:05:14 -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, 28 Oct 2002 Volume: 10 Number: 4038
Today's topics:
Re: 8 byte key's for blowfish <nobull@mail.com>
Activestate Perl problem with multiple file opening (Jan Fure)
amateur socketeer: long wait (Leaffoot)
Re: amateur socketeer: long wait <uri@stemsystems.com>
Best way to traverse multilevel hash? <bill_knight2@yahoo.com>
Re: Best way to traverse multilevel hash? <nobull@mail.com>
Grep v Foreach <codmate@NOSPAMntlworld.com>
Re: Grep v Foreach (Helgi Briem)
Re: Grep v Foreach <codmate@NOSPAMntlworld.com>
Re: Grep v Foreach <kurzhalsflasche@netscape.net>
New posters to comp.lang.perl.misc <gbacon@cs.uah.edu>
Re: Overloading and recursion; how to turn '""' overloa <nobull@mail.com>
Re: Perl - Error Handling <nobull@mail.com>
Perl LDAP help, how to authenticate simple username and (Nozer Damania)
Remote Window with Win2K Server <steve_woolet@nospamus.ibm.com>
Re: RMI Equivalent in Perl? (Brian)
Re: Serial Port <pkent77tea@yahoo.com.tea>
Statistics for comp.lang.perl.misc <gbacon@cs.uah.edu>
Re: Strange Performance Thing <simon.andrews@bbsrc.ac.uk>
Re: Strange Performance Thing <nospam@nospam.org>
Re: system() and shell "metacharacters" <pkent77tea@yahoo.com.tea>
Re: system() and shell "metacharacters" <nobull@mail.com>
Working out if string A is related to string B (Richard Lawrence)
Re: Working out if string A is related to string B <nobull@mail.com>
Re: Working out if string A is related to string B <mike_constant@yahoo.com>
Re: Working out if string A is related to string B <mjcarman@mchsi.com>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 28 Oct 2002 18:57:35 +0000
From: Brian McCauley <nobull@mail.com>
Subject: Re: 8 byte key's for blowfish
Message-Id: <u9vg3mcrxc.fsf@wcl-l.bham.ac.uk>
chrisr@ilutra.com (chris rush) writes:
> has anyone got any suggestions of tools for generating random keys of
> a specific byte length.
Does you OS have /dev/random ?
There's a Perl module, Crypt::Random, to provide an elegant interface
to /dev/random.
--
\\ ( )
. _\\__[oo
.__/ \\ /\@
. l___\\
# ll l\\
###LL LL\\
------------------------------
Date: 28 Oct 2002 10:56:02 -0800
From: jan_may2002_fure@attbi.com (Jan Fure)
Subject: Activestate Perl problem with multiple file opening
Message-Id: <e47a84bf.0210281056.2a1698a9@posting.google.com>
Hi;
I have some code which works fine under unix (Sun Sparc) Perl, but
hangs under Win32.
I am asking for volunteers to run the attached code under ActiveState
Perl, and it would be great if somebody can explain what I am doing
wrong in the code which causes the hang.
The code generates 3 text files, and then opens them. In UNIX,
everything works fine, under windows, the first file opens fine,
whereas the second one takes forever.
I have included a more compact code set than my own script which
reproduces the problem, please forgive me if there is a more elegant
demonstration of the problem, as I am very much a Perl newbie.
My OS is WinNT4.0/sp6. Strictly speaking, the code does not hang, but
the long time it takes to open the file increases the execution time
hundredfold.
Jan Fure, code is attached below:
#!/usr/local/bin/perl
use strict;
use warnings;
my $file_number=0;
while ($file_number<3){
my @data_array;
my $line_number=0;
my $R=0;
$file_number++;
while ($line_number<100000){
$line_number++;
$R=rand;
push @data_array, "$line_number \t Second_column \t Third_column \t
$R \n";
}
open WORKFILE, ">$file_number.txt";
print WORKFILE @data_array;
close WORKFILE;
}
opendir(DIR, ".") or die "Can't open directory $!";
my @textfiles = sort(grep(/.txt/, readdir(DIR))); #find files/dirs
containing ".txt"
closedir(DIR);
foreach my $file (@textfiles) {
my ( $name ) = $file =~ /^(.+)\.txt$/;
print "The input file is $file\n";
print "Program hangs on the opening of second file under
winnt4sp6/active Perl\n";
open INPUT_FILE, "$file" or die "can't open $file";
my ($heading, @array) = <INPUT_FILE>;
close INPUT_FILE;
print "Heading is $heading!\n";
open (CURRENT,">$name.tx");
print CURRENT @array;
close CURRENT;
}
------------------------------
Date: 28 Oct 2002 08:48:57 -0800
From: leaffoot@hotmail.com (Leaffoot)
Subject: amateur socketeer: long wait
Message-Id: <d7bd06a3.0210280848.120fa135@posting.google.com>
Hi,
I am doing some socket-to-socket communication using io::socket, and
this is my first time doing so, so bear with me. Sometimes the
handshake and data transmittal occurs in less than a couple seconds,
and sometimes it takes 10 minutes, for the same amount of data. I
have a "last" statement that should kick me out if it's taking too
long, but even so, it hangs for a very lengthy time before continuing.
Does anyone know how I can get around this problem, or what is going
on?? Here's the subs I use:
sub sendstr {
# pass in socket and string to send
my @args = @_;
my $sock = shift @args;
my $str = shift @args;
print $sock "$str" || confess "I can't send the str $str!\n";
return 1;
}
sub recstr {
# pass in socket and length of line, returns str & flag if closed sock
my @args = @_;
my $sock = shift @args;
my $len = shift @args;
my $stuff = "";
my $comeback_l = 0;
my $length_l = 0;
my $out = 0;
my $flag = 0;
my $time_start = new Benchmark;
while($length_l = sysread $sock, $comeback_l, $len) {
if(!defined $length_l) {
confess "System read error: $!\n";
}
while($length_l) {
#writes entire line, then length is cleared, next loop of
read occurs
my $written = syswrite STDOUT, $comeback_l,$length_l;
$stuff = $stuff.$comeback_l;
die "System error: $!\n" unless defined $written;
#makes sure entire line was written entirely
$length_l -= $written;
}
if ($comeback_l =~ m/END OF REPORT/) {
last;
}
if ($comeback_l =~ m/^\d+CERRUR\d+.*/) {
last;
}
my $time_end = new Benchmark;
my $this_time = timediff($time_end, $time_start);
my $timestr = timestr($this_time);
print "Time taken to send & retrieve: ", timestr($this_time),
"\n";
if($timestr =~ m/\b(\d+) wallclock secs/) {
if($1 > 50) {
close($sock);
$flag = 1;
last;
}
}
}
return $stuff,$flag;
}
Then after connecting, I call:
&sendstr($socket, $dialstr) || die "Can't send for $ur";
my ($report,$flag) = &recstr($socket, $linesize);
if($flag) {$socket = &connect_to_socket($logfile);}
And it hangs on after the last data is transferred, as if still trying
to read. Can anyone help? Thanks!!
Becka Louden
------------------------------
Date: Mon, 28 Oct 2002 17:05:41 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: amateur socketeer: long wait
Message-Id: <x7iszmwl26.fsf@mail.sysarch.com>
>>>>> "L" == Leaffoot <leaffoot@hotmail.com> writes:
just some coding comments.
L> sub sendstr {
L> # pass in socket and string to send
L> my @args = @_;
L> my $sock = shift @args;
L> my $str = shift @args;
where did you get that style of arg handling? why do you use the temp
var @args? either just shift @_ directly or do the more common:
my( $sock, $str ) = @_ ;
L> while($length_l = sysread $sock, $comeback_l, $len) {
L> if(!defined $length_l) {
unless is more readable than if( ! )
L> if ($comeback_l =~ m/END OF REPORT/) {
L> last;
L> }
L> if ($comeback_l =~ m/^\d+CERRUR\d+.*/) {
L> last;
L> }
last if $comeback_l =~ m/^\d+CERRUR\d+.*/ ;
L> my $time_end = new Benchmark;
my $time_end = Benchmark->new ;
uri
--
Uri Guttman ------ uri@stemsystems.com -------- http://www.stemsystems.com
----- Stem and Perl Development, Systems Architecture, Design and Coding ----
Search or Offer Perl Jobs ---------------------------- http://jobs.perl.org
------------------------------
Date: Mon, 28 Oct 2002 16:29:12 +0000 (UTC)
From: bill <bill_knight2@yahoo.com>
Subject: Best way to traverse multilevel hash?
Message-Id: <apjoko$9u4$1@reader1.panix.com>
Is there a better (or at least more elegant) way to traverse a
multilevel hash than something like
for my $v_1 (values %h) {
for my $v_2 (values %$v_1) {
for my $v_3 (values %$v_2) {
.
.
.
while (my ($k, $v) = each %$v_n) {
# etc.
}
.
.
.
}
}
}
?
TIA,
bill
------------------------------
Date: 28 Oct 2002 17:57:35 +0000
From: Brian McCauley <nobull@mail.com>
Subject: Re: Best way to traverse multilevel hash?
Message-Id: <u9lm4ie99s.fsf@wcl-l.bham.ac.uk>
bill <bill_knight2@yahoo.com> writes:
> Is there a better (or at least more elegant) way to traverse a
> multilevel hash than something like
>
> for my $v_1 (values %h) {
> for my $v_2 (values %$v_1) {
> for my $v_3 (values %$v_2) {
> .
> .
> .
> while (my ($k, $v) = each %$v_n) {
> # etc.
> }
> .
> .
> .
> }
> }
> }
There is no more elegant verion in the general case where you want to
do something different at each level of traversal.
If you really want just to traverse all levels you can use a recusive
subroutine.
--
\\ ( )
. _\\__[oo
.__/ \\ /\@
. l___\\
# ll l\\
###LL LL\\
------------------------------
Date: Mon, 28 Oct 2002 16:38:58 +0000
From: Codmate <codmate@NOSPAMntlworld.com>
Subject: Grep v Foreach
Message-Id: <apjotk$r4d$1@nntp0.reith.bbc.co.uk>
Hi all - this is my first posting to a Perl newsgroup so please be kind ;)
It's a simple question really...
I was just wondering which is faster - a grep such as:
grep {$_ ne $entry} @list
or an equivalent foreach loop searching for a value in a list.
Cheers!
------------------------------
Date: Mon, 28 Oct 2002 17:04:35 GMT
From: helgi@decode.is (Helgi Briem)
Subject: Re: Grep v Foreach
Message-Id: <3dbd6da0.1086676968@news.cis.dfn.de>
On Mon, 28 Oct 2002 16:38:58 +0000, Codmate
<codmate@NOSPAMntlworld.com> wrote:
>Hi all - this is my first posting to a Perl newsgroup so please be kind ;)
>
>It's a simple question really...
>
>I was just wondering which is faster - a grep such as:
>grep {$_ ne $entry} @list
>
>or an equivalent foreach loop searching for a value in a list.
>
Grep is faster, but if you think that matters to
you, you are probably on the wrong track.
Don't optimise prematurely.
#!perl
use strict;
use warnings;
use Benchmark;
my $array = qw/one two three four five six seven eight nine
ten/;
my $find_this = 'four';
my $count = 1000000;
timethese($count,
{
'foreach' => sub { foreach(@array) {print if
/$find_this/};},
'grep' => sub { print grep /$find_this/,@array;}
}
);
__END__
Benchmark: timing 1000000 iterations of foreach, grep...
foreach: 1 wallclock secs ( 1.03 usr + 0.00 sys = 1.03
CPU) @ 969932.10/s (n=1000000)
grep: 0 wallclock secs ( 0.45 usr + 0.00 sys = 0.45
CPU) @ 2217294.90/s (n=1000000)
--
Regards, Helgi Briem
helgi AT decode DOT is
A: Top posting
Q: What is the most irritating thing on Usenet?
- "Gordon" on apihna
------------------------------
Date: Mon, 28 Oct 2002 17:15:24 +0000
From: Codmate <codmate@NOSPAMntlworld.com>
Subject: Re: Grep v Foreach
Message-Id: <apjr1t$rqv$1@nntp0.reith.bbc.co.uk>
Helgi Briem wrote:
> On Mon, 28 Oct 2002 16:38:58 +0000, Codmate
> <codmate@NOSPAMntlworld.com> wrote:
>
>
>>Hi all - this is my first posting to a Perl newsgroup so please be kind ;)
>>
>>It's a simple question really...
>>
>>I was just wondering which is faster - a grep such as:
>>grep {$_ ne $entry} @list
>>
>>or an equivalent foreach loop searching for a value in a list.
>>
>
> Grep is faster, but if you think that matters to
> you, you are probably on the wrong track.
>
> Don't optimise prematurely.
>
> #!perl
> use strict;
> use warnings;
>
> use Benchmark;
> my $array = qw/one two three four five six seven eight nine
> ten/;
> my $find_this = 'four';
> my $count = 1000000;
>
> timethese($count,
> {
> 'foreach' => sub { foreach(@array) {print if
> /$find_this/};},
> 'grep' => sub { print grep /$find_this/,@array;}
> }
> );
> __END__
>
> Benchmark: timing 1000000 iterations of foreach, grep...
> foreach: 1 wallclock secs ( 1.03 usr + 0.00 sys = 1.03
>
> CPU) @ 969932.10/s (n=1000000)
> grep: 0 wallclock secs ( 0.45 usr + 0.00 sys = 0.45
>
> CPU) @ 2217294.90/s (n=1000000)
>
>
That's what I was looking for - thanks very much :)
------------------------------
Date: Mon, 28 Oct 2002 19:57:29 +0100
From: Dominik Seelow <kurzhalsflasche@netscape.net>
Subject: Re: Grep v Foreach
Message-Id: <3DBD8899.5080104@netscape.net>
Codmate wrote:
> Helgi Briem wrote:
>
>>On Mon, 28 Oct 2002 16:38:58 +0000, Codmate
>><codmate@NOSPAMntlworld.com> wrote:
>>
>>
>>
>>>Hi all - this is my first posting to a Perl newsgroup so please be kind ;)
>>>
>>>It's a simple question really...
>>>
>>>I was just wondering which is faster - a grep such as:
>>>grep {$_ ne $entry} @list
>>>
>>>or an equivalent foreach loop searching for a value in a list.
>>>
>>
>>Grep is faster, but if you think that matters to
>>you, you are probably on the wrong track.
>>
>>Don't optimise prematurely.
>>
>>#!perl
>>use strict;
>>use warnings;
>>
>>use Benchmark;
>>my $array = qw/one two three four five six seven eight nine
>>ten/;
>>my $find_this = 'four';
>>my $count = 1000000;
>>
>>timethese($count,
>>{
>> 'foreach' => sub { foreach(@array) {print if
>>/$find_this/};},
>> 'grep' => sub { print grep /$find_this/,@array;}
>>}
>>);
>>__END__
>>
>>Benchmark: timing 1000000 iterations of foreach, grep...
>> foreach: 1 wallclock secs ( 1.03 usr + 0.00 sys = 1.03
>>
>>CPU) @ 969932.10/s (n=1000000)
>> grep: 0 wallclock secs ( 0.45 usr + 0.00 sys = 0.45
>>
>>CPU) @ 2217294.90/s (n=1000000)
>>
>>
>
>
> That's what I was looking for - thanks very much :)
>
If you don't plan to do any pattern matching, using a hash instead of an
array search would be *really* fast:
my %HASH;
@HASH{@array}=();
do something if (exists $HASH{$find_this});
HTH,
Dominik
------------------------------
Date: Mon, 28 Oct 2002 16:02:55 -0000
From: Greg Bacon <gbacon@cs.uah.edu>
Subject: New posters to comp.lang.perl.misc
Message-Id: <urqntfhi7ndp60@corp.supernews.com>
Following is a summary of articles from new posters spanning a 7 day
period, beginning at 21 Oct 2002 16:02:27 GMT and ending at
28 Oct 2002 13:18:24 GMT.
Notes
=====
- A line in the body of a post is considered to be original if it
does *not* match the regular expression /^\s{0,3}(?:>|:|\S+>|\+\+)/.
- All text after the last cut line (/^-- $/) in the body is
considered to be the author's signature.
- The scanner prefers the Reply-To: header over the From: header
in determining the "real" email address and name.
- Original Content Rating (OCR) is the ratio of the original content
volume to the total body volume.
- Find the News-Scan distribution on the CPAN!
<URL:http://www.perl.com/CPAN/modules/by-module/News/>
- Please send all comments to Greg Bacon <gbacon@cs.uah.edu>.
- Copyright (c) 2002 Greg Bacon.
Verbatim copying and redistribution is permitted without royalty;
alteration is not permitted. Redistribution and/or use for any
commercial purpose is prohibited.
Totals
======
Posters: 76 (31.7% of all posters)
Articles: 121 (18.4% of all articles)
Volume generated: 221.7 kb (17.6% of total volume)
- headers: 95.3 kb (1,967 lines)
- bodies: 124.5 kb (4,258 lines)
- original: 97.3 kb (3,393 lines)
- signatures: 1.7 kb (41 lines)
Original Content Rating: 0.781
Averages
========
Posts per poster: 1.6
median: 1.0 post
mode: 1 post - 50 posters
s: 1.6 posts
Message size: 1876.2 bytes
- header: 806.7 bytes (16.3 lines)
- body: 1054.0 bytes (35.2 lines)
- original: 823.6 bytes (28.0 lines)
- signature: 14.5 bytes (0.3 lines)
Top 10 Posters by Number of Posts
=================================
(kb) (kb) (kb) (kb)
Posts Volume ( hdr/ body/ orig) Address
----- -------------------------- -------
9 16.3 ( 10.1/ 5.0/ 3.8) pasdespam_desmond@zeouane.org
6 15.1 ( 5.7/ 9.4/ 3.1) "john bennett" <johngnub@worldnet.att.net>
4 9.5 ( 3.5/ 6.0/ 1.6) Gary Hodges <gbhDELETE@fpcc.net>
4 9.8 ( 3.4/ 6.5/ 5.4) Marek Stepanek <mstep@t-online.de>
3 2.9 ( 2.2/ 0.8/ 0.7) "TBN" <ihave@noemail.com>
3 7.2 ( 2.9/ 4.3/ 1.7) "spicano" <spicano@netzero.net>
3 4.1 ( 2.5/ 1.7/ 1.4) Steve <THISISAFAKE@ADDRESS.000>
3 4.0 ( 2.2/ 1.8/ 1.1) Tipu <jandirb@hotmail.com>
2 2.2 ( 1.4/ 0.9/ 0.7) Andrew Gatt <sailordwarf@hotmail.com>
2 2.1 ( 1.6/ 0.4/ 0.4) "Colin Chaplin" <Colin@Chaplin.me.uk>
These posters accounted for 5.9% of all articles.
Top 10 Posters by Volume
========================
(kb) (kb) (kb) (kb)
Volume ( hdr/ body/ orig) Posts Address
-------------------------- ----- -------
16.3 ( 10.1/ 5.0/ 3.8) 9 pasdespam_desmond@zeouane.org
15.1 ( 5.7/ 9.4/ 3.1) 6 "john bennett" <johngnub@worldnet.att.net>
9.8 ( 3.4/ 6.5/ 5.4) 4 Marek Stepanek <mstep@t-online.de>
9.5 ( 3.5/ 6.0/ 1.6) 4 Gary Hodges <gbhDELETE@fpcc.net>
9.0 ( 0.7/ 8.3/ 8.3) 1 Phillip Montgomery <phillip.montgomery@motorola.com>
7.2 ( 2.9/ 4.3/ 1.7) 3 "spicano" <spicano@netzero.net>
6.7 ( 0.8/ 5.9/ 5.7) 1 Stephen Choularton <stephenc@ics.mq.edu.au>
5.9 ( 1.4/ 4.5/ 4.1) 2 J. Romano <jl_post@hotmail.com>
4.5 ( 0.8/ 3.7/ 3.7) 1 Rahul <rshringa@austin.ibm.com>
4.5 ( 1.8/ 2.7/ 2.5) 2 "reggie" <reggie_nospam@reggieband.com>
These posters accounted for 7.0% of the total volume.
Top 10 Posters by OCR (minimum of three posts)
==============================================
(kb) (kb)
OCR orig / body Posts Address
----- -------------- ----- -------
0.850 ( 0.7 / 0.8) 3 "TBN" <ihave@noemail.com>
0.830 ( 5.4 / 6.5) 4 Marek Stepanek <mstep@t-online.de>
0.823 ( 1.4 / 1.7) 3 Steve <THISISAFAKE@ADDRESS.000>
0.769 ( 3.8 / 5.0) 9 pasdespam_desmond@zeouane.org
0.607 ( 1.1 / 1.8) 3 Tipu <jandirb@hotmail.com>
0.407 ( 1.7 / 4.3) 3 "spicano" <spicano@netzero.net>
0.327 ( 3.1 / 9.4) 6 "john bennett" <johngnub@worldnet.att.net>
0.263 ( 1.6 / 6.0) 4 Gary Hodges <gbhDELETE@fpcc.net>
Bottom 10 Posters by OCR (minimum of three posts)
=================================================
(kb) (kb)
OCR orig / body Posts Address
----- -------------- ----- -------
0.850 ( 0.7 / 0.8) 3 "TBN" <ihave@noemail.com>
0.830 ( 5.4 / 6.5) 4 Marek Stepanek <mstep@t-online.de>
0.823 ( 1.4 / 1.7) 3 Steve <THISISAFAKE@ADDRESS.000>
0.769 ( 3.8 / 5.0) 9 pasdespam_desmond@zeouane.org
0.607 ( 1.1 / 1.8) 3 Tipu <jandirb@hotmail.com>
0.407 ( 1.7 / 4.3) 3 "spicano" <spicano@netzero.net>
0.327 ( 3.1 / 9.4) 6 "john bennett" <johngnub@worldnet.att.net>
0.263 ( 1.6 / 6.0) 4 Gary Hodges <gbhDELETE@fpcc.net>
8 posters (10%) had at least three posts.
Top 10 Targets for Crossposts
=============================
Articles Newsgroup
-------- ---------
6 de.comp.lang.perl.misc
3 alt.perl
2 comp.os.linux.misc
2 comp.lang.perl
2 fr.comp.lang.perl
1 microsoft.public.win2000.cmdprompt.admin
1 microsoft.public.inetserver.iis
1 alt.msdos.batch.nt
1 comp.lang.perl.modules
Top 10 Crossposters
===================
Articles Address
-------- -------
3 "Neil MacMurchy" <neilmcse@hotmail.com>
2 "Chris" <christian.le-corre@esf.ericsson.se>
2 tony@realh.co.uk
2 "Hisham Mohamed" <hisham.mohamed@no-spam.engelhard.com.noSPAM>
1 Codmate <codmate@NOSPAMntlworld.com>
1 Marc Pelletier <marcjgpelletier@hotmail.com>
0 "supernews" <arthur@excalibur-internet.net>
0 oracle@sympac.com.au
0 "TBN" <ihave@noemail.com>
0 David Keeney <dkeeney@travelbyroad.net>
------------------------------
Date: 28 Oct 2002 17:44:37 +0000
From: Brian McCauley <nobull@mail.com>
Subject: Re: Overloading and recursion; how to turn '""' overloading off?
Message-Id: <u9u1j6e9ve.fsf@wcl-l.bham.ac.uk>
Da Witch <heather710101@yahoo.com> writes:
> In <u9d6pu4v1s.fsf@wcl-l.bham.ac.uk> Brian McCauley <nobull@mail.com> writes:
>
> >Da Witch <heather710101@yahoo.com> writes:
>
> >> In <3DB9B6B7.41801E4A@earthlink.net> Benjamin Goldberg <goldbb2@earthlink.net> writes:
> >> >use vars ($stringify_recursion);
> >> >sub stringify {
> >> > return $_[0] if $stringify_recursion;
> >> > local $stringify_recursion = 1;
> >> > "Just call me $_[0]";
> >> >}
> >>
> >> Cool!
>
> >Huh?
>
> >Benjamin's untested code doesn't help at all there's still an infinite recusrion.
>
> I tested it (fixing the typo in the "use vars" line) before posting my
> reply, and it worked as advertised.
D'oh! I really should check before concluding that just because
Benjamin's code looks like it shouldn't work it won't! This isn't the
first time I've done this. Gee I must be thick.
Last time I made this mistake Benjamin's code was exploiting a bug
(which was fixed in a later release).
On this occasion Benjamin's code was exploiting something which I'd be
inclined to call a bug but it is less likely to change in a later
release because it is documented as a special case.
As a special case if the overload returns the object itself then it will
be used directly. An overloaded conversion returning the object is
probably a bug, because you're likely to get something that looks like
C<YourPackage=HASH(0x8172b34)>.
I think this is a "bad thing". It would be much better for it to
throw an error (or at least a warning) since as it says using this
feature is probably a bug.
Anyhow whether or not Benjamin's code works I still think doing it
"the right way" is neater:
sub stringify {
"Just call me " . overload::StrVal($_[0]);
}
--
\\ ( )
. _\\__[oo
.__/ \\ /\@
. l___\\
# ll l\\
###LL LL\\
------------------------------
Date: 28 Oct 2002 17:49:44 +0000
From: Brian McCauley <nobull@mail.com>
Subject: Re: Perl - Error Handling
Message-Id: <u9pttue9mv.fsf@wcl-l.bham.ac.uk>
Srikanth <member@mainframeforum.com> writes:
> wrote:
> > Can't find label ProcessCitationEnd at NewRef.pm line 1816, <INFILE>
> > line 2496.
I do not understand the significance of that quote.
> I've a collection of sub routines for manipulating string. At some time,
> an error occurs(for eg., "Unmatched (") and the program aborts. I just
> want to trap an error, and when it catches, it should do anyone of the
> following whichever is practically possible:
>
> 1. If an error occurs, the program should automatically end the current
> subroutine, and should process the remaining lines.
>
> 2. If an error occurs, the program should goto a particular label, which
> may be present in another sub routine.
Error trapping in Perl is best done using eval{}, die() and the $@
variable.
This is similar to catch/throw is some other languages.
Avoid using $SIG{__DIE__} unless you absolutely need to.
--
\\ ( )
. _\\__[oo
.__/ \\ /\@
. l___\\
# ll l\\
###LL LL\\
------------------------------
Date: 28 Oct 2002 08:13:02 -0800
From: ndamania@cyberfuse.com (Nozer Damania)
Subject: Perl LDAP help, how to authenticate simple username and password in LDAP
Message-Id: <dd37cdb4.0210280813.c71bcfc@posting.google.com>
Hi,
I have a simple LDAP structure, i am trying to authenticate usernames
and passwords against LDAP.
Unfortunately the passwords in LDAP are crypted. I use Mozilla::LDAP
package., so how do i check a valid combination of usernames and
passwords??
I tried the search string with
"(uid=$username,userPassword=$password)", i tried crypting it adding
{crypt} b4 the passwords, NOTHING works
Please help.
Thanks,
Nozer Damania
nozer@drexel.edu
------------------------------
Date: Mon, 28 Oct 2002 11:16:42 -0500
From: "Steven P. Woolet" <steve_woolet@nospamus.ibm.com>
Subject: Remote Window with Win2K Server
Message-Id: <3DBD62EA.C75010FA@nospamus.ibm.com>
When I use Perl with WMI API's to start a remote process (cmd /k that
runs a perl program) on Win2K Professional, I get a window that opens on
the remote machine and the perl program runs, as expected. When I try
the exact same code to start the process on Win2K Advanced Server, I do
not get the window...and the perl program doesn't run, although the CMD
process itself IS started.
Anyone know if there's something special that must be done to get a
remote window on Advanced Server? ..or is there perhaps a "fix" that
needs to be removed from the Advanced Server machine? It is at SP3.
Is there some way other than WMI calls to get a perl program to run on a
remote machine?
Thanks.
Steve
------------------------------
Date: 28 Oct 2002 08:34:01 -0800
From: lucid1@mediaone.net (Brian)
Subject: Re: RMI Equivalent in Perl?
Message-Id: <961d6f35.0210280834.4baba0c0@posting.google.com>
Derek, thanks a lot for your sample!!
Derek Thomson <derek@wedgetail.com> wrote in message news:<3db9473f$0$12759$afc38c87@news.optusnet.com.au>...
------------------------------
Date: Mon, 28 Oct 2002 17:28:05 GMT
From: pkent <pkent77tea@yahoo.com.tea>
Subject: Re: Serial Port
Message-Id: <pkent77tea-FA9971.17280328102002@news-text.blueyonder.co.uk>
In article <api58k$ali$1@perki.connect.com.au>,
oracle <oracle@sympac.com.au> wrote:
> Am planning a program to talk to a weather station via the serial port on an
> intel box and cannot find out how to talk to the serial port.
Just open the appropriate /dev/ttyS* device file, assuming you have
appropriate permissions, etc. All the 80x86 Unices support this in my
experience. You may need to do some kind of OS-specific 'set serial port
speed and parity etc' command, or look on CPAN for modules under the
keyword 'serial' for higher level interfaces.
P
--
pkent 77 at yahoo dot, er... what's the last bit, oh yes, com
Remove the tea to reply
------------------------------
Date: Mon, 28 Oct 2002 16:02:53 -0000
From: Greg Bacon <gbacon@cs.uah.edu>
Subject: Statistics for comp.lang.perl.misc
Message-Id: <urqntd1rc6oa5f@corp.supernews.com>
Following is a summary of articles spanning a 7 day period,
beginning at 21 Oct 2002 16:02:27 GMT and ending at
28 Oct 2002 13:18:24 GMT.
Notes
=====
- A line in the body of a post is considered to be original if it
does *not* match the regular expression /^\s{0,3}(?:>|:|\S+>|\+\+)/.
- All text after the last cut line (/^-- $/) in the body is
considered to be the author's signature.
- The scanner prefers the Reply-To: header over the From: header
in determining the "real" email address and name.
- Original Content Rating (OCR) is the ratio of the original content
volume to the total body volume.
- Find the News-Scan distribution on the CPAN!
<URL:http://www.perl.com/CPAN/modules/by-module/News/>
- Please send all comments to Greg Bacon <gbacon@cs.uah.edu>.
- Copyright (c) 2002 Greg Bacon.
Verbatim copying and redistribution is permitted without royalty;
alteration is not permitted. Redistribution and/or use for any
commercial purpose is prohibited.
Excluded Posters
================
perlfaq-suggestions\@(?:.*\.)?perl\.com
faq\@(?:.*\.)?denver\.pm\.org
comdog\@panix\.com
Totals
======
Posters: 240
Articles: 657 (264 with cutlined signatures)
Threads: 177
Volume generated: 1259.9 kb
- headers: 544.0 kb (10,598 lines)
- bodies: 681.5 kb (22,740 lines)
- original: 415.3 kb (15,003 lines)
- signatures: 33.8 kb (876 lines)
Original Content Rating: 0.609
Averages
========
Posts per poster: 2.7
median: 1.0 post
mode: 1 post - 127 posters
s: 4.3 posts
Posts per thread: 3.7
median: 3 posts
mode: 2 posts - 44 threads
s: 4.1 posts
Message size: 1963.7 bytes
- header: 847.9 bytes (16.1 lines)
- body: 1062.1 bytes (34.6 lines)
- original: 647.3 bytes (22.8 lines)
- signature: 52.7 bytes (1.3 lines)
Top 10 Posters by Number of Posts
=================================
(kb) (kb) (kb) (kb)
Posts Volume ( hdr/ body/ orig) Address
----- -------------------------- -------
36 82.7 ( 29.0/ 49.9/ 22.5) Benjamin Goldberg <goldbb2@earthlink.net>
26 47.0 ( 22.0/ 23.1/ 14.0) Brian McCauley <nobull@mail.com>
21 54.6 ( 23.2/ 28.6/ 24.0) tadmc@augustmail.com
20 29.5 ( 17.6/ 11.8/ 6.0) "Jürgen Exner" <jurgenex@hotmail.com>
17 42.5 ( 15.6/ 23.5/ 13.6) tassilo.parseval@post.rwth-aachen.de
15 28.8 ( 10.6/ 14.9/ 7.7) helgi@decode.is
14 23.0 ( 12.8/ 10.1/ 6.6) Bart Lateur <bart.lateur@pandora.be>
11 20.1 ( 9.4/ 7.5/ 3.8) Jeff 'japhy' Pinyan <pinyaj@rpi.edu>
11 15.2 ( 7.6/ 7.5/ 5.9) Da Witch <heather710101@yahoo.com>
10 21.9 ( 8.2/ 13.4/ 4.0) "John W. Krahn" <krahnj@acm.org>
These posters accounted for 27.5% of all articles.
Top 10 Posters by Volume
========================
(kb) (kb) (kb) (kb)
Volume ( hdr/ body/ orig) Posts Address
-------------------------- ----- -------
82.7 ( 29.0/ 49.9/ 22.5) 36 Benjamin Goldberg <goldbb2@earthlink.net>
54.6 ( 23.2/ 28.6/ 24.0) 21 tadmc@augustmail.com
47.0 ( 22.0/ 23.1/ 14.0) 26 Brian McCauley <nobull@mail.com>
42.5 ( 15.6/ 23.5/ 13.6) 17 tassilo.parseval@post.rwth-aachen.de
29.5 ( 17.6/ 11.8/ 6.0) 20 "Jürgen Exner" <jurgenex@hotmail.com>
28.8 ( 10.6/ 14.9/ 7.7) 15 helgi@decode.is
23.6 ( 6.6/ 15.3/ 9.7) 8 Michele Dondi <bik.mido@tiscalinet.it>
23.0 ( 12.8/ 10.1/ 6.6) 14 Bart Lateur <bart.lateur@pandora.be>
21.9 ( 8.2/ 13.4/ 4.0) 10 "John W. Krahn" <krahnj@acm.org>
21.8 ( 8.0/ 12.4/ 6.6) 8 Jason Baugher <jason@baugher.pike.il.us>
These posters accounted for 29.8% of the total volume.
Top 10 Posters by OCR (minimum of five posts)
==============================================
(kb) (kb)
OCR orig / body Posts Address
----- -------------- ----- -------
0.839 ( 3.8 / 4.6) 5 "Richard S Beckett" <spikey-wan@bigfoot.com>
0.838 ( 24.0 / 28.6) 21 tadmc@augustmail.com
0.783 ( 5.9 / 7.5) 11 Da Witch <heather710101@yahoo.com>
0.769 ( 3.8 / 5.0) 9 pasdespam_desmond@zeouane.org
0.650 ( 6.6 / 10.1) 14 Bart Lateur <bart.lateur@pandora.be>
0.634 ( 9.7 / 15.3) 8 Michele Dondi <bik.mido@tiscalinet.it>
0.634 ( 1.1 / 1.7) 5 hubert depesz lubaczewski <depesz@depesz.pl>
0.634 ( 3.8 / 5.9) 7 "Teh (tî'pô)" <teh@mindless.com>
0.607 ( 14.0 / 23.1) 26 Brian McCauley <nobull@mail.com>
0.576 ( 13.6 / 23.5) 17 tassilo.parseval@post.rwth-aachen.de
Bottom 10 Posters by OCR (minimum of five posts)
=================================================
(kb) (kb)
OCR orig / body Posts Address
----- -------------- ----- -------
0.420 ( 1.8 / 4.4) 5 Josef =?iso-8859-1?Q?M=F6llers?= <josef.moellers@fujitsu-siemens.com>
0.390 ( 3.6 / 9.2) 5 Uri Guttman <uri@stemsystems.com>
0.390 ( 3.9 / 10.0) 8 "Bill Smith" <wksmith@optonline.net>
0.359 ( 2.2 / 6.2) 5 bwalton@rochester.rr.com
0.338 ( 1.7 / 5.0) 5 ebchang <echang@netstorm.net>
0.327 ( 3.1 / 9.4) 6 "john bennett" <johngnub@worldnet.att.net>
0.299 ( 4.0 / 13.4) 10 "John W. Krahn" <krahnj@acm.org>
0.293 ( 1.9 / 6.4) 6 Graham Wood <Graham.T.Wood@oracle.com>
0.286 ( 2.9 / 10.1) 5 "Christian Caron" <nospam@nospam.org>
0.198 ( 1.2 / 6.1) 5 "Tan Nguyen" <nospam@nospam.com>
30 posters (12%) had at least five posts.
Top 10 Threads by Number of Posts
=================================
Posts Subject
----- -------
17 deleting a file... kill ??? Thanks...
17 regular expression
14 Before I buy the Book ...
14 [REPOST] Need advice on a project (wrt to tie'ing to a file and general strategy)
13 Newbie-Qeustion
13 Replacing string in binary file
12 deleting a file... kill ???
12 calling an external script within a script?
10 perl bug? "eq" less restrictive then "=="?
9 backticks/system command
These threads accounted for 19.9% of all articles.
Top 10 Threads by Volume
========================
(kb) (kb) (kb) (kb)
Volume ( hdr/ body/ orig) Posts Subject
-------------------------- ----- -------
48.8 ( 12.8/ 34.2/ 17.7) 14 [REPOST] Need advice on a project (wrt to tie'ing to a file and general strategy)
38.5 ( 15.4/ 21.6/ 12.5) 17 deleting a file... kill ??? Thanks...
28.1 ( 12.2/ 15.1/ 8.2) 13 Newbie-Qeustion
27.4 ( 14.8/ 10.3/ 6.1) 17 regular expression
27.3 ( 4.6/ 22.5/ 11.0) 5 Sending Mail, How many SMTP Servers used?
24.5 ( 14.6/ 9.1/ 5.6) 14 Before I buy the Book ...
22.3 ( 11.4/ 10.2/ 5.6) 13 Replacing string in binary file
22.1 ( 6.7/ 15.0/ 12.7) 9 waitpid not returning pid?
21.9 ( 6.3/ 14.7/ 7.7) 8 Question about hash entries with two keys
21.6 ( 10.2/ 11.2/ 5.0) 12 deleting a file... kill ???
These threads accounted for 22.4% of the total volume.
Top 10 Threads by OCR (minimum of five posts)
==============================================
(kb) (kb)
OCR orig / body Posts Subject
----- -------------- ----- -------
0.847 ( 12.7/ 15.0) 9 waitpid not returning pid?
0.759 ( 1.9/ 2.6) 5 Help with code that cuts off text at first <br>
0.743 ( 1.9/ 2.5) 5 Perl bloggers?
0.743 ( 2.3/ 3.1) 6 Regular Expression
0.733 ( 4.4/ 6.0) 6 Advice Please
0.699 ( 2.1/ 3.1) 5 Help: Sending to a $ variable in cgi SMTP
0.669 ( 7.8/ 11.7) 9 MD5 password encryption
0.661 ( 3.0/ 4.5) 5 warnings::register, no warnings, and inheritance
0.660 ( 2.5/ 3.8) 6 Difference between @foo = <`some program`> and @foo = `some program` ??
0.658 ( 2.0/ 3.0) 5 cyrpt() and other questions....
Bottom 10 Threads by OCR (minimum of five posts)
=================================================
(kb) (kb)
OCR orig / body Posts Subject
----- -------------- ----- -------
0.467 ( 3.7 / 7.9) 6 Tk help, please.
0.465 ( 1.5 / 3.2) 6 Overloading and recursion; how to turn '""' overloading off?
0.456 ( 4.0 / 8.7) 8 defined() upon aggregates (hashes and arrays) is not guaranteed to produce intuitive results
0.450 ( 1.9 / 4.3) 6 pulling out text from between two strings
0.447 ( 5.0 / 11.2) 12 deleting a file... kill ???
0.435 ( 4.4 / 10.2) 8 Writing Microsoft Outlook Notes With Perl
0.427 ( 3.9 / 9.2) 6 format to output
0.369 ( 3.6 / 9.7) 6 Hiding password variables in PERL
0.318 ( 3.7 / 11.6) 7 opendir/readdir can't handle french characters: What am I missing?
0.314 ( 3.9 / 12.3) 9 backticks/system command
51 threads (28%) had at least five posts.
Top 10 Targets for Crossposts
=============================
Articles Newsgroup
-------- ---------
6 de.comp.lang.perl.misc
3 alt.perl
2 comp.os.linux.misc
2 comp.lang.perl
2 fr.comp.lang.perl
1 microsoft.public.win2000.cmdprompt.admin
1 microsoft.public.inetserver.iis
1 alt.msdos.batch.nt
1 comp.lang.perl.modules
Top 10 Crossposters
===================
Articles Address
-------- -------
3 "Neil MacMurchy" <neilmcse@hotmail.com>
2 Shelby <webmaster@smwebdesigns.com>
2 Benjamin Goldberg <goldbb2@earthlink.net>
2 "Hisham Mohamed" <hisham.mohamed@no-spam.engelhard.com.noSPAM>
2 "Chris" <christian.le-corre@esf.ericsson.se>
2 tony@realh.co.uk
1 Codmate <codmate@NOSPAMntlworld.com>
1 Graham Wood <Graham.T.Wood@oracle.com>
1 Marc Pelletier <marcjgpelletier@hotmail.com>
1 Brian McCauley <nobull@mail.com>
------------------------------
Date: Mon, 28 Oct 2002 16:48:27 +0000
From: Simon Andrews <simon.andrews@bbsrc.ac.uk>
Subject: Re: Strange Performance Thing
Message-Id: <3DBD6A5B.4CD0FBC3@bbsrc.ac.uk>
Sven wrote:
>
> Hi folks,
>
> I've posted this a couple of days ago with no response. You'd help me a
> big deal if you copy/paste the below script, try it on your box and post
> the result. Please post as well the Perl version (perl -v), kernel
> version (uname -a) and distribution (like RedHat 8) along with it. I'm
> particularly interested in people using RedHat 8 as I do.
No problem with that code here...
$ perl -v
This is perl, v5.6.0 built for i386-linux
$ uname -srm
Linux 2.4.9-21smp i686
Based on Redhat 7.1
$ ./regextest.pl
1) Time Case Insensitive Regex from File
20000 found in 0 secs
2) Time Case Insensitive Regex from RAM
20000 found in 0 secs
3) Time Case Sensitive Regex from File
20000 found in 0 secs
4) Time Case Sensitive Regex from RAM
20000 found in 0 secs
The peak memory usage is only about 2.4Mb as well so I doubt it's a
problem with the machine swapping.
It also works OK on perl 5.6.1 on an alpha (CTU 5.1), and under
activeperl 5.6.1 on Windows. Something very strange must be happening
on your machine. When you're in the midst of your 26 second wait what
does top show is taking all the system resources??
Simon.
------------------------------
Date: Mon, 28 Oct 2002 13:08:59 -0500
From: "Christian Caron" <nospam@nospam.org>
Subject: Re: Strange Performance Thing
Message-Id: <apjufr$lsn1@nrn2.NRCan.gc.ca>
colargol> perl -v
This is perl, v5.6.1 built for i386-freebsd
colargol> uname -a
FreeBSD FreeBSD 4.6.1-RELEASE #3
1) Time Case Insensitive Regex from File
20000 found in 0 secs
2) Time Case Insensitive Regex from RAM
20000 found in 0 secs
3) Time Case Sensitive Regex from File
20000 found in 1 secs
4) Time Case Sensitive Regex from RAM
20000 found in 0 secs
"Sven" <un1@bluewin.ch> wrote in message
news:un1-55FE50.14233528102002@zinews.unizh.ch...
> Hi folks,
>
> I've posted this a couple of days ago with no response. You'd help me a
> big deal if you copy/paste the below script, try it on your box and post
> the result. Please post as well the Perl version (perl -v), kernel
> version (uname -a) and distribution (like RedHat 8) along with it. I'm
> particularly interested in people using RedHat 8 as I do.
>
> Thank you for your help! Sven
>
>
> === === === Original Posting "Slow File Read and Regex === === ===
>
> I experience a strange behaviour ever since I upgraded from Perl 5.6.1
> to 5.8.0.
>
> I'm reading a file line by line and checking every line againts a regex.
> The performance drops a lot if you use /i to make the regex case
> insensitive. Then again if you don't read from a file but cruise an
> array, there's no difference.
>
> Here's a little test script to illustrate this:
>
> ------------------------------------------------------------------------
> #!/usr/bin/perl
>
> # Create Sample File (sample.txt) and Array (@sample)
>
> $line = "xxxxxxxxxxABCDxxxxxxxxxx\n";
> @sample = ();
> open(SAMPLE,'>sample.txt');
> for (my $i=0;$i<20000;$i++) {
> push @sample, $line;
> print SAMPLE $line;
> }
> close(SAMPLE);
>
> # Test
>
> print "1) Time Case Insensitive Regex from File\n";
> open(SAMPLE,'sample.txt');
> $cnt = 0;
> $go = time;
> while (<SAMPLE>) { $cnt++ if /ABCD/; }
> print "$cnt found in ".(time-$go)." secs\n\n";
> close(SAMPLE);
>
> print "2) Time Case Insensitive Regex from RAM\n";
> $cnt = 0;
> $go = time;
> for ($i=0;$i<20000;$i++) {
> $_ = $sample[$i];
> $cnt++ if /ABCD/;
> }
> print "$cnt found in ".(time-$go)." secs\n\n";
>
> print "3) Time Case Sensitive Regex from File\n";
> open(SAMPLE,'sample.txt');
> $cnt = 0;
> $go = time;
> while (<SAMPLE>) { $cnt++ if /ABCD/i; } # added /i to regex
> print "$cnt found in ".(time-$go)." secs\n\n";
> close(SAMPLE);
>
> print "4) Time Case Sensitive Regex from RAM\n";
> $cnt = 0;
> $go = time;
> for ($i=0;$i<20000;$i++) {
> $_ = $sample[$i];
> $cnt++ if /ABCD/i; # added /i to regex
> }
> print "$cnt found in ".(time-$go)." secs\n\n";
> ------------------------------------------------------------------------
>
> As you see, test 1 and 3 are completely identical (but adding the /i)
> and the same goes for 2 and 4.
>
> Now see the output on my linux box:
>
> 1) Time Case Insensitive Regex from File
> 20000 found in 0 secs
>
> 2) Time Case Insensitive Regex from RAM
> 20000 found in 0 secs
>
> 3) Time Case Sensitive Regex from File
> 20000 found in 26 secs
>
> 4) Time Case Sensitive Regex from RAM
> 20000 found in 0 secs
>
> What's going on at test 3 there? I'm really out of clues.
>
> To give you an impression of my linux box: It's an old i586 operated by
> RedHat 8.0 (which includes Perl 5.8.0 built for i386-linux-thread-multi)
> on Kernel 2.4.18-17.8.0. The box is not running X, has only 128MB RAM
> but is hardly ever swapping and most of the time >98% idle.
>
> Thanks for any hint!!
>
> Sven
------------------------------
Date: Mon, 28 Oct 2002 17:52:56 GMT
From: pkent <pkent77tea@yahoo.com.tea>
Subject: Re: system() and shell "metacharacters"
Message-Id: <pkent77tea-DAF011.17525428102002@news-text.blueyonder.co.uk>
In article <jDbv9.142622$zE6.493465@rwcrnsc51.ops.asp.att.net>,
Stan Murch <smurch@no.spam> wrote:
> Could someone explain please why this is not a bug in Perl (5.8.0, solaris):
>
> % perl -e 'die $! if system ":"'
> No such file or directory at -e line 1.
>
> It seems to me that system's understanding of "shell metacharacters"
> doesn't extend to recognizing ":" as the first word. True, colon isn't
> technically a metacharacter but system() is still breaking its promise
> to behave the same as the shell would when taking the fast (no shell) route.
Although it doesn't explicity say, I infer from the 'system' docs that
the metacharacters it looks for are Bourne Shell, /bin/sh,
metacharacters. Now, the sh(1) manapge that I'm reading looks like ':'
"does nothing ... returns a zero exit code", while the bash ':' is noted
as doing a bit more.
In either case I'd interpret ':' as a special builtin command, not a
metacharacter, so I'd say that system() still (pedantically) does the
right thing (no metacharacters, hence no intermediate shell). My
particular perl docs for 5.6.1 don't _promise_ anything like you say, so
maybe this is a new feature in 5.8, which I haven't fully installed yet.
If you want a particular shell to actually run a command for you, try
something like:
system('/bin/sh', '-c', ':');
although check your local system's docs, etc.
P
--
pkent 77 at yahoo dot, er... what's the last bit, oh yes, com
Remove the tea to reply
------------------------------
Date: 28 Oct 2002 18:50:15 +0000
From: Brian McCauley <nobull@mail.com>
Subject: Re: system() and shell "metacharacters"
Message-Id: <u9znsycs9k.fsf@wcl-l.bham.ac.uk>
Stan Murch <smurch@no.spam> writes:
> Could someone explain please why this is not a bug in Perl (5.8.0, solaris):
>
> % perl -e 'die $! if system ":"'
> No such file or directory at -e line 1.
>
> It seems to me that system's understanding of "shell metacharacters"
> doesn't extend to recognizing ":" as the first word. True, colon isn't
> technically a metacharacter but system() is still breaking its promise
> to behave the same as the shell would when taking the fast (no shell)
> route.
I'd agree this is a bug. But it is not a very important one. I
suggest if it annoys you that you should submit a patch.
--
\\ ( )
. _\\__[oo
.__/ \\ /\@
. l___\\
# ll l\\
###LL LL\\
------------------------------
Date: 28 Oct 2002 09:55:10 -0800
From: ralawrence@my-deja.com (Richard Lawrence)
Subject: Working out if string A is related to string B
Message-Id: <b1b8a8d6.0210280955.72ec8caa@posting.google.com>
Hi all,
Hope someone can help. I'm not sure if this is the best NG for this
question, but since I'll be working in perl, I figured this was as
good as any. Please correct me if I'm wrong.
I have two string, A and B, and want to figure out how "similar" they
are to each other. I've looked in CPAN and can't find anything so I
figured that I'd roll my own. Here is one suggestion I have:
# is stringB similar to stringA?
# note: proof of concept, code not tested and definately not
efficient.
my $stringA = "...something...";
my $stringB = "...something else...";
# split up stringA and stringB into words
my @stringA_bits = split(/ /, $stringA);
my @stringB_bits = split(/ /, $stringB);
# remove duplicates in both
undef %saw;
@stringA_sortedbits = grep(!$saw{$_}++, @stringA_bits);
undef %saw;
@stringB_sortedbits = grep(!$saw{$_}++, @stringB_bits);
# remove words under 4 letters long from each
my $pos;
for ($pos = 0; $stringA_sortedbits[$pos]; $pos++)
{
if (length($stringA_sortedbits[$pos]) < 4)
{
splice @stringA_sortedbits, $pos+1, 1;
# i think $pos--, so that it ends up in the same place next time
# we go around the loop
$pos--;
}
}
# do the same for stringB
..code snipped..
# now, if a word in A appears in B then assign a number of points to B
# in this case, the length of the word
my $score = 0;
foreach (@stringA_sortedbits)
{
$score += length($_) if (in_stringB($_));
}
where in_stringB is something like
sub in_stringB
{
my $word = shift;
foreach (@stringB_sortedbits)
{
return 1 if ($_ eq $word);
}
return 0;
}
Now I have a "score" for stringB that relates to how closely it
matches A. Bonus points are awared for the longer (and more specific
words). Given that the maximum score of A is:
my $max = 0;
foreach (@string_A)
{
$score .= length($_);
}
I should then be able to tell how relevant B is to A. Or am I just
going to be rathly wildly out?
Or can anyone else come up with a far better way of saying that "A is
possibly to be relevant to B more than A is to C"?
(an example usage would be an online FAQ, where after each question
there is a possiblilty of a "related question" style link).
Many thanks in advance,
Rich
------------------------------
Date: 28 Oct 2002 18:39:31 +0000
From: Brian McCauley <nobull@mail.com>
Subject: Re: Working out if string A is related to string B
Message-Id: <u9d6pue7bw.fsf@wcl-l.bham.ac.uk>
ralawrence@my-deja.com (Richard Lawrence) writes:
> Hope someone can help. I'm not sure if this is the best NG for this
> question, but since I'll be working in perl, I figured this was as
> good as any. Please correct me if I'm wrong.
>
> I have two string, A and B, and want to figure out how "similar" they
> are to each other. I've looked in CPAN and can't find anything
I can find String::Approx it may not be exactly what you are lookign
for but it's similar.
--
\\ ( )
. _\\__[oo
.__/ \\ /\@
. l___\\
# ll l\\
###LL LL\\
------------------------------
Date: Mon, 28 Oct 2002 10:42:04 -0800
From: "Newbie" <mike_constant@yahoo.com>
Subject: Re: Working out if string A is related to string B
Message-Id: <apk0d4$2bi3c$1@ID-161864.news.dfncis.de>
"Richard Lawrence" <ralawrence@my-deja.com> wrote in message
news:b1b8a8d6.0210280955.72ec8caa@posting.google.com...
> Hi all,
>
> Hope someone can help. I'm not sure if this is the best NG for this
> question, but since I'll be working in perl, I figured this was as
> good as any. Please correct me if I'm wrong.
>
> I have two string, A and B, and want to figure out how "similar" they
> are to each other. I've looked in CPAN and can't find anything so I
> figured that I'd roll my own. Here is one suggestion I have:
>
> # is stringB similar to stringA?
> # note: proof of concept, code not tested and definately not
> efficient.
>
> my $stringA = "...something...";
> my $stringB = "...something else...";
>
> # split up stringA and stringB into words
> my @stringA_bits = split(/ /, $stringA);
> my @stringB_bits = split(/ /, $stringB);
>
> # remove duplicates in both
> undef %saw;
> @stringA_sortedbits = grep(!$saw{$_}++, @stringA_bits);
> undef %saw;
> @stringB_sortedbits = grep(!$saw{$_}++, @stringB_bits);
>
> # remove words under 4 letters long from each
>
> my $pos;
> for ($pos = 0; $stringA_sortedbits[$pos]; $pos++)
> {
> if (length($stringA_sortedbits[$pos]) < 4)
> {
> splice @stringA_sortedbits, $pos+1, 1;
>
> # i think $pos--, so that it ends up in the same place next time
> # we go around the loop
> $pos--;
> }
> }
>
> # do the same for stringB
>
> ..code snipped..
>
> # now, if a word in A appears in B then assign a number of points to B
> # in this case, the length of the word
>
> my $score = 0;
> foreach (@stringA_sortedbits)
> {
> $score += length($_) if (in_stringB($_));
> }
>
> where in_stringB is something like
>
> sub in_stringB
> {
> my $word = shift;
>
> foreach (@stringB_sortedbits)
> {
> return 1 if ($_ eq $word);
> }
> return 0;
> }
>
>
> Now I have a "score" for stringB that relates to how closely it
> matches A. Bonus points are awared for the longer (and more specific
> words). Given that the maximum score of A is:
>
> my $max = 0;
> foreach (@string_A)
> {
> $score .= length($_);
> }
>
> I should then be able to tell how relevant B is to A. Or am I just
> going to be rathly wildly out?
>
> Or can anyone else come up with a far better way of saying that "A is
> possibly to be relevant to B more than A is to C"?
>
> (an example usage would be an online FAQ, where after each question
> there is a possiblilty of a "related question" style link).
>
> Many thanks in advance,
>
> Rich
Check out "edit distance" algo. The implementation in Perl is
String::Approx
------------------------------
Date: Mon, 28 Oct 2002 12:38:30 -0600
From: Michael Carman <mjcarman@mchsi.com>
Subject: Re: Working out if string A is related to string B
Message-Id: <apk09o$6po3@onews.collins.rockwell.com>
On 10/28/02 11:55 AM, Richard Lawrence wrote:
>
> I have two string, A and B, and want to figure out how "similar" they
> are to each other. I've looked in CPAN and can't find anything so I
> figured that I'd roll my own. Here is one suggestion I have:
Take a look at String::Approx and String::Similarity. Even if they don't
quite do what you want, it should provide a starting point.
-mjc
------------------------------
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.
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 4038
***************************************