Hi Bryan,

On Sun, 08 Apr 2012 00:08:48 -0500
Bryan Harris <bryansli...@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 .

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to