in reply to Some missing textutils

So there's been an update that incorporated some suggestions, quashed a few bugs, and am a bit more robust. However I have found something rather odd. These doesn't run under perl 5.005_03. And there are no meaningful messages. The only warnings that occur are for undefined values concerning the length of the files. It seems readline is bailing right off and the first while loop is never entered!!!

I've never really used the debugger so this is the best I can get, to confirm my suspicions...
#I made this change first... - 1 while(readline($data[$i]->{FH})); + while(readline($data[$i]->{FH})){ + 1; + };
main::(./overlay.pl:5): die("usage: overlay file1 file2\n") unless sca +lar @ARGV == 2; DB<1> t Trace = on DB<1> n main::(./overlay.pl:6): my @data; DB<1> n main::(./overlay.pl:7): for(my $i=0; $i < scalar @ARGV; $i++){ DB<1> n main::(./overlay.pl:8): open($data[$i]->{FH}=gensym, $ARGV[$i]) || d +ie("overla y($ARGV[$i]): $!\n"); DB<1> n Symbol::gensym(/usr/perl5/5.00503/Symbol.pm:86): 86: my $name = "GEN" . $genseq++; Symbol::gensym(/usr/perl5/5.00503/Symbol.pm:87): 87: my $ref = \*{$genpkg . $name}; Symbol::gensym(/usr/perl5/5.00503/Symbol.pm:87): 87: my $ref = \*{$genpkg . $name}; Symbol::gensym(/usr/perl5/5.00503/Symbol.pm:88): 88: delete $$genpkg{$name}; Symbol::gensym(/usr/perl5/5.00503/Symbol.pm:89): 89: $ref; main::(./overlay.pl:9): while(readline($data[$i]->{FH})){ DB<1> n main::(./overlay.pl:12): $data[$i]->{LINE} = $.; DB<1> n main::(./overlay.pl:13): seek($data[$i]->{FH}, 0, 0); DB<1> n main::(./overlay.pl:7): for(my $i=0; $i < scalar @ARGV; $i++){
Wheras in perl 5.6 I get:
... main::(overlay.pl:9): while(readline($data[$i]->{FH})){ DB<1> n main::(overlay.pl:10): 1; DB<1> n main::(overlay.pl:9): while(readline($data[$i]->{FH})){ DB<1> n main::(overlay.pl:10): 1; DB<1> n ...

--
perl -p -e "s/(?:\w);([st])/'\$1/mg"

Replies are listed 'Best First'.
Re: Re: Some missing textutils
by danger (Priest) on Dec 02, 2001 at 23:11 UTC

    There is a difference in how readline() handles references to typeglobs from 5.00503 and 5.6.1. The following works in 5.6.1:

    #!/usr/bin/perl -w use strict; use Symbol; my $sym = gensym; open($sym, 'file1') || die "Can't $!"; while(readline($sym)){ print; }

    But it doesn't work in 5.00503 (no warnings, readline simply returns undef so the loop isn't entered). Reading from <$sym> works in both version when $sym is a globref, but readline() itself didn't work with globrefs until 5.6 --- I didn't see mention of it in perldelta, but it is mentioned in the 'Changes' file for 5.6 sources:

    _________________________________________________________________ [ 3349] By: gsar on 1999/05/09 20:23:07 Log: allow readline($globref), <$globref> already works Branch: perl ! pp_hot.c

    A work around for 5.005 is to simply dereference the globref explicitly for the readline() function. The following work in 5.00503 and 5.6.1:

    readline(${$sym}) readline(*{$sym}) or in your particular case: readline(*{$data[$i]->{FH}})

    As a final note, in your last block where you pad out the string I think you want to substract the expand()'d length, not just the length():

    # change this: print $_, ' 'x($data[$i]->{w}-1-length); # to this: print $_, ' 'x($data[$i]->{w}-1-length(expand($_)));
      Damn, YASB. I had
      my $length = length($_ = expand($_));
      originally but upon later review the assignment seemed unnnecessary and was removed.

      --
      perl -p -e "s/(?:\w);([st])/'\$1/mg"

Re: Re: Some missing textutils
by belg4mit (Prior) on Dec 02, 2001 at 08:58 UTC
    I've run overlay through B::Deparse... And learned nothing (okay I learned that B::Deparse doesn't run clean with -w, and that the code it produces (at least in this case) is invalid ;-).

    --
    perl -p -e "s/(?:\w);([st])/'\$1/mg"