SPUG: perl one-liner help

Michael R. Wolf MichaelRWolf at att.net
Wed Apr 4 18:51:10 PDT 2007


Forgive my eyes...  

...and but for a 'y' (why, because we love you?), it's profanity (M-o-u-s-e)
...but for an 'o' (Vanna, may I buy a vowel?), that looks profane....

What kind of Mickey Mouse programming is this, any way?

>   perl -F/;\s*/ -ane "print $_,$/ for @F" desktop/list.txt
    ^ ^   ^        ^^^
    p r . f        ane
    p r . f        an     i t

It does have a certain slant ('/') to it!!!

Giggles,
Michael

P.S.  Having just finished teaching a Perl class 2 hours ago, perhaps I'm
seeing this code through beginners' eyes, and wanting to protect them from
the TMTOWTDI-ity of it all.  Who knew I'd agree with Tim (There's one good
way to do it) by disagreeing with one of the awk-ish ways to use Perl?  Go
figure.

P.P.S.  In case it's not clear, I like TMTOWTDI, and the alternatives
proffered.

-- 
Michael R. Wolf
    All mammals learn by playing!
        MichaelRWolf at att.net

> -----Original Message-----
> From: spug-list-bounces+michaelrwolf=att.net at pm.org [mailto:spug-list-
> bounces+michaelrwolf=att.net at pm.org] On Behalf Of jerry gay
> Sent: Wednesday, April 04, 2007 3:20 PM
> To: Chris Wilkes
> Cc: spug-list at pm.org
> Subject: Re: SPUG: perl one-liner help
> 
> On 4/4/07, Chris Wilkes <cwilkes-spug at ladro.com> wrote:
> > On Wed, Apr 04, 2007 at 03:08:47PM -0700, Duane Blanchard wrote:
> > >
> > > I have a list of names in a file separated by a semicolon and a space:
> > >
> > > Starr, Ringo; McCartney, Paul; Lennon, John; Harrison, George;
> > >
> > > and I want to substitute each /; / with a /\n/.
> > >
> > > I'm running WinXP.
> > >
> > > perl -e "s/; /\n/" desktop/list.txt
> >
> > You're close:
> >   perldoc perlrun
> > shows that you're looking for the -p switch:
> >
> >   perl -pe "s/; /\n/g" desktop/list.txt
> >
> > throw in a "/g" in your regexp to say that you want to repeat the
> > match on the same line.
> >
> ain't perl fun?v
>   perl -F/;\s*/ -ane "print $_,$/ for @F" desktop/list.txt
> _____________________________________________________________
> Seattle Perl Users Group Mailing List
>      POST TO: spug-list at pm.org
> SUBSCRIPTION: http://mail.pm.org/mailman/listinfo/spug-list
>     MEETINGS: 3rd Tuesdays
>     WEB PAGE: http://seattleperl.org/



More information about the spug-list mailing list