the incredible missing reply-to field strikes again... On 3/21/06, Jay Savage <[EMAIL PROTECTED]> wrote: > On 3/21/06, Timothy Johnson <[EMAIL PROTECTED]> wrote: > > > > > >-----Original Message----- > > >From: Mr. Shawn H. Corey [mailto:[EMAIL PROTECTED] > > >Sent: Tuesday, March 21, 2006 1:36 PM > > >To: beginners perl > > >Subject: Re: regex one liner > > > > > >Timothy Johnson wrote: > > >> We run into one of these "How do I do this in a one-liner?" questions > > >> pretty frequently, and I for one have to ask, what exactly makes the > > >> one-liner so compelling, especially when you are using it for > > something > > >> that will be run repeatedly? > > > > > >Because you can use them in aliases: > > > > > > alias pcalc='perl -ple '\''BEGIN{use Data::Dumper}$_=eval'\''' > > > > > >See `man alias` for details. > > > > And you can't do this? > > > > alias pcalc='perl ~/pcalc.pl' > > > > > > And as for the issue of slightly varying regexes as arguments to a > > script (different email), it may seem easier to you, but not necessarily > > to the next guy that comes along. Obviously you aren't required to take > > other people into account when designing your scripts, but I always try > > to. By simply moving the part that always changes to an argument you > > give yourself the same flexibility and ability to use the history while > > at the same time leaving a trail in case you get hit by a truck and > > someone else needs to step into your shoes temporarily. And you never > > know; the person who needs to figure out what you did may end up being > > you. > > > > Obviously I'm not saying that it's wrong to do it, but IMHO it's worth > > the small bit of extra time up front, and Perl gives you all the tools > > needed to meet your requirements without having to cram it all into one > > line. > > You're making some assumptions here that may not be valid. It's not > always woth my time--or anyone else's--to sit down and write a tool to > accomplish a relatively simple task, especially if it's a task that > needs to be performed a finite number of times. Or for that matter, a > task that needs to be performed an infinite number of times with > infinite variations. No one is talking about "scripts". At least I'm > not. Nothing that needs to be maintained. Nothing, for the most part, > that another human being is ever going to see. The stuff that we all > kepp hidden away in our .profiles and heads. The basic stuff that > makes a sysadmin or advanced user's day possible. > > Coworker needs a few columns out of a tab file and doesn't know what > he's doing? Fine, let me see it. > > %perl -lanF/\t/ -e 'print join("\t", @F[2,3,4,5,6,7,12,67])' file > > newfile > > I think that's what most people are talking about when the talk about > oneliners. > > > Something like the script below, for instance, is pretty pointless: > > #!/usr/bin/perl > use warnings; > use strict; > > my $bak = $ARGV[2] . ".bak"; > > open (FILE1, "<", $ARGV[2]) or die "$!\n"; > open (FILE2, ">", $bak) or die "$!\n"; > while (<FILE1>) { > chomp; > s/$ARGV[0]/$ARGV/g > print FILE2 "$_\n"; > } > close (FILE1); > close (FILE2); > rename $bak, $ARGV[2] or die "$!\n"; > unlink $ARGV[2] or die "$!\n"; > > That's 17 lines and at the end of the day you still have to type > > %perl scriptname argv1 argv2 filename > > Why not just use a oneliner to begin with: > > %perl -lpi -e's/argv1/argv2/' filename > > As far as I'm concerned, thats what the command line switches are > there for. I look at it this way: if it's something I'd write a shell > script for, I'll probably write a Perl script and save it to a file. > If it's something I'd do on the cammand line with another tool, I'll > probably do it on the command line with Perl. > > It's partly a matter of translation, too. If I'm turning to perl to > clean up some variation on > > %sed -e 's/something/something/g' -e'something else' -e'something else' > file > > the Perl replacement will probably end up being one line, too. > > -- jay > -------------------------------------------------- > This email and attachment(s): [ ] blogable; [ x ] ask first; [ ] > private and confidential > > daggerquill [at] gmail [dot] com > http://www.tuaw.com http://www.dpguru.com http://www.engatiki.org > > values of β will give rise to dom! >
-- -------------------------------------------------- This email and attachment(s): [ ] blogable; [ x ] ask first; [ ] private and confidential daggerquill [at] gmail [dot] com http://www.tuaw.com http://www.dpguru.com http://www.engatiki.org values of β will give rise to dom!