28 but it works.

# 1 2 #1234567890123456789012345678 map/(^\s*[^:]*[^:\s])/,@list

Specifically, remove blank lines, and truncate each line at the first : (if present) and get rid of trailing whitespace after the xxxxx part (including the possible "\n".

Of all the solutions that were submitted, only this one and blokhead's (36) took into account that the 'xxxxxx' portion might itself contain whitespace. (Well, to be fair, busunsl's did too, but it didn't properly remove newlines. Update: So did Arien's as he kindly pointed out to me but his breaks by being too liberal in what it accepts/returns.)

This is what I used to test:

#!/usr/bin/perl -w use strict; my @T = ( '1 :yyyyy blah blah', '2 : yyyyy blah blah', '3 : ', '4 :', '5:yyyyy blah blah', '6: yyyyy blah blah', '7: ', '8:', ' : yyyyy blah blah', ' :yyyyy blah blah', ': yyyyy blah blah', ':yyyyy blah blah', '9 yyyyy blah blah', '10 yyyyy blah blah', '11 ', '12', ' : ', ' :', ': ', ':', ' ', '', '13 andmore:', '14 andmore : blah', ' 15 : foo', ' 16 andmore : foo', ); @T = map {($_,$_."\n")} @T; sub by { print "--- By @_ -------------\n"; } my @list; # 1 2 + 3 # 123456789012345678901234567 +8901234567 @list=@T;by 'sauoq'; print "($_)\n" for map/(^\s*[^:]*[^:\s])/,@lis +t; @list=@T;by 'blokhead'; print "($_)\n" for map{/([^:]*?)\s*(:|$)/;$1|| +()}@list; # Broken @list=@T;by 'busuns1'; print "($_)\n" for map{s/\s*(:.*|$)//;$_||()}@ +list; @list=@T;by 'Arien'; print "($_)\n" for map/(.+?)\s*(?>:|$)/,@list; @list=@T;by 'Arien'; print "($_)\n" for map/(.+?)\b\s*(?>:|$)/,@lis +t; @list=@T;by 'Aristotle';print "($_)\n" for map/^([^:\s]+)/,@list; @list=@T;by 'Aristotle';print "($_)\n" for map/^\s*([^:\s]+)/,@list; @list=@T;by 'blokhead'; print "($_)\n" for map{/([^:]*?)(\s*\n|\s*:)/& +&$1}@list; @list=@T;by 'blokhead'; print "($_)\n" for map{/([^:]*?)\s*(\n|:)/&&$1 +}@list; @list=@T;by 'jmcnmara'; print "($_)\n" for map{(split)[0]}@list; @list=@T;by 'CountZero';print "($_)\n" for map/(.*?)\s+:/,@list;

This is the output:

