Beefy Boxes and Bandwidth Generously Provided by pair Networks Joe
P is for Practical
 
PerlMonks  

Re: Longest repeated string...

by Limbic~Region (Chancellor)
on Feb 03, 2006 at 12:21 UTC ( [id://527732]=note: print w/replies, xml ) Need Help??

This is an archived low-energy page for bots and other anonmyous visitors. Please sign up if you are a human and want to interact.


in reply to Longest repeated string...

Yzzyx,
First, you are going to want to google for 'longest common substring' as your brute force approach is definately not the right way to go.

Second, the idiom you don't understand deserves to be in the "Perl Idioms Explained" category. In a nutshell, Perl will do what you mean (DWYM) when you give it proper context. A list in scalar context returns the number of items in the list.

Third - good luck. No matter what algorithm you use (LCS) and what language you use (C/Assembler), this is not going to be a fast answer.

Cheers - L~R

Replies are listed 'Best First'.
Re^2: Longest repeated string...
by japhy (Canon) on Feb 03, 2006 at 12:37 UTC
    A list in scalar context returns the number of items in the list. Not quite.

    A list assignment in scalar context returns the number of items in the right-hand list.


    Jeff japhy Pinyan, P.L., P.M., P.O.D, X.S.: Perl, regex, and perl hacker
    How can we ever be the sold short or the cheated, we who for every service have long ago been overpaid? ~~ Meister Eckhart
      japhy,
      Thanks - which is why I said this deserved an entry in "Perl Idioms Explained". I could argue that there is no assignment going on in:
      while ( @array ) { ... } # or print "Array is empty\n" if ! @array;
      but then we could discuss the difference between lists and arrays and it wouldn't be worth it. I think I was able to get the OP to understand even if I wasn't completely accurate. I do think it would make for a good entry in "Perl Idioms Explained".

      Cheers - L~R

        If you don't, I will. (Make the PIE node for this idiom, I mean.)

        Jeff japhy Pinyan, P.L., P.M., P.O.D, X.S.: Perl, regex, and perl hacker
        How can we ever be the sold short or the cheated, we who for every service have long ago been overpaid? ~~ Meister Eckhart

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://527732]
help
Sections?
Information?
Find Nodes?
Leftovers?
    Notices?
    hippoepoptai's answer Re: how do I set a cookie and redirect was blessed by hippo!
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.