Update: Code shown is based on the last one-liner of the OP which was case sensitive.

For case insensitivity replace /a/ with /a/i and y/e/.. with y/eE/.. in the following examples.


For a start, I tried this

c:\Perl_524>perl -anE"/a/&&say$_,' :'.y/$_/e/for@F" anyone cnacel declare perlmonks anyone :0 cnacel :0 declare :0
but am failing to call tr (aka y) in scalar context.

update
I misread the docs for tr, is this good enough?
c:\Perl_524>perl -anE"/a/&&say$_.' :'.y/e/e/for@F" anyone cancel declare perlmonks anyone :1 cancel :1 declare :2

note: you have to enter more lines or kill the one liner with C-c

update

one char less!

c:\Perl_524>perl -anE"/a/&&say$_.' :'.y/e//for@F" anyone cancel declare perlmonks anyone :1 cancel :1 declare :2

explanation: this is equivalent

use feature 'say'; while (<>) { @F = split(' '); /a/ and say $_ . ' :' . tr/e// foreach (@F); }

see also perlrun for -a, -n and -E

(though it claims "-a implicitly sets -n" which I can't reproduce)

Cheers Rolf
(addicted to the Perl Programming Language :)
Wikisyntax for the Monastery FootballPerl is like chess, only without the dice

update

even less under linux

~$ perl -anE'/a/&&say"$_ :".y/e//for@F' anyone cancel declare perlmonks anyone :1 cancel :1 declare :2

update
last but not least without reading from STDIN (which doesn't make much sense for a one-liner)

$ perl -E'/a/&&say"$_ :".y/e//for qw/anyone cancel declare perlmonks/' anyone :1 cancel :1 declare :2

In reply to Re: Shorten this one-liner! by LanX
in thread Shorten this one-liner! by lunix

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.