Front page | perl.beginners |
Postings from April 2012
Re: stacked processing
Thread Previous
From:
Shlomi Fish
Date:
April 9, 2012 03:25
Subject:
Re: stacked processing
Message ID:
20120409132537.5bb0f2d1@lap.shlomifish.org
Hi Bryan,
On Sun, 08 Apr 2012 00:08:48 -0500
Bryan Harris <bryanslists@gmail.com> wrote:
>
>
> Hello there!
>
> I love perl's ability to "stack" processing without intermediate variables,
> e.g. to read in a pipe, strip off commented lines, pull out column 5, and
> join, I can just do this:
>
> $txt = join "", map { (split)[4] } grep { !/^#/ } <>;
>
> What I haven't figured out is how to do a substitution in there, e.g. to
> delete any leading blank lines out of the final string, but leave in others.
> I'd love to be able to do this:
>
> $txt = s/\A\n+// join "", map { (split)[4] } grep { !/^#/ } <>;
>
If you're on perl-5.14.0 and above you can do:
$txt = +(join "", map { (split)[4] } grep { !/^#/ } <>) =~ s/\A\n+//r;
The /r makes sure to return the modified value.
Else you can do:
($txt = join "", map { (split)[4] } grep { !/^#/ } <>) =~ s/\A\n+//;
BTW, your use of \A makes me happy.
Regards,
Shlomi Fish
--
-----------------------------------------------------------------
Shlomi Fish http://www.shlomifish.org/
The Case for File Swapping - http://shlom.in/file-swap
We have nothing to fear but fear itself. Fear has nothing to fear but XSLT.
Please reply to list if it's a mailing list post - http://shlom.in/reply .
Thread Previous