On Wed, Mar 23, 2011 at 08:47, Sudhir <ece.sud...@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 = > @<<<<<<<<<<<<<<<<<<<<<<<<<<< > "This is TOP" > ------------------------------- > . > format DURATION = > @<<<<<<<<<<<<<<< > "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 = @<<<<<<<<<<<<<<<<<<<<<<<<<<< "This is TOP" ------------------------------- . format DURATION = @<<<<<<<<<<<<<<< "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 = @<<<<<<<<<<<<<<<<<<<<<<<<<<< "This is TOP" ------------------------------- . format DURATION = @<<<<<<<<<<<<<<< "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-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/