Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re: Streaming to Handles

by zentara (Archbishop)
on May 01, 2004 at 14:25 UTC ( #349614=note: print w/ replies, xml ) Need Help??


in reply to Streaming to Handles

Just some brainstorming....

Would it be possible to use the "variable as a filehandle trick"? You could accesss the variable's value at any time.

#!/usr/bin/perl my $foo = ''; open FILEHANDLE, '+>', \$foo or die $!; my $count = 0; while(1){ print FILEHANDLE $count; print "$foo\n"; select(undef,undef,undef,.1); $count++; } close FILEHANDLE or die $!;

I'm not really a human, but I play one on earth. flash japh


Comment on Re: Streaming to Handles
Download Code
Re: Re: Streaming to Handles
by crabbdean (Pilgrim) on May 05, 2004 at 12:50 UTC
    I still haven't found a great solution to this problem. Forking to me seems overly complicated implementation and doesn't create a simple interface for users.

    This solution suggested above to me seems the closest to what I can imagine. But two things: In this example your print to the FILEHANDLE and the bound variable are in the same program. I've attempted to seperate them into a script and a seperate module method but was unsuccessful. Are you able to demonstrate the above in this way. That would be really helpful.

    Secondly I had another thought along similar lines: I could create a object variable in my object like this:
    # object interface sub new { my ($class, $stream, $path, ) = @_; my $file = undef; $path = cwd unless @_ > 2; my $self = { file => \$file, path => File::Spec->canonpath($path), }; bless $self, $class; return $self; }
    and then in my script make reference to this variable like this:
    my $f = List->new; $f->look_in('c:/'); foreach ($f->list) { ##problem?? print "${$f->{file}}\n"; }
    Now I know straight up just looking at it that this code won't work in the foreach statement but is anyone getting the gist of what I'm attempting. In my program you can instantly dereference this $f->{file} at any time to access the file name it is currently working on. But how does the script know when this piece of memory changes value to rewrite it? Do you just call it in a "while" loop. Hmmmm ... the idea has merit but I'm not sure how to implement this.

    Surely there must be a way to stream ... how is it done? Somebody .. anybody ... are you out there hearing my cries for help? How do you do this? There is a way, I just need to know how!

    Dean
    The Funkster of Mirth
    Programming these days takes more than a lone avenger with a compiler. - sam
    RFC1149: A Standard for the Transmission of IP Datagrams on Avian Carriers
      two things: In this example your print to the FILEHANDLE and the bound variable are in the same program. I've attempted to seperate them into a script and a seperate module method but was unsuccessful. Are you able to demonstrate the above in this way. That would be really helpful.

      I'm not the best person to ask for help on modules, I basically understand the concept, but I still think like an old functional programmer. My first thought on putting the filehandle in the module, is to use "our" instead of "my" on the variable, or export the variable from the module.

      This would make a nice separate question to ask, "how to use a module variable as a filehandle, and export it to the main program".


      I'm not really a human, but I play one on earth. flash japh

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://349614]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (4)
As of 2014-10-31 05:52 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    For retirement, I am banking on:










    Results (214 votes), past polls