Need Help. .Issue with format statement
My work environment recently shifted from perl v5.6 to perl v5.10
I found one issue with perl format statement in latest version v5.10
sample code:
#!/bin/env perl
use strict;
&genRep();
sub genRep
{
format DURATION_TOP =
[at] <<<<<<<<<<<<<<<<<<<<<<<<<<<
"This is TOP"
-------------------------------
..
format DURATION =
[at] <<<<<<<<<<<<<<<
"Main Body"
..
$~ = 'DURATION';
write;
}
Output in perl v5.6:
This is TOP
-------------------------------
Main Body
output in perl v5.10
Main Body
What should I do in v5.10 to get the old output?
--
To unsubscribe, e-mail: beginners-unsubscribe [at] perl.org
For additional commands, e-mail: beginners-help [at] perl.org
http://learn.perl.org/
Re: Need Help. .Issue with format statement
On Wed, Mar 23, 2011 at 08:47, Sudhir <ece.sudhir [at] gmail.com> wrote:
> My work environment recently shifted from perl v5.6 to perl v5.10
>
> I found one issue with perl format statement in latest version v5.10
>
> sample code:
>
> #!/bin/env perl
> use strict;
>
> &genRep();
>
> sub genRep
> {
> format DURATION_TOP =
> [at] <<<<<<<<<<<<<<<<<<<<<<<<<<<
> "This is TOP"
> -------------------------------
> .
> format DURATION =
> [at] <<<<<<<<<<<<<<<
> "Main Body"
> .
> $~ = 'DURATION';
> write;
> }
>
> Output in perl v5.6:
> This is TOP
> -------------------------------
> Main Body
>
> output in perl v5.10
> Main Body
>
>
> What should I do in v5.10 to get the old output?
snip
I don't have 5.6 laying around, but it looks like 5.12 (and I assume
5.10) will do the right thing if the file is open:
#!/usr/bin/perl
use strict;
#create an in memory file to test if the problem is
#the lack of a filehandle
open DURATION, ">", \my $output or die $!;
&genRep();
print $output;
sub genRep
{
format DURATION_TOP =
[at] <<<<<<<<<<<<<<<<<<<<<<<<<<<
"This is TOP"
-------------------------------
..
format DURATION =
[at] <<<<<<<<<<<<<<<
"Main Body"
..
write DURATION;
}
You could also fix it with fewer steps by dup'ing STDOUT to DURATION
if you weren't already opening DURATION:
#!/usr/bin/perl
use strict;
open DURATION, ">&", \*STDOUT or die $!;
&genRep();
sub genRep
{
format DURATION_TOP =
[at] <<<<<<<<<<<<<<<<<<<<<<<<<<<
"This is TOP"
-------------------------------
..
format DURATION =
[at] <<<<<<<<<<<<<<<
"Main Body"
..
write DURATION;
}
--
Chas. Owens
wonkden.net
The most important skill a programmer can have is the ability to read.
--
To unsubscribe, e-mail: beginners-unsubscribe [at] perl.org
For additional commands, e-mail: beginners-help [at] perl.org
http://learn.perl.org/