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

Re: Creating an abstract

by tybalt89 (Monsignor)
on Aug 09, 2021 at 21:38 UTC ( [id://11135749]=note: print w/replies, xml ) Need Help??


in reply to Creating an abstract

succinct - sort of, better - ???

#!/usr/bin/perl use strict; # https://perlmonks.org/?node_id=11135746 use warnings; use Data::Dump 'dd'; local $_ = 'text <one 1> three <two 2> four <five 5> K <six 6> lastwor +d'; for my $len ( 30 .. length ) { my $text = s/^.{0,$len}\b\K.*//sr =~ s/<[^<>]*\z//sr . '...'; dd $text; }

Outputs:

"text <one 1> three <two 2> ..." "text <one 1> three <two 2> four..." "text <one 1> three <two 2> four..." "text <one 1> three <two 2> four ..." "text <one 1> three <two 2> four ..." "text <one 1> three <two 2> four ..." "text <one 1> three <two 2> four ..." "text <one 1> three <two 2> four ..." "text <one 1> three <two 2> four ..." "text <one 1> three <two 2> four ..." "text <one 1> three <two 2> four ..." "text <one 1> three <two 2> four <five 5> ..." "text <one 1> three <two 2> four <five 5> K..." "text <one 1> three <two 2> four <five 5> K..." "text <one 1> three <two 2> four <five 5> K ..." "text <one 1> three <two 2> four <five 5> K ..." "text <one 1> three <two 2> four <five 5> K ..." "text <one 1> three <two 2> four <five 5> K ..." "text <one 1> three <two 2> four <five 5> K ..." "text <one 1> three <two 2> four <five 5> K ..." "text <one 1> three <two 2> four <five 5> K ..." "text <one 1> three <two 2> four <five 5> K <six 6> ..." "text <one 1> three <two 2> four <five 5> K <six 6> ..." "text <one 1> three <two 2> four <five 5> K <six 6> ..." "text <one 1> three <two 2> four <five 5> K <six 6> ..." "text <one 1> three <two 2> four <five 5> K <six 6> ..." "text <one 1> three <two 2> four <five 5> K <six 6> ..." "text <one 1> three <two 2> four <five 5> K <six 6> ..." "text <one 1> three <two 2> four <five 5> K <six 6> ..." "text <one 1> three <two 2> four <five 5> K <six 6> lastword..."

Replies are listed 'Best First'.
Re^2: Creating an abstract
by Bod (Parson) on Aug 09, 2021 at 21:58 UTC

    It's certainly more succinct and it behaves slightly differently. Your version includes the tag if it is to be split whereas mine removes it - this makes no difference to my application. It's taken me a little while to work out how the regexp works and I very much doubt I could write it for myself tomorrow...so probably not easily maintainable by me.

    But certainly succinct and rather impressive :)

      Nope, mine removes the last tag if it's not closed.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11135749]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others examining the Monastery: (7)
As of 2024-03-29 13:19 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found