in reply to Re^3: Truncating after the last period
in thread Truncating after the last period

Your code still has the same defect in it.

#!/usr/bin/perl -l use strict; use warnings; my $string = '.' x 400_000_000; print length $string; # Prints 400000000 $string =~ s[^.{1,400}\.\K.*?$][]; print length $string; # Prints 401

It's so easily fixed it boggles the mind you still haven't figured out how to fix it.

Replies are listed 'Best First'.
Re^5: Truncating after the last period
by BrowserUk (Patriarch) on Aug 23, 2011 at 00:52 UTC

    Hm. Curiouser and curiouser. I haven't made any attempt to 'fix' it, because you (nor anyone) had demonstrated a problem with it. And you still haven't:

    $s = '.' x 500;; $s =~ s[^.{1,400}\.\K.*?$][];; print length $s;; 401

    I guess your system must be broken?


    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.

      I'm sure by now it's clear to Simon, the OP, how useless your code is to him in its defective state. That's all that matters.

      It's astonishing you continue to repost the same defective code over and over again—this time with the evidence of the obviously wrong result included in the code!

        I'm sure by now it's clear to Simon, the OP, how useless your code is to him in its defective state. That's all that matters.

        If, by useless, you mean that as posted it can result in a string of 401 characters in length (and if so, wouldn't it have saved an great deal of time if you'd just come out and said that instead of trying to be snide!), then I guess you haven't actually thought about why that might be so. Much less actually tried it on realistic data.

        Consider the case where the first sentence (minus the period) in the string is exactly 400 characters in length:

        $s = "Claims revolve around the longest printed sentence, as there is +no absolute limit on the length of a written English sentence; a sent +ence describing successive reading, for example, could be infinitely +long, and one concatenating clauses with grammatical conjunctions suc +h as and could go on as long as material may be supplied; which makes + any claim made for the longest sentence trivial to overturn. then so +me other stuff here.";; $s =~ s[^.{1,400}\.\K.*?$][];; print length $s;; 401 print $s;; Claims revolve around the longest printed sentence, as there is no abs +olute limit on the length of a written English sentence; a sentence d +escribing successive reading, for example, could be infinitely long, +and one concatenating clauses with grammatical conjunctions such as a +nd could go on as long as material may be supplied; which makes any c +laim made for the longest sentence trivial to overturn.

        Is it better to keep the extra character, or discard the whole sentence?

        Unrealistic you might say, except that other than my clumsy extension (following the ;), that sentence is verbatim from Wikipedia. And James Joyce's famous Ulysses, contained many long sentences, including one 11,281 words long, and another 12,931 words long.

        But even without such run-ons, the point still holds:

        $s = "The quick brown fox jumps over the lazy dog. The quick brown fox + jumps over the lazy dog. The quick brown fox jumps over the lazy dog +. The quick brown fox jumps over the lazy dog. The quick brown fox ju +mps over the lazy dog. The quick brown fox jumps over the lazy dog. T +he quick brown fox jumps over the lazy dog. The quick brown fox jumps + over the lazy dog. A sentence that exactly fills to the 400. The qu +ick brown fox jumps over the lazy dog. The quick brown fox jumps ove +r the lazy dog. The quick brown fox jumps over the lazy dog.";; $s =~ s[^.{1,400}\.\K.*?$][];; print length $s;; 401 print $s;; The quick brown fox jumps over the lazy dog. The quick brown fox jumps + over the lazy dog. The quick brown fox jumps over the lazy dog. The +quick brown fox jumps over the lazy dog. The quick brown fox jumps ov +er the lazy dog. The quick brown fox jumps over the lazy dog. The qui +ck brown fox jumps over the lazy dog. The quick brown fox jumps over +the lazy dog. A sentence that exactly fills to the 400.

        Is it better to retain the extra character, or discard the whole of the last sentence?

        When I was writing a search with context function a while back, in consultation with others, I concluded that the former is preferable.

        But, should the OP decide that he simply cannot afford to retain that extra character, I'm quite certain that he is quite capable of seeing the same simple workaround that you've claimed to have seen(*). He can make up his own mind on the issue.

        (*)Of course, if you'd just come out with the problem you perceived, and offered your solution to it, instead of trying to come across all superior, then we could have saved a about 20 posts and a bunch of time.


        Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
        "Science is about questioning the status quo. Questioning authority".
        In the absence of evidence, opinion is indistinguishable from prejudice.