[32021] in Perl-Users-Digest

home help back first fref pref prev next nref lref last post

Perl-Users Digest, Issue: 3285 Volume: 11

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Feb 14 09:09:26 2011

Date: Mon, 14 Feb 2011 06:09:10 -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, 14 Feb 2011     Volume: 11 Number: 3285

Today's topics:
        gcc error in Clone (was: Subroutine exec...) <marc.girod@gmail.com>
    Re: Hashes are good, but not good enough. <tooscattered@gmail.com>
    Re: Hashes are good, but not good enough. <rvtol+usenet@xs4all.nl>
    Re: Hashes are good, but not good enough. <nospam-abuse@ilyaz.org>
    Re: How to exclude action of Find::Find::find in subdir <vadim.dvorkin@gmail.com>
        How to use (??{code}) correctly in foreach loop? <pengyu.ut@gmail.com>
    Re: How to use (??{code}) correctly in foreach loop? <nospam-abuse@ilyaz.org>
    Re: How to use (??{code}) correctly in foreach loop? <nospam.gravitalsun@hotmail.com.nospam>
    Re: How to use (??{code}) correctly in foreach loop? <nospam.gravitalsun@hotmail.com.nospam>
    Re: How to use (??{code}) correctly in foreach loop? <pengyu.ut@gmail.com>
        Subroutine exec redefined warning with perl 5.12.2 <marc.girod@gmail.com>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

----------------------------------------------------------------------

Date: Mon, 14 Feb 2011 06:08:03 -0800 (PST)
From: Marc Girod <marc.girod@gmail.com>
Subject: gcc error in Clone (was: Subroutine exec...)
Message-Id: <bada3d8b-dd4c-407b-9485-57f0990c5e41@1g2000yqq.googlegroups.com>

On Feb 14, 12:14=A0pm, Marc Girod <marc.gi...@gmail.com> wrote:

> Clone.xs: In function 'sv_clone':
> Clone.xs:160: error: duplicate case value
> Clone.xs:154: error: previously used here

BTW, this isn't true:

W:\atcctest\Clone>perl -nle "print if $. =3D=3D 154 or $. =3D=3D 160" Clone=
 .xs
      case SVt_IV:              /* 1 */
      case SVt_RV:              /* 3 */

This is version 0.28.

Marc


------------------------------

Date: Sun, 13 Feb 2011 06:40:24 -0800 (PST)
From: scattered <tooscattered@gmail.com>
Subject: Re: Hashes are good, but not good enough.
Message-Id: <3d380234-e788-4512-8b65-b9c5cc663c33@y31g2000prd.googlegroups.com>

On Feb 11, 4:13=A0am, "George Mpouras"
<nospam.gravital...@hotmail.com.nospam> wrote:
> We all find hashes pretty convenient, and helpful to make things fast; bu=
t
> the problem with hashes is that they consume too much memory on big trees=
,
> and they are too slow for hundred millions of keys. Try it yourself.
>
> What we need in these situations is something different called DAWG.
>
> Please have a look at this article to understand what I mean.
>
> http://en.wikipedia.org/wiki/DAWG
>
> I tried to implement this DAWG data structure with Perl but I found it VE=
RY
> difficult.
>
> What are your thoughts about the necessity of this new data structure.

DAWGs are data structures for strings whose sole purpose is to tell if
a given string is in a set of strings. It can't be used as a data
structure which implements a key-data mapping. The entire point of a
DAWG is that strings which begin and end the same way end up at the
same final node - so you can't just put the keyed data at that node.
You could put a hash at a final node, with keys consisting of those
keys in the original set of keys which lead to the same DAWG node -
but in your intended application of 100s of millions of keys, you
would doubtless just replace one huge hash by thousands of smaller,
but still large hashes. There might be *some* scenario in which this
would be advantageous (since these smaller hashes would have fewer
collisions) - but the overhead would be substantial and the lack of
easy insertions and deletions a major drawback. Hashes are good at
what they do, and DAWGs provide no real competition.