--- By sauoq ------------- (1) (1) (2) (2) (3) (3) (4) (4) (5) (5) (6) (6) (7) (7) (8) (8) (9 yyyyy blah blah) (9 yyyyy blah blah) (10 yyyyy blah blah) (10 yyyyy blah blah) (11) (11) (12) (12) (13 andmore) (13 andmore) (14 andmore) (14 andmore) ( 15) ( 15) ( 16 andmore) ( 16 andmore) --- By blokhead ------------- (1) (1) (2) (2) (3) (3) (4) (4) (5) (5) (6) (6) (7) (7) (8) (8) (9 yyyyy blah blah) (9 yyyyy blah blah) (10 yyyyy blah blah) (10 yyyyy blah blah) (11) (11) (12) (12) (13 andmore) (13 andmore) (14 andmore) (14 andmore) ( 15) ( 15) ( 16 andmore) ( 16 andmore) --- By busuns1 ------------- (1) (1 ) (2) (2 ) (3) (3 ) (4) (4 ) (5) (5 ) (6) (6 ) (7) (7 ) (8) (8 ) ( ) ( ) ( ) ( ) (9 yyyyy blah blah) (9 yyyyy blah blah) (10 yyyyy blah blah) (10 yyyyy blah blah) (11) (11) (12) (12) ( ) ( ) ( ) ( ) (13 andmore) (13 andmore ) (14 andmore) (14 andmore ) ( 15) ( 15 ) ( 16 andmore) ( 16 andmore ) --- By Arien ------------- (1) (1) (2) (2) (3) (3) (4) (4) (5) (5) (6) (6) (7) (7) (8) (8) ( ) ( ) ( ) ( ) (: yyyyy blah blah) (: yyyyy blah blah) (:yyyyy blah blah) (:yyyyy blah blah) (9 yyyyy blah blah) (9 yyyyy blah blah) (10 yyyyy blah blah) (10 yyyyy blah blah) (11) (11) (12) (12) ( ) ( ) ( ) ( ) (:) (:) (:) (:) ( ) ( ) (13 andmore) (13 andmore) (14 andmore) (14 andmore) ( 15) ( 15) ( 16 andmore) ( 16 andmore) --- By Arien ------------- (1) (1) (2) (2) (3) (3) (4) (4) (5) (5) (6) (6) (7) (7) (8) (8) ( : yyyyy blah blah) ( : yyyyy blah blah) ( :yyyyy blah blah) ( :yyyyy blah blah) (: yyyyy blah blah) (: yyyyy blah blah) (:yyyyy blah blah) (:yyyyy blah blah) (9 yyyyy blah blah) (9 yyyyy blah blah) (10 yyyyy blah blah) (10 yyyyy blah blah) (11) (11) (12) (12) (13 andmore) (13 andmore) (14 andmore) (14 andmore) ( 15) ( 15) ( 16 andmore) ( 16 andmore) --- By Aristotle ------------- (1) (1) (2) (2) (3) (3) (4) (4) (5) (5) (6) (6) (7) (7) (8) (8) (9) (9) (10) (10) (11) (11) (12) (12) (13) (13) (14) (14) --- By Aristotle ------------- (1) (1) (2) (2) (3) (3) (4) (4) (5) (5) (6) (6) (7) (7) (8) (8) (9) (9) (10) (10) (11) (11) (12) (12) (13) (13) (14) (14) (15) (15) (16) (16) --- By blokhead ------------- (1) (1) (2) (2) (3) (3) (4) (4) (5) (5) (6) (6) (7) (7) (8) (8) () () () () () () () () () (9 yyyyy blah blah) () (10 yyyyy blah blah) () (11) () (12) () () () () () () () () () () () () (13 andmore) (13 andmore) (14 andmore) (14 andmore) ( 15) ( 15) ( 16 andmore) ( 16 andmore) --- By blokhead ------------- (1) (1) (2) (2) (3) (3) (4) (4) (5) (5) (6) (6) (7) (7) (8) (8) () () () () () () () () () (9 yyyyy blah blah) () (10 yyyyy blah blah) () (11) () (12) () () () () () () () () () () () () (13 andmore) (13 andmore) (14 andmore) (14 andmore) ( 15) ( 15) ( 16 andmore) ( 16 andmore) --- By jmcnmara ------------- (1) (1) (2) (2) (3) (3) (4) (4) (5:yyyyy) (5:yyyyy) (6:) (6:) (7:) (7:) (8:) (8:) (:) (:) (:yyyyy) (:yyyyy) (:) (:) (:yyyyy) (:yyyyy) (9) (9) (10) (10) (11) (11) (12) (12) (:) (:) (:) (:) (:) (:) (:) (:) (13) (13) (14) (14) (15) (15) (16) (16) --- By CountZero ------------- (1) (1) (2) (2) (3) (3) (4) (4) () () () () () () () () (14 andmore) (14 andmore) ( 15) ( 15) ( 16 andmore) ( 16 andmore)
-sauoq
"My two cents aren't worth a dime.";

In reply to Re: golf anyone? (taking first field) by sauoq
in thread golf anyone? (taking first field) by John M. Dlugosz

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.