in reply to Re: Some missing textutils
in thread Some missing textutils

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($_)));

Replies are listed 'Best First'.
Re:**3(danger): Some missing textutils
by belg4mit (Prior) on Dec 03, 2001 at 00:27 UTC
    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"