P
PerlUser
Hello,
Please give me an idea of how the following scenario can work. I am
use to C reference / dereference concepts, but after reading perlref
half a dozen times and looking at dozens of newsgroups, I have not been
able to come up with a solution. Given the following code and a file
called "out" with a few lines of junk;
====================
sub tst {
open($FID, "<out");
printf("FID in sub = $FID\n");
return($FID);
}
# Works
$FID = tst();
while (<$FID>) { printf("REC=$_");}
close($FID);
# Works
$FID = *{&tst()}{GLOB};
while (<$FID>) { printf("REC=$_");}
close($FID);
# Works
sysread(tst(), $REC, 100);
printf("REC=${REC}\n");
close($FID);
====================
What I would like is to avoid the assignment of $FID and put the
function call directly into the while loop using the <> operator.
Basically:
while (<tst()>) { printf("REC=$_");}
I know there is a simple solution to this (a few characters on one side
or the other of tst()), but I have yet been able to find the smoking
gun. I am avoiding using any other packages (e.g. no "use" commands...
just built-in functionality).
Thank you in advance for your responses.
v5.8.0 built for i386-linux-thread-multi
Please give me an idea of how the following scenario can work. I am
use to C reference / dereference concepts, but after reading perlref
half a dozen times and looking at dozens of newsgroups, I have not been
able to come up with a solution. Given the following code and a file
called "out" with a few lines of junk;
====================
sub tst {
open($FID, "<out");
printf("FID in sub = $FID\n");
return($FID);
}
# Works
$FID = tst();
while (<$FID>) { printf("REC=$_");}
close($FID);
# Works
$FID = *{&tst()}{GLOB};
while (<$FID>) { printf("REC=$_");}
close($FID);
# Works
sysread(tst(), $REC, 100);
printf("REC=${REC}\n");
close($FID);
====================
What I would like is to avoid the assignment of $FID and put the
function call directly into the while loop using the <> operator.
Basically:
while (<tst()>) { printf("REC=$_");}
I know there is a simple solution to this (a few characters on one side
or the other of tst()), but I have yet been able to find the smoking
gun. I am avoiding using any other packages (e.g. no "use" commands...
just built-in functionality).
Thank you in advance for your responses.
v5.8.0 built for i386-linux-thread-multi