perl script to write to a text file

M

MOUNIL

hi ppl,
I am a newbie just tinkering with perl. what i am trying to do
at the moment is writing a script to listen in on a socket. i want to
save the data passed on from the server script to the client script;
in a text file. any help would be highly appreciated.

thanks,
Mounil
 
S

Sherm Pendley

MOUNIL said:
I am a newbie just tinkering with perl. what i am trying to do
at the moment is writing a script to listen in on a socket. i want to
save the data passed on from the server script to the client script;
in a text file. any help would be highly appreciated.

What have you tried so far? What did it do, and how is that different from
what you expected it to do?

Have you read the posting guidelines that are posted here frequently?

sherm--
 
M

Mounilk

I've written 2 scripts in perl; one is the server side script and the
other is the client side script. I run the scripts from two terminals.
Both create,bind and listen in to the socket on the local host machine
(127.0.0.1) . When the connection is established, the server script
passes on some data onto the client script. For eg, just a statement
like "You are now connected to the server". I havent been able to find
out how i can save this data into a text file.

- Mounil
 
S

Sherm Pendley

Mounilk said:
passes on some data onto the client script. For eg, just a statement
like "You are now connected to the server". I havent been able to find
out how i can save this data into a text file.

Open the file for output and print to it. See:

perldoc -f open
perldoc -f print

sherm--
 
J

John Bokma

Sherm said:
Open the file for output and print to it. See:

perldoc -f open
perldoc -f print

Have also a look at
File::Slurp

Or:

yourscript.pl > out.txt
 
M

Mounilk

thanks Sherm.John, i really appreciate you helping me out. i couldn't
really follow your suggestion. i am sorry if i sound naive,but i've
just started using perl a couple of days. could you please elaborate on
your suggestion.

Thanks,
Mounil.
 
S

Sherm Pendley

Mounilk said:
thanks Sherm.John, i really appreciate you helping me out. i couldn't
really follow your suggestion. i am sorry if i sound naive,but i've
just started using perl a couple of days. could you please elaborate on
your suggestion.

"perldoc" is a utility commonly used to read the documentation that comes
with Perl. Other methods can be used too; for example ActiveState's Perl
for Windows comes with documentation in HTML format as well.

Regardless of whether you're actually using the "perldoc" tool or not, when
you see the term "perldoc Foo" used here in this group, it's a pointer to
the documentation that comes with Perl.

When you're using the "perldoc" tool, "perldoc -q Foo" searches the FAQ
questions for the word "Foo". "perldoc -f foo" will display the docs for
the function foo(). And "perldoc Foo::Bar" will display docs for the module
Foo::Bar.

So, my suggestion to you was to read the documentation for the open() and
print() functions. John's suggestion is good too - go to <http:/
search.cpan.org>, find the File::Slurp module, and have a look at its
documentation.

And like I said before - please read (and follow) the posting guidelines
that appear here twice a week.

sherm--
 
M

Mounilk

thanks a lot for that Sherm. You and John have been very helpfull. I
will most certainly have a look at the posting guidelines tonight
because i'll be using this group often and hopefully contributing to
the group as well in the future. Once again, thank you.
-Mounil.
 
J

John Bokma

Mounilk said:
thanks a lot for that Sherm. You and John have been very helpfull. I
will most certainly have a look at the posting guidelines tonight
because i'll be using this group often and hopefully contributing to
the group as well in the future. Once again, thank you.
-Mounil.

What works for me: read a book front to back. Skip everything you don't
understand. Just keep reading.

Read it a second time, and mark the important parts. Also, try out the
examples.

I am doing this with "Dive into Python" and for me this works. There is no
Dive into Perl afaik, but Learning Perl is probably a very good start too,
and maybe better if you are new at programming Perl.

If you are serious at Perl programming, buy the Cookbook too :-D.
 

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,582
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top