String buffer instead of file handle?

D

danparker276

I have to connect to this module, and I usually send it a file handle,
or stdout. But I want to write it to a string. Is there a string
buffer or something I can use?

open (FILEO, ">test.txt");
$xw = MP3Com::XMLWriter->new (\*FILEO);

or
$xw = MP3Com::XMLWriter->new (\*STDOUT);

I want to do:
my $xmlstring
$xw = MP3Com::XMLWriter->new ($xmlstring);
 
P

Paul Lalli

I have to connect to this module, and I usually send it a file handle,
or stdout. But I want to write it to a string. Is there a string
buffer or something I can use?
Yes.

open (FILEO, ">test.txt");
$xw = MP3Com::XMLWriter->new (\*FILEO);

or
$xw = MP3Com::XMLWriter->new (\*STDOUT);

I want to do:
my $xmlstring
$xw = MP3Com::XMLWriter->new ($xmlstring);

Check the documentation for the function you're using. In this case,
that's open:
perldoc -f open
[snip]
File handles can be opened to "in memory" files held
in Perl scalars via:

open($fh, '>', \$variable) || ..
[snip]

Paul Lalli
 
B

Brian McCauley

I have to connect to this module, and I usually send it a file handle,
or stdout. But I want to write it to a string. Is there a string
buffer or something I can use?
Yes.

open (FILEO, ">test.txt");

perldoc -f open

(At least on recent Perl. On older Perl you can't just use open() to
make a scalar behave like a file and you need the IO::Scalar module).

BTW: If you _do_ have a recent Perl then you should accept the standard
admonishment to read the documentation for the functions you are using
before you start asking others for help.
 
D

danparker276

Paul said:
I have to connect to this module, and I usually send it a file handle,
or stdout. But I want to write it to a string. Is there a string
buffer or something I can use?
Yes.

open (FILEO, ">test.txt");
$xw = MP3Com::XMLWriter->new (\*FILEO);

or
$xw = MP3Com::XMLWriter->new (\*STDOUT);

I want to do:
my $xmlstring
$xw = MP3Com::XMLWriter->new ($xmlstring);

Check the documentation for the function you're using. In this case,
that's open:
perldoc -f open
[snip]
File handles can be opened to "in memory" files held
in Perl scalars via:

open($fh, '>', \$variable) || ..

This just opens a file called SCALAR(0x8a09e30)

[snip]

Paul Lalli
 
T

Tad McClellan

Did you do that?

(obviously not...)

In this case,
that's open:
perldoc -f open
[snip]
File handles can be opened to "in memory" files held
in Perl scalars via:

open($fh, '>', \$variable) || ..


Did _your_ docs say what was quoted above?

If not, then the quote does not apply to the version of perl that you have.

This just opens a file called SCALAR(0x8a09e30)


Upgrade to a modern perl.
 
X

xhoster

I have to connect to this module, and I usually send it a file handle,
or stdout. But I want to write it to a string. Is there a string
buffer or something I can use?

I think this should do what you want, from perldoc -f open:

Since v5.8.0, perl has built using PerlIO by
default. Unless you've changed this (ie Configure
-Uuseperlio), you can open file handles to "in
memory" files held in Perl scalars via:

open($fh, '>', \$variable) || ..


Xho
 
X

xhoster

Check the documentation for the function you're using. In this case,
that's open:
perldoc -f open
[snip]
File handles can be opened to "in memory" files held
in Perl scalars via:

open($fh, '>', \$variable) || ..

This just opens a file called SCALAR(0x8a09e30)

what does perl -V give?

If your Perl is too old to support this, see IO::Scalar

Xho
 
B

Brian McCauley

We really mean this!
[snip]
File handles can be opened to "in memory" files held
in Perl scalars via:

open($fh, '>', \$variable) || ..

This just opens a file called SCALAR(0x8a09e30)

Did you check the documentation for the function you're using? Note:
the function you are using is open() in the version of Perl that you
are using. This is evidently not as recent as the one Paul is using and
the feature you are looking for only became built-in [1] very recently.

