FAQ
I would like to modify a file 'in place' at the command line with regexes. The file changes daily and is messy. Can one negate a regex itself as opposed to a class of regular expressions? If I could remove everything but that selected by m/\d{2}\t\d{2}\t\d{2}/g life would be better as I know it. Thanx

--
_______________________________________________

Search for businesses by name, location, or phone number. -Lycos Yellow Pages

http://r.lycos.com/r/yp_emailfooter/http://yellowpages.lycos.com/default.asp?SRC=lycos10

Search Discussions

  • Timothy Johnson at Mar 21, 2006 at 12:57 am
    What have you tried? Have you seen the -i option?

    -----Original Message-----
    From: stu meacham
    Sent: Monday, March 20, 2006 2:33 PM
    To: beginners@perl.org
    Subject: regex one liner

    I would like to modify a file 'in place' at the command line with
    regexes. The file changes daily and is messy. Can one negate a regex
    itself as opposed to a class of regular expressions? If I could remove
    everything but that selected by m/\d{2}\t\d{2}\t\d{2}/g life would be
    better as I know it. Thanx

    --
    _______________________________________________

    Search for businesses by name, location, or phone number. -Lycos Yellow
    Pages

    http://r.lycos.com/r/yp_emailfooter/http://yellowpages.lycos.com/default
    .asp?SRC=lycos10


    --
    To unsubscribe, e-mail: beginners-unsubscribe@perl.org
    For additional commands, e-mail: beginners-help@perl.org
    <http://learn.perl.org/> <http://learn.perl.org/first-response>
  • Stu meacham at Mar 21, 2006 at 1:16 am

    perl -i -p -e 's/^(\d{2}\t\d{2}\t\d{2})/g' This was the 1st thing that I tried; it doesn't work. It was initially easy but different things kept appearing that forced me to use > 1
    statements on the command line. Negating what I want seems like it ought to be simple.

    What have you tried? Have you seen the -i option?

    -----Original Message-----


    I would like to modify a file 'in place' at the command line with
    regexes. The file changes daily and is messy. Can one negate a regex
    itself as opposed to a class of regular expressions? If I could remove
    everything but that selected by m/\d{2}\t\d{2}\t\d{2}/g life would be
    better as I know it. Thanx

    --
    _______________________________________________

    Search for businesses by name, location, or phone number. -Lycos Yellow
    Pages

    http://r.lycos.com/r/yp_emailfooter/http://yellowpages.lycos.com/default
    .asp?SRC=lycos10


    --
    To unsubscribe, e-mail: beginners-unsubscribe@perl.org
    For additional commands, e-mail: beginners-help@perl.org
    <http://learn.perl.org/> <http://learn.perl.org/first-response>
    >


    --
    _______________________________________________

    Search for businesses by name, location, or phone number. -Lycos Yellow Pages

    http://r.lycos.com/r/yp_emailfooter/http://yellowpages.lycos.com/default.asp?SRC=lycos10
  • Jay Savage at Mar 21, 2006 at 2:27 pm

    On 3/20/06, stu meacham wrote:
    perl -i -p -e 's/^(\d{2}\t\d{2}\t\d{2})/g' This was the 1st thing that I tried; it doesn't work. It was initially easy but different things kept appearing that forced me to use > 1
    statements on the command line. Negating what I want seems like it ought to be simple.
    There are a couple of things here:

    1) s/// requires a string to replace the match with. you haven't
    supplied one. This should produce a syntax error.

    2) You've anchored your patttern at the beginning of the string. This
    makes /g a no-op; you're pattern can't possibly match more than once,
    because '^' can only appear once.

    3) s/// replaces whatever is matched on the left side with whatever
    you put on the right side, and leaves the rest of the string
    untouched. You need to specify what you don't want, as well.

    If you know that your will always have a single occurance at the
    beginning of the line, use something like:

    s/^(\d\d\t\d\d\t\d\d).*/$1/

    I think we're about at the end of how much we can help based on what
    you've given us. Show us a couple of the complete command lines you've
    tried (so we can see what your ultimate goal is) and some sample data.

    -- 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!
  • Chad Perrin at Mar 21, 2006 at 11:32 pm

    On Tue, Mar 21, 2006 at 09:27:28AM -0500, Jay Savage wrote:
    On 3/20/06, stu meacham wrote:

    perl -i -p -e 's/^(\d{2}\t\d{2}\t\d{2})/g' This was the 1st thing that I tried; it doesn't work. It was initially easy but different things kept appearing that forced me to use > 1
    statements on the command line. Negating what I want seems like it ought to be simple.
    2) You've anchored your patttern at the beginning of the string. This
    makes /g a no-op; you're pattern can't possibly match more than once,
    because '^' can only appear once.
    I think that was in large part my fault. I sent an email with a
    proposed solution while I was half-asleep, and ended up making two
    errors:

    1. I accidentally sent it to the individual rather than the list.

    2. I screwed up the regex pretty badly.

    If I'd been fully conscious and thinking clearly, what I would have sent
    would have been something like this:

    $foo !~ s/\d{2}\t\d{2}\t\d{2}//g

    (where $foo is what you want to modify)

    I just saw the initial regex example and thought "negation", then
    misused the carat. Mea culpa, Jay. I didn't mean to lead you astray.

    --
    Chad Perrin [ CCD CopyWrite | http://ccd.apotheon.org ]
    "The measure on a man's real character is what he would do
    if he knew he would never be found out." - Thomas McCauley
  • Chad Perrin at Mar 21, 2006 at 11:34 pm

    On Tue, Mar 21, 2006 at 04:32:21PM -0700, Chad Perrin wrote:

    misused the carat. Mea culpa, Jay. I didn't mean to lead you astray.
    . . . and here I go with the stupid mistakes again. I meant Stu, not
    Jay.

    --
    Chad Perrin [ CCD CopyWrite | http://ccd.apotheon.org ]
    "Real ugliness is not harsh-looking syntax, but having to
    build programs out of the wrong concepts." - Paul Graham
  • Jay Savage at Mar 21, 2006 at 1:46 am

    On 3/20/06, stu meacham wrote:
    I would like to modify a file 'in place' at the command line with regexes. The file changes daily and is messy. Can one negate a regex itself as opposed to a class of regular expressions? If I could remove everything but that selected by m/\d{2}\t\d{2}\t\d{2}/g life would be better as I know it. Thanx

    --
    Stu,

    The short answer is "not really," but it depends on your data, and
    what, exactly, you want to do. Do you want to remove lines that don't
    match? Do you want to delete just the parts of the line that don't
    match? Is your data delimited in some way and you want to remove all
    fields but one? There are several (at least) ways to approach this,
    depending on the situation. Here are some thoughts to get you
    started, though:

    in list context, m// returns an array of capturing paren matches, so
    something like:

    @matched = /(\d{2}\t\d{2}\t\d{2})/g; print "@matched\n";

    might work for you. You could also try something like:

    s/.*?(\d{2}\t\d{2}\t\d{2}).*?(?!\d{2}\t\d{2}\t\d{2})/$1/g

    look for (?!) and "zero-width negative lookahead" in perlre. And of
    course if your data can be conveniently split into fileds, check out
    the -a flag in perlrun and grep() in perlfunc.

    HTH,

    -- 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!
  • Stu meacham at Mar 21, 2006 at 4:22 pm
    I tried one final time with non-capturing parentheses i.e. (?: to no avail.
    This works just fine however:

    perl -i -p -e '@matches = m/\d{2}\t\d{2}\t\d{2}/g; s/.*//g; print"@matches\n"'

    Retrieve, delete what's left, and rewrite what's to be kept. It should now
    work everytime all the time. Crude but effective. My (result)/(time spent)
    ratio would have been lower without your help. I stumbled over the ; inside
    of the ''s for one.
    Thanks very much.

    Stu
    perl -i -p -e 's/^(\d{2}\t\d{2}\t\d{2})/g' This was the 1st
    thing that I tried; it doesn't work. It was initially easy but
    different things kept appearing that forced me to use > 1
    statements on the command line. Negating what I want seems like
    it ought to be simple.
    There are a couple of things here:

    1) s/// requires a string to replace the match with. you haven't
    supplied one. This should produce a syntax error.

    2) You've anchored your patttern at the beginning of the string. This
    makes /g a no-op; you're pattern can't possibly match more than once,
    because '^' can only appear once.

    3) s/// replaces whatever is matched on the left side with whatever
    you put on the right side, and leaves the rest of the string
    untouched. You need to specify what you don't want, as well.

    If you know that your will always have a single occurance at the
    beginning of the line, use something like:

    s/^(\d\d\t\d\d\t\d\d).*/$1/

    I think we're about at the end of how much we can help based on what
    you've given us. Show us a couple of the complete command lines you've
    tried (so we can see what your ultimate goal is) and some sample data.

    -- jay
    --
    _______________________________________________

    Search for businesses by name, location, or phone number. -Lycos Yellow Pages

    http://r.lycos.com/r/yp_emailfooter/http://yellowpages.lycos.com/default.asp?SRC=lycos10
  • Timothy Johnson at Mar 21, 2006 at 6:56 pm
    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?

    IMHO it would have been much more practical to just create a three line
    Perl script and run it from the command-line. It makes it easier to
    read, doesn't discourage commenting, and avoids the contortions
    sometimes needed to cram it all into one line.



    -----Original Message-----
    From: stu meacham
    Sent: Tuesday, March 21, 2006 8:25 AM
    To: Jay Savage; beginners perl
    Subject: Re: regex one liner

    I tried one final time with non-capturing parentheses i.e. (?: to no
    avail.
    This works just fine however:

    perl -i -p -e '@matches = m/\d{2}\t\d{2}\t\d{2}/g; s/.*//g;
    print"@matches\n"'

    Retrieve, delete what's left, and rewrite what's to be kept. It should
    now
    work everytime all the time. Crude but effective. My (result)/(time
    spent)
    ratio would have been lower without your help. I stumbled over the ;
    inside
    of the ''s for one.
    Thanks very much.

    <snip>
  • Jay Savage at Mar 21, 2006 at 9:30 pm

    On 3/21/06, 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?

    IMHO it would have been much more practical to just create a three line
    Perl script and run it from the command-line. It makes it easier to
    read, doesn't discourage commenting, and avoids the contortions
    sometimes needed to cram it all into one line.
    I can only speak for myself here, but there are a couple of things
    that make one-liners appealing. By and large, they're the same things
    that drive a decision to use sed over awk, although these days I
    pretty much use perl for everything except maintaining bits of old
    code.

    1) Quantity. If you're doing this sort of thing, you're probably doing
    it a lot. And you're probably searching the same file many times for
    slightly different information. Or you're searching a number of
    oh-so-subtly different log files for the same information. Having 400
    different scripts that all do essentially the same thing with
    different regexes doesn't make sense. writing a general purpose tolls
    that will except the regex on the command line doesn't make a lot of
    sense, either: if you're going to type the regex anyway, you might as
    well just type out the command.

    2) Clutter. given the choice, for simple tasks, I'll choose to clutter
    up my brain, rather than ~/bin. Not to mention that i may want to run
    the script as several different users, depending on the situation, and
    I certainly don't want all my personal scripts laying around in
    /usr/bin.

    3) Sanity. What do you name all your former oneliners?
    ApacheLogReportOne, ApacheLogReportForBossThisWeeksParams03102006?
    That gets old, not to mention headache-inducing, in a hurry.

    4) Platform. Most cases where you'd want a oneliner aren't work
    working up a truly robust script that looks at %ENV to figure out what
    system I'm on, etc., and how to deal with the quirks in the different
    log files, etc.

    5) Laziness (in the good sense). I have to type a command line anyway.
    If it would only take a line or two of code (make it three with the
    bang path), and I'm still going to have to type a line to start it up,
    it's probably not worth my while to write a script, especially since I
    then have to deal with the input, etc. Let perl deal with $^I, <>, and
    maybe even print and split for me. How many lines of code would it
    take to emulate "perl -lpi -e's/^.*(match).*$/$1/replaces at least 5
    lines of code right off the bat. the -l switch is particularly sneaky.

    6) Testing. If you're testing a regex and are making incremental
    changes, things go a lot faster. I figure I save somewhere int he
    neighborhood of 60% of my keystrokes when I can do something small
    right on the command line, instead of constantly launching shells in
    emacs, or going through the constant "[run], fg, [edit], ^X^S, ^Z,
    [up][up], [run]" cycle. At the command line, that turns into "ret.,
    [up], [edit], ret.".

    The only drawback to oneliners (for things that can legitimately be
    condensed to one line without qualifying for an obfuscation prize),
    then, is the difficulty remembering and formulating regexen. And why
    not get good at that?

    -- 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!
  • Mr. Shawn H. Corey at Mar 21, 2006 at 9:35 pm

    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.


    --

    Just my 0.00000002 million dollars worth,
    --- Shawn

    "For the things we have to learn before we can do them,
    we learn by doing them."
    Aristotle

    "The man who sets out to carry a cat by its tail learns something that
    will always be useful and which will never grow dim or doubtful."
    Mark Twain

    "Believe in the Divine, but paddle away from the rocks."
    Hindu Proverb

    * Perl tutorials at http://perlmonks.org/?node=Tutorials
    * A searchable perldoc is at http://perldoc.perl.org/
  • Stu meacham at Mar 21, 2006 at 8:55 pm
    Good question. I went to a script right away after the difficulty with the one-liner and returned to the command line syntax problem more out of curiosity than anything else. I'm a fan of the command line because once I get one that works all I need is the 'history' command and an up arrow key to retrieve it--one less file. You're right though, cleverness is overated.
    Stu
    --

    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?

    IMHO it would have been much more practical to just create a three line
    Perl script and run it from the command-line. It makes it easier to
    read, doesn't discourage commenting, and avoids the contortions
    sometimes needed to cram it all into one line.
    --
    _______________________________________________

    Search for businesses by name, location, or phone number. -Lycos Yellow Pages

    http://r.lycos.com/r/yp_emailfooter/http://yellowpages.lycos.com/default.asp?SRC=lycos10
  • Timothy Johnson at Mar 21, 2006 at 10:01 pm

    -----Original Message-----
    From: Mr. Shawn H. Corey
    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.
  • Mr. Shawn H. Corey at Mar 21, 2006 at 10:28 pm

    Timothy Johnson wrote:
    And you can't do this?

    alias pcalc='perl ~/pcalc.pl'
    No. With alias, I can create an alias file that works with sh (and ksh,
    bash) and csh (and tcsh). This would be dot'ed in your .profile as:

    . ~/.alias

    or source'd in your .cshrc as:

    source ~/.alias

    If you want the same as a script:

    mv ~/pcalc.pl ~/bin/pcalc

    BTW, out here in the real world (that would be UNIX), *.pl stands for
    Perl Library file, not a script.


    --

    Just my 0.00000002 million dollars worth,
    --- Shawn

    "For the things we have to learn before we can do them,
    we learn by doing them."
    Aristotle

    "The man who sets out to carry a cat by its tail learns something that
    will always be useful and which will never grow dim or doubtful."
    Mark Twain

    "Believe in the Divine, but paddle away from the rocks."
    Hindu Proverb

    * Perl tutorials at http://perlmonks.org/?node=Tutorials
    * A searchable perldoc is at http://perldoc.perl.org/
  • Kevin Viel at Mar 21, 2006 at 10:52 pm

    BTW, out here in the real world (that would be UNIX), *.pl stands for
    Perl Library file, not a script.

    What extension do you suggest using, if any, in the real world?

    Thanks,

    Kevin

    ----------------------------------------------------------------------
    Kevin Viel
    Department of Genetics e-mail: kviel@darwin.sfbr.org
    Southwest Foundation phone: (210)258-9884
    P.O. Box 760549 fax: (210)258-9444
    San Antonio, TX 78245-0549
  • Dave Gray at Mar 21, 2006 at 11:05 pm

    On 3/21/06, Kevin Viel wrote:
    BTW, out here in the real world (that would be UNIX), *.pl stands for
    Perl Library file, not a script.
    What extension do you suggest using, if any, in the real world?
    .ps for perl script

    /snicker
  • Chad Perrin at Mar 21, 2006 at 11:44 pm

    On Tue, Mar 21, 2006 at 04:05:17PM -0700, Dave Gray wrote:
    On 3/21/06, Kevin Viel wrote:
    BTW, out here in the real world (that would be UNIX), *.pl stands for
    Perl Library file, not a script.
    What extension do you suggest using, if any, in the real world?
    .ps for perl script
    Funny.

    Actually, I tend to either use no file extension or .plx as the file
    extension for a non-library script. I'm pretty sure ActivePerl
    recognizes .plx (not entirely sure, but pretty sure), though I generally
    do all my scripting on *nix, so it's not really an issue here.

    --
    Chad Perrin [ CCD CopyWrite | http://ccd.apotheon.org ]
    "The ability to quote is a serviceable
    substitute for wit." - W. Somerset Maugham
  • Mr. Shawn H. Corey at Mar 22, 2006 at 12:25 am

    Chad Perrin wrote:
    Actually, I tend to either use no file extension or .plx as the file
    extension for a non-library script. I'm pretty sure ActivePerl
    recognizes .plx (not entirely sure, but pretty sure), though I generally
    do all my scripting on *nix, so it's not really an issue here.
    In UNIX, you should use file(1) to determine what the file is.


    --

    Just my 0.00000002 million dollars worth,
    --- Shawn

    "For the things we have to learn before we can do them,
    we learn by doing them."
    Aristotle

    "The man who sets out to carry a cat by its tail learns something that
    will always be useful and which will never grow dim or doubtful."
    Mark Twain

    "Believe in the Divine, but paddle away from the rocks."
    Hindu Proverb

    * Perl tutorials at http://perlmonks.org/?node=Tutorials
    * A searchable perldoc is at http://perldoc.perl.org/
  • Jay Savage at Mar 21, 2006 at 11:06 pm
    the incredible missing reply-to field strikes again...
    On 3/21/06, Jay Savage wrote:
    On 3/21/06, Timothy Johnson wrote:

    -----Original Message-----
    From: Mr. Shawn H. Corey
    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!
  • Timothy Johnson at Mar 21, 2006 at 11:12 pm


    -----Original Message-----
    From: Mr. Shawn H. Corey
    Sent: Tuesday, March 21, 2006 2:29 PM
    To: beginners perl
    Subject: Re: regex one liner

    Timothy Johnson wrote:
    And you can't do this?

    alias pcalc='perl ~/pcalc.pl'
    No. With alias, I can create an alias file that works with sh (and ksh,
    bash) and csh (and tcsh). This would be dot'ed in your .profile as:

    . ~/.alias

    or source'd in your .cshrc as:

    source ~/.alias

    If you want the same as a script:

    mv ~/pcalc.pl ~/bin/pcalc
    It works on my SunOS box using bash. I can set an alias to the
    command-line for launching my script without moving it into any special
    directories, and yes, I am much more familiar with Windows than any
    flavor of UNIX, so I'm aware that I might not be following best
    practices, but that's not the point. I'm not completely sure you didn't
    get my point, however.
    BTW, out here in the real world (that would be UNIX), <snip>
    Beyond being rude and immature, this is off-topic. Please don't try to
    start a "my OS is better than your OS" war.
  • Omega -1911 at Mar 21, 2006 at 11:29 pm
    With all the debate going on, let me just say that a perl script was THE
    ONLY method that allowed me to change paths in 13,161 files and scripts when
    I moved from one provider to another. Try a *one-liner" on multiple files
    (13,000+) located in different directories...

    With a Perl script, I can make the needed changes, make a copy of the
    original for back-up purposes, and move files accordingly. Will I always
    remember a *one-liner* that will do all that? Certainly not, but I will
    always have that script. Honestly, was there a better way then using a
    script for the above purpose?

    I like this list, but sometimes I think authors forget from wince they came
    making the "barrier to entry" difficult as if job security was an issue.

    ~Feel free to allow knowledge freedom~
    On 3/21/06, Timothy Johnson wrote:



    -----Original Message-----
    From: Mr. Shawn H. Corey
    Sent: Tuesday, March 21, 2006 2:29 PM
    To: beginners perl
    Subject: Re: regex one liner

    Timothy Johnson wrote:
    And you can't do this?

    alias pcalc='perl ~/pcalc.pl'
    No. With alias, I can create an alias file that works with sh (and ksh,
    bash) and csh (and tcsh). This would be dot'ed in your .profile as:

    . ~/.alias

    or source'd in your .cshrc as:

    source ~/.alias

    If you want the same as a script:

    mv ~/pcalc.pl ~/bin/pcalc
    It works on my SunOS box using bash. I can set an alias to the
    command-line for launching my script without moving it into any special
    directories, and yes, I am much more familiar with Windows than any
    flavor of UNIX, so I'm aware that I might not be following best
    practices, but that's not the point. I'm not completely sure you didn't
    get my point, however.
    BTW, out here in the real world (that would be UNIX), <snip>
    Beyond being rude and immature, this is off-topic. Please don't try to
    start a "my OS is better than your OS" war.


    --
    To unsubscribe, e-mail: beginners-unsubscribe@perl.org
    For additional commands, e-mail: beginners-help@perl.org
    <http://learn.perl.org/> <http://learn.perl.org/first-response>

  • Mr. Shawn H. Corey at Mar 22, 2006 at 12:23 am

    Timothy Johnson wrote:
    Beyond being rude and immature, this is off-topic. Please don't try to
    start a "my OS is better than your OS" war.
    I wasn't trying to be rude but Perl was developed and evolved in UNIX;
    something most people don't know. In UNIX, all scripts, whether there
    are Perl, sh, sed, awk, or anything else, do not have extensions. In
    fact, in UNIX, extensions are conventions, not necessities.

    I apologize if my post caused any bad feelings.


    --

    Just my 0.00000002 million dollars worth,
    --- Shawn

    "For the things we have to learn before we can do them,
    we learn by doing them."
    Aristotle

    "The man who sets out to carry a cat by its tail learns something that
    will always be useful and which will never grow dim or doubtful."
    Mark Twain

    "Believe in the Divine, but paddle away from the rocks."
    Hindu Proverb

    * Perl tutorials at http://perlmonks.org/?node=Tutorials
    * A searchable perldoc is at http://perldoc.perl.org/
  • Timothy Johnson at Mar 21, 2006 at 11:23 pm

    -----Original Message-----
    From: Jay Savage
    Sent: Tuesday, March 21, 2006 3:06 PM
    To: Timothy Johnson
    Subject: Re: regex one liner
    <snip>

    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.
    <snip>
    You're making some assumptions here that may not be valid.
    Quite possibly.
    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. <snip >
    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

    Excellent points. I concede that there are times where it will save you
    effort. I'll still maintain my prejudice against trying to do
    complicated things in one-liners, but that's just because I'm stubborn
    like that.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupbeginners @
categoriesperl
postedMar 20, '06 at 10:30p
activeMar 22, '06 at 12:25a
posts23
users8
websiteperl.org

People

Translate

site design / logo © 2022 Grokbase