in reply to Shorten this one-liner!
For case insensitivity replace /a/ with /a/i and y/e/.. with y/eE/.. in the following examples.
For a start, I tried this
but am failing to call tr (aka y) in scalar context.c:\Perl_524>perl -anE"/a/&&say$_,' :'.y/$_/e/for@F" anyone cnacel declare perlmonks anyone :0 cnacel :0 declare :0
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
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
even less under linux
~$ perl -anE'/a/&&say"$_ :".y/e//for@F' anyone cancel declare perlmonks anyone :1 cancel :1 declare :2
$ perl -E'/a/&&say"$_ :".y/e//for qw/anyone cancel declare perlmonks/' anyone :1 cancel :1 declare :2
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: Shorten this one-liner!
by lunix (Novice) on Aug 26, 2018 at 10:03 UTC |