Having said all this, a DAWG implementation in Perl would be quite
nice, though it would clearly belong in CPAN rather than as a core
part of the language. It is hard to believe that it hasn't been done
by anybody, but maybe not (the unfortunate tendency for semi-literate
people to spell "dog" as "dawg" in the mistaken belief that this is
somehow cute or cool makes searching for DAWG implementations somewhat
annoying) . A Perl DAWG implementation could make code for something
like http://dotnetperls.com/scrabble more elegant.

-scattered


------------------------------

Date: Sun, 13 Feb 2011 17:25:32 +0100
From: "Dr.Ruud" <rvtol+usenet@xs4all.nl>
Subject: Re: Hashes are good, but not good enough.
Message-Id: <4d5805fd$0$81475$e4fe514c@news.xs4all.nl>

On 2011-02-13 15:40, scattered wrote:

> DAWGs are data structures for strings whose sole purpose is to tell if
> a given string is in a set of strings.

About strstr: http://volnitsky.com/project/str_search/

-- 
Ruud


------------------------------

Date: Sun, 13 Feb 2011 22:46:08 +0000 (UTC)
From: Ilya Zakharevich <nospam-abuse@ilyaz.org>
Subject: Re: Hashes are good, but not good enough.
Message-Id: <slrnilgnpg.b2b.nospam-abuse@powdermilk.math.berkeley.edu>

On 2011-02-12, Peter J  Holzer <hjp-usenet2@hjp.at> wrote:
>> I find this claim 
>> 
>>   a DAWG is very similar to a trie, but it is much more space efficient
>> 
>> very suspicious.  If you want DAWG to be dynamic, then extra "parent"
>> pointers you need to keep would, in most situations, far outweight the
>> space savings.  If DAWG is not intended to change, you do not need
>> parent pointers,
>
> I don't think a DAWG is intended to change. Inserts and deletions look
> expensive to me. You probably build it once from a collection of words
> and then do only lookups.

There is no problem on deletion.  For insertion, one needs a
dictionary of suffixes - which is, essentially, given by parent
pointers, since they form a DAWG as well.

>> but still, I can't imagine many situations in which
>> the tail-folding would save much.
>
> The data structure seems to be designed to represent a dictionary of
> (English) words. Many words share a common suffix, so would expect 
> significant space savings compared to a trie.

"Significant" in which sense?  For me, half an order of magnitude is
significant.  30% is not - in most situations Perl is used for.  I
would expect it to be of second type for English words - but it is
just a guts feeling...  (And I was considered "DAWG vs *folded* tries"
- those where a node contains a substring, not a char.)

> If you use it to store 
> data without common suffixes it will degenerate into a trie, so it should
> never be worse than a trie, IMHO. 

DAWG may be MUCH worse than a folded trie - even if you fold a DAWG.

Ilya


------------------------------

Date: Sun, 13 Feb 2011 21:28:36 -0800 (PST)
From: vdvorkin <vadim.dvorkin@gmail.com>
Subject: Re: How to exclude action of Find::Find::find in subdirectories with known names?
Message-Id: <94bcc75e-9cc8-4f90-adf5-4a5c9e5f7b18@r13g2000yqk.googlegroups.com>

Thanks a lot, J. Gleixner and Jim Gibson. The both ways are working
correctly.

--Vadim



------------------------------

Date: Sun, 13 Feb 2011 18:01:12 -0800 (PST)
From: Peng Yu <pengyu.ut@gmail.com>
Subject: How to use (??{code}) correctly in foreach loop?
Message-Id: <1831debc-88b0-4aee-bb5f-8156339a1350@i40g2000yqh.googlegroups.com>

Hi,

I have the following code and output. I'm not sure why the code
doesn't search for 'abc' in the second string 'efgabcabcd'. Could you
anybody let me know what the problem is and how to fix it?

$ cat main.pl
#!/usr/bin/env perl

use strict;
use warnings;

my @strings=('abcdefgabc', 'efgabcabcd');
my $pattern='abc';

foreach my $s (@strings) {
  my @offsets=();
  {
    use re 'eval';
    $s =~ /(?=\Q$pattern\E)(??{push @offsets, $-[0]})/g;
  }
  print join('::', @offsets), "\n"
}
print "end\n";

$ ./main.pl
0::7

end


------------------------------

