[31585] in Perl-Users-Digest
Perl-Users Digest, Issue: 2844 Volume: 11
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Mar 2 14:09:32 2010
Date: Tue, 2 Mar 2010 11:09:17 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Tue, 2 Mar 2010 Volume: 11 Number: 2844
Today's topics:
Can you compile a perl executable? <steve@staticg.com>
Re: Can you compile a perl executable? <adam.kellas@gmail.com>
Re: Can you compile a perl executable? <steve@staticg.com>
Re: Can you compile a perl executable? <adam.kellas@gmail.com>
Re: Can you compile a perl executable? <jurgenex@hotmail.com>
Re: Can you compile a perl executable? <steve@staticg.com>
flushing buffer for printing to the screen <efoss@fhcrc.org>
Re: flushing buffer for printing to the screen <jurgenex@hotmail.com>
Re: flushing buffer for printing to the screen <ben@morrow.me.uk>
how to speed up a string-substitution loop? <adam.kellas@gmail.com>
Re: how to speed up a string-substitution loop? <jimsgibson@gmail.com>
Re: how to speed up a string-substitution loop? <uri@StemSystems.com>
Re: how to speed up a string-substitution loop? <jurgenex@hotmail.com>
Re: how to speed up a string-substitution loop? <adam.kellas@gmail.com>
Re: how to speed up a string-substitution loop? <adam.kellas@gmail.com>
Re: how to speed up a string-substitution loop? <jurgenex@hotmail.com>
Re: how to speed up a string-substitution loop? <ben@morrow.me.uk>
Re: trim the last blank-line and compare files <subhash12@gmail.com>
Re: trim the last blank-line and compare files <cartercc@gmail.com>
Re: trim the last blank-line and compare files <uri@StemSystems.com>
Re: trim the last blank-line and compare files <subhash12@gmail.com>
Re: trim the last blank-line and compare files <uri@StemSystems.com>
Re: trim the last blank-line and compare files <jurgenex@hotmail.com>
Re: unicode characters with PerlMagick <dam-kat-jensen@gmail-kat-.com>
Re: unicode characters with PerlMagick <ben@morrow.me.uk>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Tue, 2 Mar 2010 09:12:05 -0800 (PST)
From: Steve <steve@staticg.com>
Subject: Can you compile a perl executable?
Message-Id: <6f2027d6-4323-4bf6-9e43-d59694eed626@t31g2000prh.googlegroups.com>
If I made an application, and wanted to make it portable, is it
possible to compile it into a single binary?
------------------------------
Date: Tue, 2 Mar 2010 09:18:20 -0800 (PST)
From: Adam Kellas <adam.kellas@gmail.com>
Subject: Re: Can you compile a perl executable?
Message-Id: <79ffa1c8-6572-4aaf-ad04-87435035ee73@15g2000yqi.googlegroups.com>
On Mar 2, 12:12=A0pm, Steve <st...@staticg.com> wrote:
> If I made an application, and wanted to make it portable, is it
> possible to compile it into a single binary?
Don't you mean "if I want to make it un-portable"? A script is
portable, a binary will be native to a particular platform. But yes,
there are advantages to making your script into a binary and there are
tools to do so. Last I looked there's a commercial tool made by
ActiveState and at least one free alternative. Google will help you
here.
AK
------------------------------
Date: Tue, 2 Mar 2010 09:40:16 -0800 (PST)
From: Steve <steve@staticg.com>
Subject: Re: Can you compile a perl executable?
Message-Id: <6ae73eaa-b803-435b-be20-19e61222c476@g28g2000prb.googlegroups.com>
On Mar 2, 9:18=A0am, Adam Kellas <adam.kel...@gmail.com> wrote:
> On Mar 2, 12:12=A0pm, Steve <st...@staticg.com> wrote:
>
> > If I made an application, and wanted to make it portable, is it
> > possible to compile it into a single binary?
>
> Don't you mean "if I want to make it un-portable"? A script is
> portable, a binary will be native to a particular platform. But yes,
> there are advantages to making your script into a binary and there are
> tools to do so. Last I looked there's a commercial tool made by
> ActiveState and at least one free alternative. Google will help you
> here.
>
> AK
Unportable? No, that's not what I mean. EG: I make a script/program
that loads modules I've installed on my computer. I can't go and move
this to another server/computer unless I install the modules first,
right? I'm looking for a way to avoid installing all the modules
manually.
------------------------------
Date: Tue, 2 Mar 2010 09:57:21 -0800 (PST)
From: Adam Kellas <adam.kellas@gmail.com>
Subject: Re: Can you compile a perl executable?
Message-Id: <819aabce-f002-45d3-8264-acfd6f17f0a0@q23g2000yqd.googlegroups.com>
On Mar 2, 12:40=A0pm, Steve <st...@staticg.com> wrote:
> On Mar 2, 9:18=A0am, Adam Kellas <adam.kel...@gmail.com> wrote:
>
> > On Mar 2, 12:12=A0pm, Steve <st...@staticg.com> wrote:
>
> > > If I made an application, and wanted to make it portable, is it
> > > possible to compile it into a single binary?
>
> > Don't you mean "if I want to make it un-portable"? A script is
> > portable, a binary will be native to a particular platform. But yes,
> > there are advantages to making your script into a binary and there are
> > tools to do so. Last I looked there's a commercial tool made by
> > ActiveState and at least one free alternative. Google will help you
> > here.
>
> > AK
>
> Unportable? No, that's not what I mean. EG: I make a script/program
> that loads modules I've installed on my computer. =A0I can't go and move
> this to another server/computer unless I install the modules first,
> right? I'm looking for a way to avoid installing all the modules
> manually.
Which is a fine goal, but not what is meant by "portable". Portable
means it can run on different platforms.
AK
------------------------------
Date: Tue, 02 Mar 2010 10:08:20 -0800
From: Jürgen Exner <jurgenex@hotmail.com>
Subject: Re: Can you compile a perl executable?
Message-Id: <pvkqo5t6prif68eet664diomel07v9u3em@4ax.com>
Steve <steve@staticg.com> wrote:
>If I made an application, and wanted to make it portable, is it
>possible to compile it into a single binary?
See "perldoc -q compile":
"How can I compile my Perl program into byte code or C?"
jue
------------------------------
Date: Tue, 2 Mar 2010 10:33:47 -0800 (PST)
From: Steve <steve@staticg.com>
Subject: Re: Can you compile a perl executable?
Message-Id: <d03d147d-bfee-4709-887b-77d5b22a9535@g8g2000pri.googlegroups.com>
On Mar 2, 10:08=A0am, J=FCrgen Exner <jurge...@hotmail.com> wrote:
> Steve <st...@staticg.com> wrote:
> >If I made an application, and wanted to make it portable, is it
> >possible to compile it into a single binary?
>
> See "perldoc -q compile":
> =A0 =A0 =A0 =A0 "How can I compile my Perl program into byte code or C?"
>
> jue
Thanks!
------------------------------
Date: Tue, 2 Mar 2010 10:44:30 -0800 (PST)
From: "efoss@fhcrc.org" <efoss@fhcrc.org>
Subject: flushing buffer for printing to the screen
Message-Id: <e16302b8-376e-4be0-ace4-72d133c27fdb@u15g2000prd.googlegroups.com>
I want to be certain that a print statement is immediately executed.
Googling around led me to use "$| = 1". Is this correct? Here is an
example of how I'm using it:
my $test;
$| = 1;
$test = 3;
print "test is $test\n";
Thanks.
Eric
------------------------------
Date: Tue, 02 Mar 2010 10:50:05 -0800
From: Jürgen Exner <jurgenex@hotmail.com>
Subject: Re: flushing buffer for printing to the screen
Message-Id: <1anqo5p7sqicb01136oesvv2fgd473933l@4ax.com>
"efoss@fhcrc.org" <efoss@fhcrc.org> wrote:
>I want to be certain that a print statement is immediately executed.
>Googling around led me to use "$| = 1". Is this correct? Here is an
>example of how I'm using it:
>
>$| = 1;
>$test = 3;
>print "test is $test\n";
Yes, that is the correct use of $|.
However it only tells perl to not buffer the output and has no impact on
whatever buffereing your OS or terminal server or server-client protocol
(if applicable) decides to do.
jue
------------------------------
Date: Tue, 2 Mar 2010 19:01:35 +0000
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: flushing buffer for printing to the screen
Message-Id: <ft3067-ak1.ln1@osiris.mauzo.dyndns.org>
Quoth "efoss@fhcrc.org" <efoss@fhcrc.org>:
> I want to be certain that a print statement is immediately executed.
> Googling around led me to use "$| = 1". Is this correct? Here is an
> example of how I'm using it:
perldoc perlvar
Ben
------------------------------
Date: Tue, 2 Mar 2010 08:39:16 -0800 (PST)
From: Adam Kellas <adam.kellas@gmail.com>
Subject: how to speed up a string-substitution loop?
Message-Id: <688f37dd-7719-4944-a19f-77a60c572804@d2g2000yqa.googlegroups.com>
Hi,
Looking for suggestions on how to speed up the function below. It's
intended to "re-macroize" the output of make; in other words given a
sequence of command lines generated by make, and a set of make macros,
I need to substitute in the make variables such that "gcc -c -g -O2 -
Wall -DNDEBUG" might become (say) "$(CC) -c $(CFLAGS) $(DFLAGS)", as
much as possible as it was in the original Makefile. The %Variables
hash maps strings to macro names; thus with the above example we would
have
$Variables{'gcc'} = '$(CC)';
$Variables{'-g -O2 -Wall'} = '$(CFLAGS)';
$Variables{'-DNDEBUG'} = '$(DFLAGS)';
Anyway, the function below seems to work but scales very badly and
becomes unusable when enough variables are in use. Any ideas on how to
write it better?
sub varify {
my $word = shift;
$word =~ s%\$%\$\$%g;
for my $substr (keys %Variables) {
while ((my $start = index($word, $substr)) >= 0) {
substr($word, $start, length($substr)) = $Variables{$substr};
}
}
return $word;
}
Thanks,
AK
------------------------------
Date: Tue, 02 Mar 2010 09:57:39 -0800
From: Jim Gibson <jimsgibson@gmail.com>
Subject: Re: how to speed up a string-substitution loop?
Message-Id: <020320100957398385%jimsgibson@gmail.com>
In article
<688f37dd-7719-4944-a19f-77a60c572804@d2g2000yqa.googlegroups.com>,
Adam Kellas <adam.kellas@gmail.com> wrote:
> Hi,
>
> Looking for suggestions on how to speed up the function below. It's
> intended to "re-macroize" the output of make; in other words given a
> sequence of command lines generated by make, and a set of make macros,
> I need to substitute in the make variables such that "gcc -c -g -O2 -
> Wall -DNDEBUG" might become (say) "$(CC) -c $(CFLAGS) $(DFLAGS)", as
> much as possible as it was in the original Makefile. The %Variables
> hash maps strings to macro names; thus with the above example we would
> have
>
> $Variables{'gcc'} = '$(CC)';
> $Variables{'-g -O2 -Wall'} = '$(CFLAGS)';
> $Variables{'-DNDEBUG'} = '$(DFLAGS)';
>
> Anyway, the function below seems to work but scales very badly and
> becomes unusable when enough variables are in use. Any ideas on how to
> write it better?
>
> sub varify {
> my $word = shift;
> $word =~ s%\$%\$\$%g;
> for my $substr (keys %Variables) {
> while ((my $start = index($word, $substr)) >= 0) {
> substr($word, $start, length($substr)) = $Variables{$substr};
> }
> }
> return $word;
> }
I don't see how you are going to get much of a speedup. It seems you
are already doing the minimum amount of work with no wasted steps.
You might try using the each() function instead of keys. That saves
generating the key array and the hash lookup for the replacement
string:
while( my($key,$replace) = each( %Variables) ) {
...
substr($word, $start, length($substr)) = $replace;
}
You could also pre-compute the replacement string lengths so you don't
have to call the length() function for each replacement. Thus, you
might be better off using three arrays or a two-dimensional (N,3) array
to hold (key,replacement,length(replacement)) values.
How many key:replacement pairs are you using? I am surprised this
doesn't scale very well. It would appear to be O(n) in the number of
search strings.
As always, only benchmarking can ensure you are getting any speedups or
tell you where the actual bottlenecks are.
--
Jim Gibson
------------------------------
Date: Tue, 02 Mar 2010 13:06:59 -0500
From: "Uri Guttman" <uri@StemSystems.com>
Subject: Re: how to speed up a string-substitution loop?
Message-Id: <87iq9ey4vw.fsf@quad.sysarch.com>
>>>>> "AK" == Adam Kellas <adam.kellas@gmail.com> writes:
AK> Hi,
AK> Looking for suggestions on how to speed up the function below. It's
AK> intended to "re-macroize" the output of make; in other words given a
AK> sequence of command lines generated by make, and a set of make macros,
AK> I need to substitute in the make variables such that "gcc -c -g -O2 -
AK> Wall -DNDEBUG" might become (say) "$(CC) -c $(CFLAGS) $(DFLAGS)", as
AK> much as possible as it was in the original Makefile. The %Variables
AK> hash maps strings to macro names; thus with the above example we would
AK> have
AK> $Variables{'gcc'} = '$(CC)';
AK> $Variables{'-g -O2 -Wall'} = '$(CFLAGS)';
AK> $Variables{'-DNDEBUG'} = '$(DFLAGS)';
AK> sub varify {
AK> my $word = shift;
AK> $word =~ s%\$%\$\$%g;
AK> for my $substr (keys %Variables) {
AK> while ((my $start = index($word, $substr)) >= 0) {
AK> substr($word, $start, length($substr)) = $Variables{$substr};
AK> }
AK> }
AK> return $word;
AK> }
can you make a pattern that would match ANY of the strings you want to
match? even a alternation might do well enough. then you can do a
single s/// with the replacement value being looked up in the $variables
(poor name) hash.
also why would speed be an issue here? it looks like it would be done
off line to fix up makefile output.
uri
--
Uri Guttman ------ uri@stemsystems.com -------- http://www.sysarch.com --
----- Perl Code Review , Architecture, Development, Training, Support ------
--------- Gourmet Hot Cocoa Mix ---- http://bestfriendscocoa.com ---------
------------------------------
Date: Tue, 02 Mar 2010 10:07:02 -0800
From: Jürgen Exner <jurgenex@hotmail.com>
Subject: Re: how to speed up a string-substitution loop?
Message-Id: <1hkqo5hdtbf46aic4ogi7ar0h5omp2c6n9@4ax.com>
Adam Kellas <adam.kellas@gmail.com> wrote:
>Looking for suggestions on how to speed up the function below. It's
>intended to "re-macroize" the output of make; in other words given a
>sequence of command lines generated by make, and a set of make macros,
>I need to substitute in the make variables such that "gcc -c -g -O2 -
>Wall -DNDEBUG" might become (say) "$(CC) -c $(CFLAGS) $(DFLAGS)", as
>much as possible as it was in the original Makefile. The %Variables
>hash maps strings to macro names; thus with the above example we would
>have
>
> $Variables{'gcc'} = '$(CC)';
> $Variables{'-g -O2 -Wall'} = '$(CFLAGS)';
> $Variables{'-DNDEBUG'} = '$(DFLAGS)';
>
>Anyway, the function below seems to work but scales very badly and
>becomes unusable when enough variables are in use. Any ideas on how to
>write it better?
>
>sub varify {
> my $word = shift;
> $word =~ s%\$%\$\$%g;
> for my $substr (keys %Variables) {
> while ((my $start = index($word, $substr)) >= 0) {
> substr($word, $start, length($substr)) = $Variables{$substr};
Probably I am missing the obvious,but why are you doing the replacements
manually, thus incurring a lot of string copy, instead of simply doing a
s///?
I would replace the whole while loop with a straight-forward
s/$substr/$Variables{$substr}/g;
May have to add \Q...\E if needed.
BTW: $substr is an awful name considering there is a function substr()
and capitalized names ($Variables) normally indicate file handles.
jue
------------------------------
Date: Tue, 2 Mar 2010 10:36:50 -0800 (PST)
From: Adam Kellas <adam.kellas@gmail.com>
Subject: Re: how to speed up a string-substitution loop?
Message-Id: <f665b144-a0a3-46cd-a353-aaf42ca48490@j27g2000yqn.googlegroups.com>
On Mar 2, 1:06=A0pm, "Uri Guttman" <u...@StemSystems.com> wrote:
> can you make a pattern that would match ANY of the strings you want to
> match? even a alternation might do well enough. then you can do a
> single s/// with the replacement value being looked up in the $variables
> (poor name) hash.
Thanks, I will try this.
> also why would speed be an issue here? it looks like it would be done
> off line to fix up makefile output.
You're right, this is done more or less off line and in theory should
not be too performance sensitive. But this exhibits really
pathological behavior - for reasons I don't understand, though it
works fine in small unit-test setups it can appear to hang for hours
on end in real-world situations. During that time strace shows that
perl is calling the brk() system call over and over.
Thanks,
AK
------------------------------
Date: Tue, 2 Mar 2010 10:39:14 -0800 (PST)
From: Adam Kellas <adam.kellas@gmail.com>
Subject: Re: how to speed up a string-substitution loop?
Message-Id: <b5491a0d-5e02-478c-bc35-6324e5136172@q16g2000yqq.googlegroups.com>
On Mar 2, 1:07=A0pm, J rgen Exner <jurge...@hotmail.com> wrote:
> Adam Kellas <adam.kel...@gmail.com> wrote:
> >Looking for suggestions on how to speed up the function below. It's
> >intended to "re-macroize" the output of make; in other words given a
> >sequence of command lines generated by make, and a set of make macros,
> >I need to substitute in the make variables such that "gcc -c -g -O2 -
> >Wall -DNDEBUG" might become (say) "$(CC) -c $(CFLAGS) $(DFLAGS)", as
> >much as possible as it was in the original Makefile. The %Variables
> >hash maps strings to macro names; thus with the above example we would
> >have
>
> > =A0$Variables{'gcc'} =3D '$(CC)';
> > =A0$Variables{'-g -O2 -Wall'} =3D '$(CFLAGS)';
> > =A0$Variables{'-DNDEBUG'} =3D '$(DFLAGS)';
>
> >Anyway, the function below seems to work but scales very badly and
> >becomes unusable when enough variables are in use. Any ideas on how to
> >write it better?
>
> >sub varify {
> > =A0 =A0my $word =3D shift;
> > =A0 =A0$word =3D~ s%\$%\$\$%g;
> > =A0 =A0for my $substr (keys %Variables) {
> > =A0 =A0while ((my $start =3D index($word, $substr)) >=3D 0) {
> > =A0 =A0 =A0 =A0substr($word, $start, length($substr)) =3D $Variables{$s=
ubstr};
>
> Probably I am missing the obvious,but why are you doing the replacements
> manually, thus incurring a lot of string copy, instead of simply doing a
> s///?
> I would replace the whole while loop with a straight-forward
> =A0 =A0 =A0 =A0 s/$substr/$Variables{$substr}/g;
> May have to add \Q...\E if needed.
>
> BTW: $substr is an awful name considering there is a function substr()
> and capitalized names ($Variables) normally indicate file handles.
I figured that s/// would be slower than the index/substr technique,
which in theory should resolve to a strstr(), strcpy, and realloc() in
the perl binary. Or at least so I thought.
AK
------------------------------
Date: Tue, 02 Mar 2010 10:52:18 -0800
From: Jürgen Exner <jurgenex@hotmail.com>
Subject: Re: how to speed up a string-substitution loop?
Message-Id: <cfnqo5lotbdf3ldean0jb2bsqsf6v0jvsf@4ax.com>
Adam Kellas <adam.kellas@gmail.com> wrote:
[...]
>> I would replace the whole while loop with a straight-forward
>> s/$substr/$Variables{$substr}/g;
>> May have to add \Q...\E if needed.
>>
>I figured that s/// would be slower than the index/substr technique,
I'd guess it's a simple enough change to just give it a try. If you
really need hard data then there's always the Benchmark module.
jue
------------------------------
Date: Tue, 2 Mar 2010 19:01:02 +0000
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: how to speed up a string-substitution loop?
Message-Id: <es3067-ak1.ln1@osiris.mauzo.dyndns.org>
Quoth Adam Kellas <adam.kellas@gmail.com>:
> On Mar 2, 1:07 pm, J rgen Exner <jurge...@hotmail.com> wrote:
> > Adam Kellas <adam.kel...@gmail.com> wrote:
> > >Looking for suggestions on how to speed up the function below. It's
> > >intended to "re-macroize" the output of make; in other words given a
> > >sequence of command lines generated by make, and a set of make macros,
> > >I need to substitute in the make variables such that "gcc -c -g -O2 -
> > >Wall -DNDEBUG" might become (say) "$(CC) -c $(CFLAGS) $(DFLAGS)", as
> > >much as possible as it was in the original Makefile. The %Variables
> > >hash maps strings to macro names; thus with the above example we would
> > >have
> >
> > > $Variables{'gcc'} = '$(CC)';
> > > $Variables{'-g -O2 -Wall'} = '$(CFLAGS)';
> > > $Variables{'-DNDEBUG'} = '$(DFLAGS)';
> >
> > >Anyway, the function below seems to work but scales very badly and
> > >becomes unusable when enough variables are in use. Any ideas on how to
> > >write it better?
> >
> > >sub varify {
> > > my $word = shift;
> > > $word =~ s%\$%\$\$%g;
> > > for my $substr (keys %Variables) {
> > > while ((my $start = index($word, $substr)) >= 0) {
> > > substr($word, $start, length($substr)) = $Variables{$substr};
> >
> > Probably I am missing the obvious,but why are you doing the replacements
> > manually, thus incurring a lot of string copy, instead of simply doing a
> > s///?
> > I would replace the whole while loop with a straight-forward
> > s/$substr/$Variables{$substr}/g;
> > May have to add \Q...\E if needed.
> >
> > BTW: $substr is an awful name considering there is a function substr()
> > and capitalized names ($Variables) normally indicate file handles.
>
> I figured that s/// would be slower than the index/substr technique,
> which in theory should resolve to a strstr(), strcpy, and realloc() in
> the perl binary. Or at least so I thought.
As a rule of thumb, any single perl op (s/// is a single op) is likely
to be faster than the equivalent algorithm using multiple ops (substr,
index, the assignment and the while loop add up to quite a lot of ops
between them). Lvalue substr is also likely to be slower than 4-arg
substr (since it's much more magical).
Your post xthread (about the process sitting in brk(2)) suggests a lot
of string copying. You could try running through the source string and
building a single result string as an alternative, which should avoid
most of the copying. If you have some idea of an upper bound on the
length of the destination string (if your de-substitutions always make
the string shorter, for instance) you could even try preallocating the
destination string like this:
my $dest = "x" x $dest_size;
$dest = "";
If you now only append to $dest, it won't ever be re-allocated (assuming
you don't go over the original size).
Ben
------------------------------
Date: Tue, 2 Mar 2010 06:49:19 -0800 (PST)
From: Subhash <subhash12@gmail.com>
Subject: Re: trim the last blank-line and compare files
Message-Id: <d387e190-615b-4c8a-91f9-b1931c2cb778@u5g2000prd.googlegroups.com>
On Mar 2, 5:32=A0pm, Subhash <subhas...@gmail.com> wrote:
> Hi
>
> Im comparing two files. Newer file has blank-line introduced at the
> end. So the file difference is only a blank-line at the end. If I need
> to ignore this difference, module File::Compare does not help.
>
> tried with the third argument to the cmp function:
> =A0 cmp("file1","file2", sub { chomp($_[0]) ne chomp($_[1]) })
> which would chomp the lines and then compare the difference if any.
> But still there is difference.
>
> Can you please let me know where Im making the mistake.
>
> Thanks
> Subhash
tweaked a bit, added chomp to a subroutine:
sub trim($) {
my $line =3D $_[0];
chomp($line);
return $line;
}
my $result =3D cmp("file1","file2", sub {trim $_[0] ne trim $_[1]});
but still the comparison fails
------------------------------
Date: Tue, 2 Mar 2010 06:49:45 -0800 (PST)
From: ccc31807 <cartercc@gmail.com>
Subject: Re: trim the last blank-line and compare files
Message-Id: <e45ade3b-839c-421e-9759-8f118757d097@o30g2000yqb.googlegroups.com>
On Mar 2, 7:32=A0am, Subhash <subhas...@gmail.com> wrote:
> Im comparing two files. Newer file has blank-line introduced at the
> end. So the file difference is only a blank-line at the end.
Tie::File lets you treat a file like an array. You might pop the last
line of the file you are treating like an array. I'll try this later
on in the day when I get a break and post back.
CC.
------------------------------
Date: Tue, 02 Mar 2010 09:56:18 -0500
From: "Uri Guttman" <uri@StemSystems.com>
Subject: Re: trim the last blank-line and compare files
Message-Id: <87mxyqzsa5.fsf@quad.sysarch.com>
>>>>> "S" == Subhash <subhash12@gmail.com> writes:
S> On Mar 2, 5:32 pm, Subhash <subhas...@gmail.com> wrote:
>>
>> Im comparing two files. Newer file has blank-line introduced at the
>> end. So the file difference is only a blank-line at the end. If I need
>> to ignore this difference, module File::Compare does not help.
>>
>> tried with the third argument to the cmp function:
>> cmp("file1","file2", sub { chomp($_[0]) ne chomp($_[1]) })
>> which would chomp the lines and then compare the difference if any.
>> But still there is difference.
how are you getting the cmp() function into your code? are you
explicitly importing it? from the module docs:
File::Compare::cmp is a synonym for File::Compare::compare. It is
exported from File::Compare only by request.
use the longer name as you may be getting the builtin cmp op instead.
S> tweaked a bit, added chomp to a subroutine:
S> sub trim($) {
S> my $line = $_[0];
S> chomp($line);
S> return $line;
S> }
are you sure the blank line only has a newline in it? you need to check/trim
all trailing white space if it isn't just a newline.
S> my $result = cmp("file1","file2", sub {trim $_[0] ne trim $_[1]});
have you run the unix diff command and seen that is the only difference?
how do you know it is only a trailing blank line that is the failing
diff?
uri
--
Uri Guttman ------ uri@stemsystems.com -------- http://www.sysarch.com --
----- Perl Code Review , Architecture, Development, Training, Support ------
--------- Gourmet Hot Cocoa Mix ---- http://bestfriendscocoa.com ---------
------------------------------
Date: Tue, 2 Mar 2010 07:33:13 -0800 (PST)
From: Subhash <subhash12@gmail.com>
Subject: Re: trim the last blank-line and compare files
Message-Id: <794ab21f-4644-440e-bb85-c1dcd0240c55@b5g2000prd.googlegroups.com>
On Mar 2, 7:56=A0pm, "Uri Guttman" <u...@StemSystems.com> wrote:
> >>>>> "S" =3D=3D Subhash =A0<subhas...@gmail.com> writes:
>
> =A0 S> On Mar 2, 5:32 pm, Subhash <subhas...@gmail.com> wrote:
> =A0 >>
> =A0 >> Im comparing two files. Newer file has blank-line introduced at th=
e
> =A0 >> end. So the file difference is only a blank-line at the end. If I =
need
> =A0 >> to ignore this difference, module File::Compare does not help.
> =A0 >>
> =A0 >> tried with the third argument to the cmp function:
> =A0 >> cmp("file1","file2", sub { chomp($_[0]) ne chomp($_[1]) })
> =A0 >> which would chomp the lines and then compare the difference if any=
.
> =A0 >> But still there is difference.
>
> how are you getting the cmp() function into your code? are you
> explicitly importing it? from the module docs:
>
> =A0 =A0 =A0 =A0 File::Compare::cmp is a synonym for File::Compare::compar=
e. =A0It is
> =A0 =A0 =A0 =A0 exported from File::Compare only by request.
>
> use the longer name as you may be getting the builtin cmp op instead.
>
> =A0 S> tweaked a bit, added chomp to a subroutine:
> =A0 S> sub trim($) {
> =A0 S> =A0 =A0 =A0 =A0 my $line =3D $_[0];
> =A0 S> =A0 =A0 =A0 =A0 chomp($line);
> =A0 S> =A0 =A0 =A0 =A0 return $line;
> =A0 S> }
>
> are you sure the blank line only has a newline in it? you need to check/t=
rim
> all trailing white space if it isn't just a newline.
>
> =A0 S> my $result =3D cmp("file1","file2", sub {trim $_[0] ne trim $_[1]}=
);
>
> have you run the unix diff command and seen that is the only difference?
> how do you know it is only a trailing blank line that is the failing
> diff?
>
> uri
>
> --
> Uri Guttman =A0------ =A0u...@stemsystems.com =A0-------- =A0http://www.s=
ysarch.com--
> ----- =A0Perl Code Review , Architecture, Development, Training, Support =
------
> --------- =A0Gourmet Hot Cocoa Mix =A0---- =A0http://bestfriendscocoa.com=
---------
CC, presently have read the entire file into an array and removing
blank-lines from the last.
Yes Uri, have explicitly imported cmp of File::Compare module.
ran diff under UNIX, it showed the difference in the last line only.
(ie) the blank line
Thanks
Subhash
------------------------------
Date: Tue, 02 Mar 2010 10:38:00 -0500
From: "Uri Guttman" <uri@StemSystems.com>
Subject: Re: trim the last blank-line and compare files
Message-Id: <87r5o2ybs7.fsf@quad.sysarch.com>
>>>>> "S" == Subhash <subhash12@gmail.com> writes:
S> Yes Uri, have explicitly imported cmp of File::Compare module.
S> ran diff under UNIX, it showed the difference in the last line only.
S> (ie) the blank line
but was it just a newline which chomp could handle or were there blanks
in it? diff won't show you that. you need to look carefully at that last
line to see what is in it. then write your trim to handle it.
uri
--
Uri Guttman ------ uri@stemsystems.com -------- http://www.sysarch.com --
----- Perl Code Review , Architecture, Development, Training, Support ------
--------- Gourmet Hot Cocoa Mix ---- http://bestfriendscocoa.com ---------
------------------------------
Date: Tue, 02 Mar 2010 09:55:57 -0800
From: Jürgen Exner <jurgenex@hotmail.com>
Subject: Re: trim the last blank-line and compare files
Message-Id: <6cjqo55fvd3j6u2ndk8eh5p2ckpbvgm2fk@4ax.com>
Subhash <subhash12@gmail.com> wrote:
>Im comparing two files. Newer file has blank-line introduced at the
>end. So the file difference is only a blank-line at the end.[...]
>which would chomp the lines and then compare the difference if any.
>But still there is difference.
This is a wild guess only but a blank line even after it is chomp()ed is
still something different than no line (empty string versus EOF or
undef).
Even more: if I were to implement this function then the first thing I
would check is the file size. If the file size is different -and your
second file must be larger by your own description- then don't even
bother comparing the content because the contents cannot possibly be the
same.
The easiest solution might be to append a blank line to the older file,
too, if necessary in a temporary copy, and then compare their contents.
jue
------------------------------
Date: 02 Mar 2010 17:24:20 GMT
From: Torben <dam-kat-jensen@gmail-kat-.com>
Subject: Re: unicode characters with PerlMagick
Message-Id: <Xns9D2FBB3AC2A69myicqgmxnet@130.225.254.104>
Ben Morrow <ben@morrow.me.uk> wrote in news:ttgt57-aaj2.ln1
@osiris.mauzo.dyndns.org:
> Hmmmmmm. You clearly haven't been following the interminable 'Unicode is
> irrepairably broken, whatever are we to do??' threads on p5p... :)
No, honestly, I did not see that. Perhaps you could enlighten me with a
link ? :) Yes, I did Google for it.
------------------------------
Date: Tue, 2 Mar 2010 18:52:36 +0000
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: unicode characters with PerlMagick
Message-Id: <kc3067-ak1.ln1@osiris.mauzo.dyndns.org>
Quoth Torben <dam-kat-jensen@gmail-kat-.com>:
> Ben Morrow <ben@morrow.me.uk> wrote in news:ttgt57-aaj2.ln1
> @osiris.mauzo.dyndns.org:
>
> > Hmmmmmm. You clearly haven't been following the interminable 'Unicode is
> > irrepairably broken, whatever are we to do??' threads on p5p... :)
>
> No, honestly, I did not see that. Perhaps you could enlighten me with a
> link ? :) Yes, I did Google for it.
I was (mostly) being facetious. There are some serious problems with
Perl's Unicode support, mostly due to the internal representation
leaking out in places where it shouldn't, and they are being worked on
currently. If you are doing fairly ordinary things, you are careful to
always pass your data through Encode, you stay away from bytes.pm, and
you aren't terribly fussed about questions like 'does e-acute match \w?'
you should be OK.
If you really want references, pretty much any p5p thread started by
Karl Williamson or (lately) Tom Christiansen is likely to be about
Unicode.
Ben
------------------------------
Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 6 Apr 01)
Message-Id: <null>
Administrivia:
To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.
Back issues are available via anonymous ftp from
ftp://cil-www.oce.orst.edu/pub/perl/old-digests.
#For other requests pertaining to the digest, send mail to
#perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
#sending perl questions to the -request address, I don't have time to
#answer them even if I did know the answer.
------------------------------
End of Perl-Users Digest V11 Issue 2844
***************************************