[1] Actually it's not completely built-in, behind the curtain open()
actually loads a module IIRC. But please ignore the man behind the
curtain. :)
 
D

danparker276

Brian said:
We really mean this!
[snip]
File handles can be opened to "in memory" files held
in Perl scalars via:

open($fh, '>', \$variable) || ..

This just opens a file called SCALAR(0x8a09e30)

Did you check the documentation for the function you're using? Note:
the function you are using is open() in the version of Perl that you
are using. This is evidently not as recent as the one Paul is using and
the feature you are looking for only became built-in [1] very recently.
Yeah, the version on the machine is old, 5.6. I read the docs and
couldn't find anything. I'm more of a .net or java person. This code
just needs to be supported for the next year until it is replaced.

[1] Actually it's not completely built-in, behind the curtain open()
actually loads a module IIRC. But please ignore the man behind the
curtain. :)
 
D

danparker276

Tad,
" open($fh, '>', \$variable)" This would work perfect, just not the
right version of perl.
I'm just gonna rewrite the other module to use a string, it's not worth
the trouble of finding another solution.

And your quote:
"> Did you do that?
(obviously not...)"

Makes me want to punch you in the face. Why do you have to be such a
smart a**?
I guess with a name like Tad, you're used to being picked on.

Why does everyone have to always say "read the docs". This is
something simple I thought someone knew off the top of their head.
Maybe I don't have to use the open function.

Oh yeah, and I top-posted on purpose. Everyone on this group is so
stuck up. .NET 2.0 blows everything away anyway. At least on their
formus, people from microsoft will answer questions instead of "Look at
the docs"





Tad said:
Did you do that?

(obviously not...)

In this case,
that's open:
perldoc -f open
[snip]
File handles can be opened to "in memory" files held
in Perl scalars via:

open($fh, '>', \$variable) || ..


Did _your_ docs say what was quoted above?

If not, then the quote does not apply to the version of perl that you have.

This just opens a file called SCALAR(0x8a09e30)


Upgrade to a modern perl.
 
A

Ala Qumsieh

Oh yeah, and I top-posted on purpose. Everyone on this group is so
stuck up. .NET 2.0 blows everything away anyway. At least on their
formus, people from microsoft will answer questions instead of "Look at
the docs"

Well, they are being paid by Microsoft to do that. If somebody (for example,
you) pays me, I'll answer too. Otherwise, you don't really get to complain.

--Ala
 
T

Tad McClellan

.NET 2.0 blows everything away anyway. At least on their
formus, people from microsoft will answer questions instead of "Look at
the docs"


That's because Bill's mindless minions _need_ someone to hold their hand.

This programming stuff is pretty scary!
 
M

Mumia W.

Tad,
" open($fh, '>', \$variable)" This would work perfect, just not the
right version of perl. [...]

Do you mean that you can't install and use IO::Scalar?

If you haven't tried it, you probably can.
 
D

danparker276

I just changed to module to use a string instead of a file handle and
it works fine (oh man I rule, can you say genius!!). I'm not gonna
upgrade to 5.8 and risk other stuff not working.

being a .net programmer puts me on a higher evolutionary scale, and I
get more chicks that way.


Michele said:
" open($fh, '>', \$variable)" This would work perfect, just not the
right version of perl.

This *should* work perfectly. But *you* say it didn't. And in a way
that clearly shows that your perl does not support thay feature. Thus
your perl must be considerably old and I recommend you to follow the
good piece of advice you've been given: i.e. upgrade it.
And your quote:
"> Did you do that?

Makes me want to punch you in the face. Why do you have to be such a
smart a**?
I guess with a name like Tad, you're used to being picked on.

Such an attitude as yours makes me *possibly* want to punch one in the
face. Both for your refusal of listening to good suggestions after
having asked for help and for bringing a personal attack -albeit a
very weak one, due to its stupidity- as means to support your "point".
Why does everyone have to always say "read the docs". This is

