[sf-perl] double filter (but short)
Michael Friedman
friedman at highwire.stanford.edu
Tue Jul 1 10:33:05 PDT 2008
Oops. I always get caught on the return value of s/// and of chomp,
for some reason. I also noticed I forgot to remove the shell escaping
of parens.
Thanks for the better way!
-- Mike
On Jul 1, 2008, at 9:08 AM, Randal L. Schwartz wrote:
>> "Michael" == Michael Friedman <friedman at highwire.stanford.edu>
>> writes:
>>
> Michael> I haven't tried this, but something like:
> Michael> print reverse( map {s/^\([^:]*\):/_$1_:/} <> );
>
> That's going to print the result of the s///, which will be a
> success/fail
> boolean. I also consider it bad form to modify $_ within the map
> block,
> because sometimes it fails (read only), and is at least misleading.
>
> I'd go with something like this:
>
> print reverse map { /(.*):(.*)/ or die; "_$1_:$2\n" } <>;
>
> --
> Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503
> 777 0095
> <merlyn at stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
> Smalltalk/Perl/Unix consulting, Technical writing, Comedy, etc. etc.
> See http://methodsandmessages.vox.com/ for Smalltalk and Seaside
> discussion
---------------------------------------------------------------------
Michael Friedman HighWire Press
Phone: 650-725-1974 Stanford University
FAX: 270-721-8034 <friedman at highwire.stanford.edu>
---------------------------------------------------------------------
More information about the SanFrancisco-pm
mailing list