cal has asked for the wisdom of the Perl Monks concerning the following question:

Greetings,
I have a HTML file that I need to duplicate so that I can change the code wihtout affecting the original.
Any Ideas on the best way to do this in perl?
Thanks

Replies are listed 'Best First'.
Re: Duplicating HTML files
by Abigail-II (Bishop) on Jul 23, 2002 at 17:34 UTC
    perl -pe1 original.html > copy.html
    Abigail
Re: Duplicating HTML files
by seattlejohn (Deacon) on Jul 23, 2002 at 17:27 UTC
    You could load the file into memory, operate on it there, and save it out to a different name.

    Or use File::Copy.

Re: Duplicating HTML files
by dimmesdale (Friar) on Jul 23, 2002 at 17:29 UTC
    What do you mean by dubplicate and change?

    Well, here's a generic response, though the more info as to what you're doing the better replies you can get (and the monks here can be really helpful).

    You could open the file, and (if its not to big) slurp it into an array, then to some changes based on your needs then save the array to a file (possibly use tie?).

    You could use File::Copy to copy the file, open in (with perl/by hand?) to do some editing.

    #some code to show what I was talking about ... $file = 'your/path/or/is\it\this\way'; # open and slurp in open(FH,$file) or die "make a helpful die statement here"; @lines_of_file = <FH>;
Re: Duplicating HTML files
by talexb (Chancellor) on Jul 23, 2002 at 17:27 UTC
    So maybe you want to write a script that makes the necessary changes from the input stream and outputs to the updated file. Like this:
    perl -w myscript.pl <original.html >updated.html

    --t. alex

    "Mud, mud, glorious mud. Nothing quite like it for cooling the blood!"
    --Michael Flanders and Donald Swann

Re: Duplicating HTML files
by FoxtrotUniform (Prior) on Jul 23, 2002 at 17:27 UTC
Re: Duplicating HTML files
by Bird (Pilgrim) on Jul 23, 2002 at 17:38 UTC
    The way you've phrased your question, it doesn't sound like you even want to edit the file with perl. Instead you're just asking how to copy it, which can be done with...
    perl -ne 'print' original.html >duplicate.html
    ...as well as about a thousand other ways. Of course, the simplest way to do something like this is to skip perl completely and use your OS's copy command, then open up the duplicate and edit away.