Forwarded to the list, since I botched this again. Sorry. ---------- Forwarded message ---------- From: David Mertens <[email protected]> Date: Fri, Jan 20, 2012 at 9:36 AM Subject: Re: [Perldl] PDL and arrays of text To: Craig DeForest <[email protected]>
On Fri, Jan 20, 2012 at 9:07 AM, Craig DeForest <[email protected]>wrote: > PDLs are the wrong tool for storing and manipulating collections of > variable length strings. There is a very nice tool for that, called > "Perl". If the desire is to make collections of strings that, > syntactically, act like like PDLs, a nice strategy might be to start with > thread_define and thereby implement threading in Perl itself. That would > further blur the distinction between perl lists and PDLs. > > Cheers, > Craig > Kare - I hope Craig's joke didn't offend you. For what it's worth, it gave me a good laugh. If you're doing lots of operations with words in Perl arrays, you should look into List::MoreUtils (http://p3rl.org/List::MoreUtils) which is implemented in XS, I believe, so it should be about as fast as they come. For your particular example, you might be able to get away with Perl's grep: # Get the list of matching text (rather useless for strict eq) my @matches = grep { $_ eq "some text" } @input; But to get the actual indices (ala which), you should use List::MoreUtils' indexes, which is described as being "just like grep only that it returns indices instead of values" my @indices = indices { $_ eq "some text" } @input; David > On Jan 20, 2012, at 8:02 AM, Bryan Jurish wrote: > > > moin Kare, > > > > I've done something like what I think you're suggesting using PDL, but > > it amounted in my case to mapping all the text symbols to integer > > identifiers (and back) using perl hashes (and arrays), so I could do > > something like: > > > > ##-- setup symbol table for strings in @STRINGS > > $prev = 'NOT_A_SYMBOL'; > > @id2sym = map {$prev eq $_ ? qw() : ($prev=$_)} @STRINGS; > > %sym2id = map {($id2sym[$_]=>$_)} (0..$#id2sym); > > > > ##-- encode @STRINGS as a piddle > > $sp = pdl(long, @sym2id{@STRINGS}); > > > > ##-- do something interesting > > $which = which($sp==$id2sym{"some symbol"}); > > > > ... it would be really nice to have a better way to deal with large > > symbol tables than perl hashes, but this strategy works for me most of > > the time... > > > > marmosets, > > Bryan > > > > On 2012-01-20 14:32, Kåre Edvardsen wrote: > >> I've been away from programming a couple of years now, but got to get > >> back. Are there any news on indexing text arrays in perl/PDL? > >> > >> Something like: > >> which(@txtarr) == "some text"; > >> > >> Cheers, > >> Kare > > > > > > -- > > Bryan Jurish "There is *always* one more bug." > > [email protected] -Lubarsky's Law of Cybernetic Entomology > > > > > > _______________________________________________ > > Perldl mailing list > > [email protected] > > http://mailman.jach.hawaii.edu/mailman/listinfo/perldl > > > > > _______________________________________________ > Perldl mailing list > [email protected] > http://mailman.jach.hawaii.edu/mailman/listinfo/perldl > -- Sent via my carrier pigeon. -- Sent via my carrier pigeon.
_______________________________________________ Perldl mailing list [email protected] http://mailman.jach.hawaii.edu/mailman/listinfo/perldl
