Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Re: Creating an abstract

by tybalt89 (Prior)
on Aug 09, 2021 at 21:38 UTC ( #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 (Curate) 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? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (6)
As of 2022-05-24 12:35 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Do you prefer to work remotely?



    Results (82 votes). Check out past polls.

    Notices?