[tpm] find, manipulate, then output
Antonio Sun
antoniosun at lavabit.com
Mon May 28 09:09:56 PDT 2012
On Mon, May 28, 2012 at 11:51 AM, Peter Vereshagin <peter at vereshagin.org>wrote:
> AS> >> perl -ne 'print $2 . ", ". $1. "\n" while(/.../)'
> AS> >>
> AS> >> But I really can't work out the rest now.
> AS> >> Please help.
>
> Sure.
>
> perl -Mstrict -wE 'my ( $blob, $fname, $lname ) = map {""} 0 .. 2; while (
> my $str = <> ) { $blob .= $str; if ( $blob =~
> m/<(first|last)-name[^>]*>([^>]*)</ ) { my ( $kind => $name ) = ( $1 => $2
> ); $name =~ s/^\s+|\s+$//g; if ( $kind eq "first" ) { $fname = $name; }
> else { $lname = $name; } $blob = ""; } if ( $fname and $lname ) { print
> "$lname, $fname\n"; ( $fname => $lname ) = map {""} 0 .. 1; } }'
>
Thank you Peter for your reply.
I think the reason that your script is far more complicated than what I
thought is because that you are handling one line at a time. I believe that
if we to slurp the whole file in and have '.' match new lines as well, it
can be greatly simplified.
Again, I don't have my "perl notes" at hands, so I can't prove it now.
Thanks anyway.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.pm.org/pipermail/toronto-pm/attachments/20120528/68684b1c/attachment-0001.html>
More information about the toronto-pm
mailing list