Because some people tries very hard to keep the docs up to date and
rich and helpful, maybe? Because it is the best way to teach one how
to find quickly help without bothering people with questions that do
not really deserve being asked?
something simple I thought someone knew off the top of their head.
Maybe I don't have to use the open function.

In fact someone knew. Most of us do. The answer is

open my $fh, '>', \$buffer or die "horribly: $!\n";

That's the first answer you got. And since it is now a standard open()
feature you've been pointed to its documentation as well. Of course
you were not strictly required to check it soon, but you definitely
should have, upon verifying that the ready made solution above didn't
work. You would have realized that the feature we pointed you to
appears not to be documented on your system. Thus you could have
realized that your system is outdated too. Then it could have been
fair to ask "how do I do it with an outdated perl?" if you *really* do
not want to update, which remains the best thing to do in any case...
Oh yeah, and I top-posted on purpose. Everyone on this group is so

Oh! Very kind of you to make communication more difficult for everyone
here (but possibly you), for no real good reason. You will be
*PLONKED* on purpose.

Ignorance one can cope with, stupidity one can cope with. Arrogance is
just a little bit too much for me and for quite about of others here.
With this attitude you will be left alone with the "expertise" of
those who "will answer questions"...
stuck up. .NET 2.0 blows everything away anyway. At least on their
formus, people from microsoft will answer questions instead of "Look at
the docs"

And who gives a ****?!? Should this increase my consideration about
them? Should this decrease that of one of the most resourceful and
helpful newsgroups I've ever been in, namely this one?

"Give a man a fish, he'll live for a day. Teach him how to fish, he'll
tell you that he has no time to play with lines and hooks."


Michele
--
{$_=pack'B8'x25,unpack'A8'x32,$a^=sub{pop^pop}->(map substr
(($a||=join'',map--$|x$_,(unpack'w',unpack'u','G^<R<Y]*YB='
.'KYU;*EVH[.FHF2W+#"\Z*5TI/ER<Z`S(G.DZZ9OX0Z')=~/./g)x2,$_,
256),7,249);s/[^\w,]/ /g;$ \=/^J/?$/:"\r";print,redo}#JAPH,
 
B

Brian McCauley

Michele said:
Because some people tries very hard to keep the docs up to date and
rich and helpful, maybe? Because it is the best way to teach one how
to find quickly help without bothering people with questions that do
not really deserve being asked?

That's only part of it. There's also the fact that to an experienced
programmer just looking at an inappropriate denormalization is painful.
Retyping information that's covered in the standard docs is a
denomalization. So even if it weren't for the fact that it's more
effort for the person answering and less help to the person asking I'd
still be uncomfortable retyping.
 
D

danparker276

Brian said:
That's only part of it. There's also the fact that to an experienced
programmer just looking at an inappropriate denormalization is painful.
Retyping information that's covered in the standard docs is a
denomalization. So even if it weren't for the fact that it's more
effort for the person answering and less help to the person asking I'd
still be uncomfortable retyping.

So if your friend asked you what's on TV tonight (and you know you were
watching Prison Break), you'd tell him "Look it up in the TV guide".
It's called being nice.

Look at me, I got over 9000 MySpace friends!!!! I'm a stud.
 
T

Ted Zlatanov

being a .net programmer puts me on a higher evolutionary scale, and
I get more chicks that way.

So you've evolved into a chicken? That explains a *lot* about .Net
programmers.

Ted
 
D

danparker276

Serious? Was that supposed to be funny? I scored with 2 chicks last
weekend! Think about that next time your home alone on friday night.
 
D

danparker276

I'd tell her what's on, and then her and all her model friends would
then want to watch it at my place.
 
R

RedGrittyBrick

So if your friend asked you what's on TV tonight (and you know you were
watching Prison Break), you'd tell him "Look it up in the TV guide".
It's called being nice.

How about if some total stranger shouted out "whats on TV tonight"
whilst holding a TV guide in their hands?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top