Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Re^2: Reading a text file collapsing line continuations

by CountZero (Bishop)
on Mar 09, 2009 at 17:59 UTC ( #749372=note: print w/ replies, xml ) Need Help??


in reply to Re: Reading a text file collapsing line continuations
in thread Reading a text file collapsing line continuations

I doubt if it is a scoping issue. The script works as expected on my Windows XP Pro ActiveState Perl v5.8.8 [MSWin32-x86-multi-thread]. The OP has a problem with the script under Linux Perl v5.8.8 but no problem under Linux Perl v5.10.0.

If you are right, that means that the scoping rules would be different between Windows and Linux? Seems strange to me.

But I see the same output (but not the warnings!) as the OP if I replace the redo with next and that is as expected.

The difference between redo and next being that redo does not re-evaluate the condition, whereas next of course does. In other words, with redo you do not run the defined(my $line = <DATA>) again, so the accumulation of the "broken" lines work and hence it cannot be a scoping issue since you never leave, nor re-enter the scope.

CountZero

A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James


Comment on Re^2: Reading a text file collapsing line continuations
Select or Download Code
Re^3: Reading a text file collapsing line continuations
by kennethk (Monsignor) on Mar 09, 2009 at 18:51 UTC
    That my Linux box (v5.8.8 built for x86_64-linux-gnu-thread-multi under Ubuntu) replicates the issue and my Windows box (v5.8.9 built for MSWin32-x86-multi-thread, I forgot I upgraded) does not implies something differs between the implementations. Running the Linux variety through my debugger shows $line to be undef on line 7 on the continuation case, whereas it maintains continuity under AS. Since we are dealing with a variable which is scoped at the loop, I was reading it as the variable was getting a new instance upon redo even though the my was not being re-evaluated. This is supported by the following code, which prints an infinite series of 1's on my Windows box and prints one 1 and then an infinite series of "Use of uninitialized value in print at fluff.pl line 6, <DATA> line 1." on my Linux box:

    #!/usr/bin/perl -w use strict; use warnings; while (defined(my $line = <DATA>) ) { print $line; redo; } __DATA__ 1

    Update: Better example code (I think). Prints 210 under Windows and 2 under Linux:

    #!/usr/bin/perl use strict; use warnings; my $j = 2; while ( my $i = $j ) { print $i if defined $i; last unless $i--; redo; }

    Update 2: Filed a bug report, id [perl #63752]

      It is quite frightening that there are such fundamental differences between Linux and Windows implementations. I would rate that as a bug.

      CountZero

      A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James

      Received a reply on the bug report. The change in behavior between 5.8.8 and 5.10.0 represents "an intended change of behaviour (a bugfix)". The fact that the AS distribution behaves well reflects non-standard patching implemented by AS (Change 24412). Incident is closed, though it seems to me like this patch also needs inclusion in the next distro of 5.8.x.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://749372]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (3)
As of 2014-07-13 22:46 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    When choosing user names for websites, I prefer to use:








    Results (252 votes), past polls