in reply to Re: Easy Things
in thread Easy Things

I do think the use of perl -es is a big domain of sys admins and less for CGI programmers. That doesn't mean they can be any less useful for CGI / OO programmers. (Note, I am using the term perl -es liberally and to refer to any quick and dirty script that makes work lighter and can be thrown away -- but saves quite a bit of time).

To give you a good example, one of my clients got bought out, and wanted me to change widgetscorp.com to widgetscorpinternational.com, and "Widgets Corp., Inc." to "Widgets Corp. International, Inc., A Subdivision of International, Inc." within all of their web pages and CGI scripts on their site. (Several hundred pages combined, not all of which I had done. They however wanted me to change it all under the technical support I was supposed to give them for the site.).

Now I really wanted to keep them as a client, even though I would have had every right to tell them that something of this magnitude was outside the scope of the contract. (I mean, there wasn't anything wrong with the CGI scripts I had written, i.e. bugs, and it wasn't my fault they were bought out!) But, the idea of going through all of their web pages and scripts -- even doing a search and replace -- to change them didn't thrill me either, even if I were to be paid for it because it was grunt work.

Enter Perl and File::Find to the rescue. 5 minutes and I had a script to traverse an arbitrary directory, run an s/widgetscorp\.com/widgetscorpinternational\.com/sgi, and I looked like a hero. Even better, I could e-mail them a copy of the script, and then they could use it internally on their files.

Needless to say they were tickled pink for 5 minutes of my time -- which was well spent because it helped cement my relationship with Widgets Corp International when they were being shaken up.

Replies are listed 'Best First'.
Re: Re: Re: Easy Things
by hardburn (Abbot) on Jan 26, 2004 at 17:19 UTC

    Looking like a hero++

    Pretty much any Perl programmer can benifit from perl -e. The question is if you need more than that to do your job. CGI and application programmers certainly do, but sys admins might not.

    ----
    I wanted to explore how Perl's closures can be manipulated, and ended up creating an object system by accident.
    -- Schemer

    : () { :|:& };:

    Note: All code is untested, unless otherwise stated

      CGI and application programmers certainly do, but sys admins might not.

      This has been bugging me. Can't quite figure out why, but I figure responding will at least get it off my mind

      I really think this all depends on what you view as a system admins role being. Also I suppoed what platform they are an admin for, but I think that is to a lesser extent. I have been a sysadmin for the last 4 years, and I have rarely used perl -e '' constructs, though I have worked on writing and maintaining perl scripts and apps on a daily basis. Any time it is as trivial as a perl -e '', I use system utilities to get the job done.

      I have run just about the full gamut of possible system utilities short of creating a Tk/X based interface. Log parsers, automagic account and quota creation/deletion, wrappers around other system apps allowing for access restriction or business rule adherence, DB interfaces, network aware deamons launcing intersystem apps, yada, yada, yada. I was going to say I haven't built GUIs, but I suppose a browser is a GUI client. I certainly needed more than -e in order to do my job well. Matter of fact the only time I have played with -e, is usually due to a comment in a port or the CB.

      use perl;
      Everyone should spend some time pounding nails with their forehead for a while before they graduate to complicated stuff like hammers. - Dominus

        Certianly many sys admins get along without perl -e. In fact, I know one sys admin that hasn't learned much Perl because awk and sed does what he needs. I'm the opposite--I haven't learned awk or sed because perl -e does what I need for that problem domain (OTOH, I'm not technically employed as a sys admin, either). It's all a matter of what you're comfertable with.

        ----
        I wanted to explore how Perl's closures can be manipulated, and ended up creating an object system by accident.
        -- Schemer

        : () { :|:& };:

        Note: All code is untested, unless otherwise stated

grep, map, and perl -i -pe
by Anonymous Monk on Jan 31, 2004 at 22:30 UTC

    Don't tell them the secret! Now they won't need you. ;)

    I use perl a lot for global search and replace, for example, perl -i -pe 's/before/after/g' *.txt . I use it so much that I have pp aliased to 'perl -i -pe'.

    Regarding the original post, one "easy thing" that I think it's very much worth knowing and that some novices overlook is the appropriate use of grep and map. Sometimes you can save lots of time and typing and write clearer code with grep and map.