G
gordon
I'm having some problems running a bit of legacy perl code on a newly
installed redhat 9. With the perl 5.8.0 that comes with redhat 9, the
match against the string literal works, the match against the same
string read from a file fails.
The weird thing is that with a 5.8.0 compiled from source with default
settings, both matches work, which is what we'd expect.
To make the script work you can add a binmode F after the second file
open, or you can change the [^\s]+ to [\S]+ or \S+. But the question
is, why are either of these things necessary? I don't understand the
fundamental cause of this problem and don't want to go through all the
legacy scripts if I can help it.
Is there a problem in the redhat 9 perl distribution, or just a
misunderstanding of something on my part?
Here's a tiny script to show the problem:
my $x = "this\n";
open(F, ">/tmp/test.txt");
print F "$x";
close(F);
open(F, "</tmp/test.txt");
my @lines = <F>;
close(F);
if ($x =~ /^\s*([^\s]+)/)
{
print "'$x' internal string matched OK\n";
}
else
{
print "'$x' internal string FAILED!\n";
}
for $x (@lines)
{
if ($x =~ /^\s*([^\s]+)/)
{
print "'$x' file string matched OK\n";
}
else
{
print "'$x' file string FAILED!\n";
}
}
- gordon
installed redhat 9. With the perl 5.8.0 that comes with redhat 9, the
match against the string literal works, the match against the same
string read from a file fails.
The weird thing is that with a 5.8.0 compiled from source with default
settings, both matches work, which is what we'd expect.
To make the script work you can add a binmode F after the second file
open, or you can change the [^\s]+ to [\S]+ or \S+. But the question
is, why are either of these things necessary? I don't understand the
fundamental cause of this problem and don't want to go through all the
legacy scripts if I can help it.
Is there a problem in the redhat 9 perl distribution, or just a
misunderstanding of something on my part?
Here's a tiny script to show the problem:
my $x = "this\n";
open(F, ">/tmp/test.txt");
print F "$x";
close(F);
open(F, "</tmp/test.txt");
my @lines = <F>;
close(F);
if ($x =~ /^\s*([^\s]+)/)
{
print "'$x' internal string matched OK\n";
}
else
{
print "'$x' internal string FAILED!\n";
}
for $x (@lines)
{
if ($x =~ /^\s*([^\s]+)/)
{
print "'$x' file string matched OK\n";
}
else
{
print "'$x' file string FAILED!\n";
}
}
- gordon