Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical

code to replace

by littlemonk (Sexton)
on May 02, 2010 at 16:06 UTC ( #837994=perlquestion: print w/replies, xml ) Need Help??
littlemonk has asked for the wisdom of the Perl Monks concerning the following question:

I have a directory called dir1 which contains number of file with .xml extension ..i want to change tht .xml extension to .txt any body help me ..thanks in advance?

Replies are listed 'Best First'.
Re: perl script & perl program
by BrowserUk (Pope) on May 02, 2010 at 17:15 UTC

    I think the origins of the term 'script' in this context, come from shell scripts, and jcl scripts, where mostly, the interpreter only provided flow control, and the meat of the task was sub-tasked to specialist processes. Eg. sort, split, find xargs, gzip etc. As such the control files (source code) used by these types of interpreters were likened to the scripts used to give actors directions in theatre and movies.

    Whilst Perl can still be used this way for simple tasks, by bringing the functions of many of the separate sub-task procesess 'in-house', and combining them with composable data structures, and a rich set of built-in functions to manipulate them; and modular sources; Perl became a fully fledged, very high level, programming language. So, the distinction between scripts and programs breaks down.

    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.
Re: perl script & perl program
by Old_Gray_Bear (Bishop) on May 02, 2010 at 20:52 UTC
    A script, to me, is a throw-away -- a quick and dirty solution (usually a one-liner) for an immediate problem ("Get me all XML files in this directory with ABCD in their name and rename them to *abcd*'.) A program is something that I am going to use more than twice. (Once is a script; twice is 'I did that last week....'; third time is A Tool in my ./tools directory.)

    Seriously, the distinction used to be that Programs were compiled and linked, Scripts were interpreted. Then Perl and Java came along and changed the paradigm by having a two-pass Interpreter where the first pass generated Objects that the second pass executed. I use the terms almost interchangeably when I am talking to other Programmers/Developers. I always use 'Program' when I am talking to The Suits In Management.

    I Go Back to Sleep, Now.



      I use the terms almost interchangeably when I am talking to other Prog +rammers/Developers. I always use 'Program' when I am talking to The S +uits In Management.

      This IMHO have found is a rather major caveat in the business world. tell the suits you built a "Program" that makes you more efficient, you get a pat on the back and a raise. tell them you're writing a script and they give you funny looks and talk about you in their board meetings.

Re: perl script & perl program
by moritz (Cardinal) on May 02, 2010 at 16:38 UTC
    "A program is what you give the audience, a script is what you give the actor" (I think TimToday used or quoted that in one of his State of the Onion speeches). (Update: a reference, but not the one I was looking for)

    But it's really just different words for the same thing, in the context of Perl.

Re: perl script & perl program
by erix (Parson) on May 02, 2010 at 16:28 UTC
Re: perl script & perl program
by Illuminatus (Curate) on May 02, 2010 at 16:56 UTC
    • script - used mostly by Java(tm) 'programmers' in a lame attempt to hide the fact that their language is an obtuse, bloated monstrosity that leaks memory like a sieve. I put quotes around programmer because things written in Java are not 'programs', but 'bcs' (byte-code spam)
    • program - what almost everyone else uses
    Seriously, I usually use 'script' if it is less than about 20-30 lines, and program otherwise...


Re: perl script & perl program
by Krambambuli (Curate) on May 02, 2010 at 16:40 UTC
    Sure... :)

    There are quite a few possible answers to your tricky question.

    1. There is no difference, as neither of those two beasts exists.

    2. However, there are Perl scripts and Perl programs.

    3. As Perl scripts are scripts and Perl programs are programs, the difference between them is the same as between scripts and programs.

    4. AFAIK, there is no clear cut between them. Some scripts are called programs and some programs are actually just scripts.

    5. In day to day personal use, I _tend_ to refer to some Perl code as being a script if it is rather a simple, quick-and-dirty program, targeted for command line use, maybe even single-shot uses. I'd probably never call code that runs as a daemon a script.

    But YMMV.

      Re: points 1 and 2, if you're going to take the position that there are Perl (scripts|programs) but not perl (scripts|programs), presumably as a variation on "Perl is the language, perl is the interpreter", then I must point out that /usr/bin/perl is a program, thus there is a "perl program", just like there's a "cat program", a "vi program", etc.
Re: perl script & perl program
by jdporter (Canon) on May 03, 2010 at 14:50 UTC

    I'm sure you're the first person to have wondered this. That's why you shouldn't have expected to find it answered in the Perl FAQ.

    What is the sound of Windows? Is it not the sound of a wall upon which people have smashed their heads... all the way through?
Re: perl script & perl program
by Anonymous Monk on May 02, 2010 at 16:47 UTC
Re: perl script & perl program
by cdarke (Prior) on May 03, 2010 at 10:57 UTC
    Scripts are thrown together without thought, cost nothing to produce, and run without comment.

    Programs require a plan, a specification, Gantt charts, analysts, teams of programmers, testers, technical documenters, project management and a million dollar budget. They are cancelled before they get into production.

      s/require/should have/

Re: perl script & perl program
by dsheroh (Prior) on May 03, 2010 at 09:53 UTC
    "Script" is five letters.
    "Program" is seven letters.
      Shh! Exe is 3 letters :) Oh, I meant: Psst!

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://837994]
Approved by planetscape
Front-paged by Old_Gray_Bear
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (5)
As of 2018-05-26 16:26 GMT
Find Nodes?
    Voting Booth?