Date: Mon, 14 Feb 2011 06:17:49 +0000 (UTC)
From: Ilya Zakharevich <nospam-abuse@ilyaz.org>
Subject: Re: How to use (??{code}) correctly in foreach loop?
Message-Id: <slrnilhi8d.bql.nospam-abuse@powdermilk.math.berkeley.edu>

On 2011-02-14, Peng Yu <pengyu.ut@gmail.com> wrote:
> Hi,
>
> I have the following code and output. I'm not sure why the code
> doesn't search for 'abc' in the second string 'efgabcabcd'. Could you
> anybody let me know what the problem is and how to fix it?
>
> $ cat main.pl
> #!/usr/bin/env perl
>
> use strict;
> use warnings;
>
> my @strings=('abcdefgabc', 'efgabcabcd');
> my $pattern='abc';
>
> foreach my $s (@strings) {
>   my @offsets=();
>   {
>     use re 'eval';
>     $s =~ /(?=\Q$pattern\E)(??{push @offsets, $-[0]})/g;
>   }
>   print join('::', @offsets), "\n"
> }
> print "end\n";

I have no idea what do you want to achieve.  Do you think it is a
scalar context //g, or a list content?

Anyway, I suspect a bug in scalar/list context //g applied to a
foreach-iterator.  Did you try it without (??{}) ?

Ilya


------------------------------

Date: Mon, 14 Feb 2011 11:28:20 +0200
From: "George Mpouras" <nospam.gravitalsun@hotmail.com.nospam>
Subject: Re: How to use (??{code}) correctly in foreach loop?
Message-Id: <ijasi9$1t66$1@ulysses.noc.ntua.gr>


"Peng Yu" <pengyu.ut@gmail.com> wrote in message 
news:1831debc-88b0-4aee-bb5f-8156339a1350@i40g2000yqh.googlegroups.com...
> Hi,
>
> I have the following code and output. I'm not sure why the code
> doesn't search for 'abc' in the second string 'efgabcabcd'. Could you
> anybody let me know what the problem is and how to fix it?
>
> $ cat main.pl
> #!/usr/bin/env perl
>
> use strict;
> use warnings;
>
> my @strings=('abcdefgabc', 'efgabcabcd');
> my $pattern='abc';
>
> foreach my $s (@strings) {
>  my @offsets=();
>  {
>    use re 'eval';
>    $s =~ /(?=\Q$pattern\E)(??{push @offsets, $-[0]})/g;
>  }
>  print join('::', @offsets), "\n"
> }
> print "end\n";
>
> $ ./main.pl
> 0::7
>
> end



# Here is what you want
# somehow the (??{..@offsets...}) defines the arrray as local at the 
namespace at first time
# and "my" undefine it or something like that !

use strict;
use warnings;

my @strings=('abcdefgabc', 'efgabcabcd');
my $pattern='abc';
my @offsets=();

use re 'eval';
foreach my $s (@strings)
{
$s =~ /(?=\Q$pattern\E)(??{push @offsets, $-[0]})/g;
print "Offsets of $s: @offsets\n"
}
no re;

print "end\n";




------------------------------

Date: Mon, 14 Feb 2011 11:30:06 +0200
From: "George Mpouras" <nospam.gravitalsun@hotmail.com.nospam>
Subject: Re: How to use (??{code}) correctly in foreach loop?
Message-Id: <ijaslk$1tcf$1@ulysses.noc.ntua.gr>

# sorry here is the correct one !

use strict;
use warnings;

my @strings=('abcdefgabc', 'efgabcabcd');
my $pattern='abc';
my @offsets=();

foreach my $s (@strings)
{
@offsets=();
{use re 'eval'; $s =~ /(?=\Q$pattern\E)(??{push @offsets, $-[0]})/g }
print "Offsets of $s: @offsets\n"
}

print "end\n"; 




------------------------------

Date: Mon, 14 Feb 2011 05:45:29 -0800 (PST)
From: Peng Yu <pengyu.ut@gmail.com>
Subject: Re: How to use (??{code}) correctly in foreach loop?
Message-Id: <aca41a13-343a-4012-a0cc-22deba047360@v16g2000vbq.googlegroups.com>

