in reply to Write to file, after manipulation
I'm not saying this is the best way to do it, but it's worked for me when I need to multiplex between a number of different choices. It keeps my code bits isolated from each other, and it's easy for other people to read.# Untested code for demonstation purposes only while($command = <IRC>) { last if /please leave, $botname/; bot_command($command); } sub bot_command { my $command = shift(@_); join_channel($command) if ($command =~ /join/); part_channel($command) if ($command =~ /part/); msg_user($command) if ($command =~ /msg/); .... default($command); } sub join_channel { ... } sub part_channel { ... }
If you have use warnings turned on, when you try this you should get an error like:$remove = <REMOVE>;
To open a file for reading AND write, use:Filehandle FILE opened only for output at C:\file.pl line 7.
but this will clober your file, removing any contents before you can read from it. Useopen(REMOVE, "+>project.pjt")
if you want to read and write (append) to the file without zapping the contents everytime. See also the perl Open() tutorial.open(REMOVE, "+>>project.pjt")
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Write to file, after manipulation
by FireBird34 (Pilgrim) on Jan 28, 2003 at 05:08 UTC | |
by Aristotle (Chancellor) on Jan 28, 2003 at 11:53 UTC | |
by FireBird34 (Pilgrim) on Jan 28, 2003 at 20:02 UTC | |
|
Re: Re: Write to file, after manipulation
by jdporter (Paladin) on Jan 28, 2003 at 19:54 UTC | |
by jdporter (Paladin) on Jan 29, 2003 at 20:06 UTC | |
by ibanix (Hermit) on Jan 28, 2003 at 22:01 UTC |