perl, was Re: [plug] Merging 2 files, CVS-style
Peter Wright
pete at cygnus.uwa.edu.au
Thu Apr 13 17:52:45 WST 2000
On Thu, Apr 13, 2000 at 03:36:55PM +0800, Mike Holland wrote:
> A pity you dont have the common ancestor.
> Whats wrong with Perl BTW?
Nothing, just that where it's not strictly needed (as in a case like
this, where 98% of the "real work" is done by external programs) and
bourne shell is up to the glue work, it's _probably_ preferable to do
it in shell.
Just that I hardly ever do bourne shell programming cos I always have
Perl :).
> Its perfect for that kind of thing - no need to run 'grep' or 'cut'
> externally.
> It can be a lot 'neater' too, .e.g.
> sub gtr {return $_[0] > $_[1] ? $_[0] : $_[1]; }
Yes, I was thinking as I typed that function out that it could
probably be done in a much more compact fashion, but I'd finished
typing the function before my brain had finished processing that
thought.
(and no, that means I'm a fast typist, not (just) a slow thinker :)
> and system("diff -u$size $f1 $f2 | grep '^ ' | cut -c2- > $merge");
> becomes something like:
>
> $merge = map '/^ (.*)$/' `diff -u$size $f1 $f2`;
Or rather:
@merge_lines = map '/^ (.*)$/' `diff -u$size $f1 $f2`;
$merge = join('', @merge_lines);
Otherwise, according to perlfunc(1):
"In scalar context, returns the total number of elements so
generated."
Although I haven't tested it so that still might not be "right". :)
> I like perl. Such a great hack.
There's More Than One Way To Do It.
Or, more appropriately in this case, Whatever Gets The Job Done Before
Your Boss Fires You.
> Mike Holland <mike at golden.wattle.id.au>
:)
Pete.
--
http://cygnus.uwa.edu.au/~pete/
--
Bravely bold Sir Robin, rode forth from Camelot,
He was not afraid to die, Oh Brave Sir Robin,
He was not at all afraid to be killed in nasty ways
Brave, brave, brave, brave Sir Robin.
"Monty Python and the Holy Grail" PYTHON (MONTY) PICTURES LTD
More information about the plug
mailing list