Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > filehandle to variable problem

Reply
Thread Tools

filehandle to variable problem

 
 
mathias
Guest
Posts: n/a
 
      07-15-2003
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.
instead of getting the expected content of the var, i get something
like *main::FH or main::STDOUT or GLOB(0x80f60ac)

you can see the sample script i use at:
http://www.tiasarea.org/perl.html
http://www.tiasarea.org/perl2.html
http://www.tiasarea.org/perl3.html

Thank you for any help

greetings

Mathias

 
Reply With Quote
 
 
 
 
mathias
Guest
Posts: n/a
 
      07-15-2003
Greg Bacon wrote:

> : like *main::FH or main::STDOUT or GLOB(0x80f60ac)
>
> It's a filehandle. Why do you care what it looks like when you print
> its internal representation? What did you expect to happen?
>
> Greg

well i was waiting for bla instead of any of the strings i had.
can you give me a way then to get "bla" from this filehandle ?

thank you
Mathias

 
Reply With Quote
 
 
 
 
Jay Tilton
Guest
Posts: n/a
 
      07-15-2003
mathias <(E-Mail Removed)> wrote:

: Greg Bacon wrote:
:
: > : like *main::FH or main::STDOUT or GLOB(0x80f60ac)
: >
: > It's a filehandle. Why do you care what it looks like when you print
: > its internal representation? What did you expect to happen?
: >
: > Greg

: well i was waiting for bla instead of any of the strings i had.
: can you give me a way then to get "bla" from this filehandle ?

Your code is short enough that including it in the article is
preferable to making readers go out to the web to see it.

[grabbed from http://www.tiasarea.org/perl.html]
#!/usr/bin/perl -w
use strict;

sub runme {
my $fh=shift;
print $fh "bla\n"; }

my $var;
open FH, '>', \$var;
runme(\*FH);
$var = *FH;
close FH;

print "var: \n";
print ">".$var."<\n";

the output from this script is:
var:
>*main::FH<


In Perl 5.8.0, "open FH, '>', \$var" will cause stuff printed to FH to
go into $var. Cut out the "$var = *FH;" line and look in $var for
your 'bla'.

In an older Perl, that form of open() does not have the same behavior.
It just ends up stringifying the scalar reference, creating a file
named like "SCALAR(0x1a653b4)".

 
Reply With Quote
 
mathias
Guest
Posts: n/a
 
      07-17-2003
Jay Tilton wrote:
> mathias <(E-Mail Removed)> wrote:
>
> : Greg Bacon wrote:
> :
> : > : like *main::FH or main::STDOUT or GLOB(0x80f60ac)
> : >
> : > It's a filehandle. Why do you care what it looks like when you print
> : > its internal representation? What did you expect to happen?
> : >
> : > Greg
>
> : well i was waiting for bla instead of any of the strings i had.
> : can you give me a way then to get "bla" from this filehandle ?
>
> Your code is short enough that including it in the article is
> preferable to making readers go out to the web to see it.
>
> [grabbed from http://www.tiasarea.org/perl.html]
> #!/usr/bin/perl -w
> use strict;
>
> sub runme {
> my $fh=shift;
> print $fh "bla\n"; }
>
> my $var;
> open FH, '>', \$var;
> runme(\*FH);
> $var = *FH;
> close FH;
>
> print "var: \n";
> print ">".$var."<\n";
>
> the output from this script is:
> var:
> >*main::FH<

>
> In Perl 5.8.0, "open FH, '>', \$var" will cause stuff printed to FH to
> go into $var. Cut out the "$var = *FH;" line and look in $var for
> your 'bla'.
>
> In an older Perl, that form of open() does not have the same behavior.
> It just ends up stringifying the scalar reference, creating a file
> named like "SCALAR(0x1a653b4)".
>

thank you for the help
i finally solved it out

Mathias

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
A problem with storing a filehandle as an instance variable Sniff Perl Misc 6 12-21-2007 08:56 PM
Filehandle Pipe Problem? g4173c@motorola.com Perl Misc 2 04-20-2007 04:11 PM
Problem Commenting within Filehandle Iteration Wijaya Edward Python 1 10-26-2006 08:18 AM
Problem using print with a reference to a filehandle niall.macpherson@ntlworld.com Perl Misc 4 06-02-2006 03:43 PM
How can I tell if a variable is a FileHandle? peterkayatwork@yahoo.com Perl Misc 2 01-13-2005 04:26 PM



Advertisments