Ask a Question related to PERL Beginners, Design and Development.
-
mcdavis941@netscape.net #1
How to tell if subroutine param is filehandle
Hi,
Is there a way for a subroutine to tell when it got passed a FILEHANDLE?
Running a quick test suggests a way, which is to check the first char of the result of interpolating the subroutine param as a string. Can anyone say whether this is robust and if not what might be a better approach? Thank you.
testprintorstring.pl:
---------------------
use warnings;
use strict;
{
my $string = "xyz";
testprint( "Filehandle", *STDIN );
testprint( "Stringref", \$string );
}
sub testprint {
my( $descr, $r_data ) = @_;
print "$descr: $r_data ", ref($r_data), "\n";
}
output:
-------
D:\MCD\dvl\scripts>perl testprintorstring.pl
Filehandle: *main::STDIN
Stringref: SCALAR(0x155a898) SCALAR
__________________________________________________ ________________
New! Unlimited Netscape Internet Service.
Only $9.95 a month -- Sign up today at [url]http://isp.netscape.com/register[/url]
Act now to get a personalized email address!
Netscape. Just the Net You Need.
mcdavis941@netscape.net Guest
-
closed filehandle
Hello when I run the code below I get readline() on closed filehandle DATA at practice.plx line 6. #!/usr/bin/perl use warnings; use... -
FILEHANDLE to print to nothing
Howdy, I am benchmarking some stuff that does multiple print staements. What I'd like to do is print to a file handel so ethat the stuff I'm... -
filehandle to variable problem
Hello all, i try to store filehandle in variable (as described in perl cookbook for instance) and i am not able to use the variable afterwards.... -
first.pl | second.pl with ARGV filehandle ?
>>>>> "s" == stu7 <stuseven@hotmail.com> writes: s> + perl first.pl | perl second.pl something, something ARGV fh ? s> This is what I've seen... -
Using filehandle many times
On 29 Jun 2003 23:43:42 -0700 cdcer@hongkong.com (ABC) wrote: In such cases, 'use diagnostics' might help you with what exactly you need to... -
Jeff 'Japhy' Pinyan #2
Re: How to tell if subroutine param is filehandle
On Feb 1, [email]mcdavis941@netscape.net[/email] said:
You could test to see if its ref() returns "GLOB" or "IO::File" or>Is there a way for a subroutine to tell when it got passed a FILEHANDLE?
"IO::Handle", etc., but I think it's a nifty idea to do:
if (defined fileno($arg)) {
# it's an open filehandle
}
--
Jeff "japhy" Pinyan [email]japhy@pobox.com[/email] [url]http://www.pobox.com/~japhy/[/url]
RPI Acacia brother #734 [url]http://www.perlmonks.org/[/url] [url]http://www.cpan.org/[/url]
<stu> what does y/// stand for? <tenderpuss> why, yansliterate of course.
[ I'm looking for programming work. If you like my work, let me know. ]
Jeff 'Japhy' Pinyan Guest



Reply With Quote

