RE: regex one liner




-----Original Message-----
From: Mr. Shawn H. Corey [mailto:shawnhcorey@xxxxxxxx]
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.

That being said, if I have the time and anyone has a question, I'll be
happy to try to help. I don't want to discourage anyone from expanding
their knowledge.


.



Relevant Pages

  • Re: regex one liner
    ... We run into one of these "How do I do this in a one-liner?" ... Perl script and run it from the command-line. ... well just type out the command. ... The only drawback to oneliners (for things that can legitimately be ...
    (perl.beginners)
  • Re: Bash scripting problems
    ... I even created a new script with these two caommands and get the same ... alias rm='rm -i' ... # echo all aliases set ...
    (Fedora)
  • Re: oddity regarding execution
    ... and fired off a test message. ... > Well, when the alias fed the message to it, it barked. ... I modified the script to ... And is there anything I can do so the cwd will be the dir the ...
    (freebsd-questions)
  • Re: [opensuse] alias failure
    ... So it's just an accident that the following aliases all work as I want/expect? ... alias ll='ls -l $*' ... I made a script with nothing but that in it, ... the shell procedure. ...
    (SuSE)
  • Re: Using alias within a bash script
    ... > script. ... > My particular command that i want to alias is echo. ... shopt -s expand_aliases ...
    (comp.unix.shell)