On Feb 14, 3:30=A0am, "George Mpouras"
<nospam.gravital...@hotmail.com.nospam> wrote:
> # sorry here is the correct one !
>
> use strict;
> use warnings;
>
> my @strings=3D('abcdefgabc', 'efgabcabcd');
> my $pattern=3D'abc';
> my @offsets=3D();
>
> foreach my $s (@strings)
> {
> @offsets=3D();
> {use re 'eval'; $s =3D~ /(?=3D\Q$pattern\E)(??{push @offsets, $-[0]})/g }
> print "Offsets of $s: @offsets\n"
>
> }
>
> print "end\n";

This works. Thank you!

Also, I don't quite understand why "my @offsets;" has to be moved out
of the loop.

I checked Programming Perl 3rd edition. There are thousands of "my" in
this book. Would you please help me understand why it is the case by
pointing me which page of Programming Perl or which perl document (and
what part of it) I should read?


------------------------------

Date: Mon, 14 Feb 2011 04:14:23 -0800 (PST)
From: Marc Girod <marc.girod@gmail.com>
Subject: Subroutine exec redefined warning with perl 5.12.2
Message-Id: <edd389c1-b5b5-4c6a-99c0-e9cfb951d391@o1g2000yqb.googlegroups.com>

Hello,

I installed Strawberry perl 5.12.2 on my new laptop and started to
install my modules on it.
And I met some surprises. I'll mention 3, but the first is the one
that bothers me for now.

1. I got a new warning, and I'd like to understand whether it displays
a yet unknown problem (with perl up to 5.10) or should just be
silenced (with the next question of how?)

The warning is:

Subroutine exec redefined at C:/strawberry/perl/site/lib/Argv.pm line
852.

I get it in running a command line involving ClearCase::Wrapper::MGi.
This is hard to reproduce without ClearCase, even if the modules are
all on CPAN.
I tried to extract the significant code, but could not reproduce the
symptom.
So, here is my failed attempt at rproducing.
Could you please help me guessing what I could add to reproduce the
symptom, i.e. explain me what precisely it warns against?
There is indeed a redefinition of exec on line 852 of Argv.pm, but I
cannot see how it differes from the one below.

#!/usr/bin/perl

use warnings;
use strict;

package Foo;

sub exec {
  print "overloaded in Foo\n";
}
sub new {
  return bless {}, __PACKAGE__;
}

package Bar;
our @ISA = qw(Foo);

sub exec {
  my $self = shift;
  print "overloaded in Bar\n";
  return $self->SUPER::exec;
}
sub new {
  return bless {}, __PACKAGE__;
}

package main;
my $bar = new Bar;
$bar->exec;
exit 0;

This works the same on 5.12 as on 5.10:

$ ~/tmp/execdemo
overloaded in Bar
overloaded in Foo



2. Running: 'perl Makefile.PL' for all the modules I have tried
produces makefiles with a systematic syntax error:
double opening braces instead of single ones.

Running the following solves the problem:

W:\atcctest\Clone>perl -pi.bak -e "s/{{/{/g" Makefile



3. I fail to build the Clone package (from CPAN) with the following
error:

W:\atcctest\Clone>gmake
Skip blib\lib\Clone.pm (unchanged)
gcc -c   -s -O2 -DWIN32 -DHAVE_DES_FCRYPT -DUSE_SITECUSTOMIZE -
DPERL_IMPLICIT_CONTEXT -DPERL_IMPLICIT_SYS -fno-strict-aliasing -mms-
bitfields -DPERL_MSVCRT_READFIX -O3   -DVERSION=\"0.28\" -DXS_VERSION=
\"0.28\"  "-IC:\strawberry\perl\lib\CORE"   Clone.c
Clone.xs: In function 'sv_clone':
Clone.xs:160: error: duplicate case value
Clone.xs:154: error: previously used here
gmake: *** [Clone.o] Error 1

Thanks,
Marc


------------------------------

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:

To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.

Back issues are available via anonymous ftp from
ftp://cil-www.oce.orst.edu/pub/perl/old-digests. 

#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 3285
***************************************


home help back first fref pref prev next nref lref last post