use LWP::Simple();
my $url = "http://www.pjb.com.au/muscript/samples/prelude.mid";
my $midi = LWP::Simple::get($url);
use Symbol('gensym');
my $P = gensym();
use MIDI;
my $opus_ref = MIDI::Opus->new({'from_handle' => *P{IO}});
if (!print $P $midi) { warn "can't print: $!\n"; }
$opus_ref->dump();
I've tried $P{IO}, *P{IO}, $P, *{$P}{IO} and several others, and
I've tried putting the print $P $midi line before and
after the MIDI::Opus->new line, but I just get the warning:
can't print: Bad file descriptor
I guess the problem is that before MIDI::Opus->new, no file
is opened on P, and that after, MIDI::Opus->new has opened
the handle and read it and there was no data there.
Is there a way I can get my data into MIDI::Opus->new ?
Regards, Peter
--
Peter Billam www.pjb.com.au www.pjb.com.au/comp/contact.html
Don't mess with gensym. Just do this:
open P, '<', \$midi or die;
>
> use MIDI;
> my $opus_ref = MIDI::Opus->new({'from_handle' => *P{IO}});
> if (!print $P $midi) { warn "can't print: $!\n"; }
and get rid of that print.
> $opus_ref->dump();
>
--
Alan Curry
On 2009-11-28, Alan Curry <pac...@kosh.dhis.org> replied:
> Don't mess with gensym. Just do this:
> open P, '<', \$midi or die;
> > use MIDI;
> > my $opus_ref = MIDI::Opus->new({'from_handle' => *P{IO}});
> > if (!print $P $midi) { warn "can't print: $!\n"; }
> and get rid of that print.
Many thanks ! I'd never used this before (perldoc -f open):
Since v5.8.0, perl has built using PerlIO by default. Unless
you’ve changed this (i.e. Configure -Uuseperlio), you can open
file handles to "in memory" files held in Perl scalars via:
open($fh, '>', \$variable) || ..
It all works now :-)