Re: Write to file handle
- From: "Paul Lalli" <mritty@xxxxxxxxx>
- Date: 26 Dec 2005 04:32:36 -0800
Swayam Panda wrote:
> Hi All ,
>
> I am using Win32::SerialPort to read the datas from the
> serial port .It's working fine .but i want to save (what ever the serial
> port is reading) to a log file continuously .Can anybody help me how to do
> .I know that i have open a file like
> open (*FIL,+>>log.txt) or die ("couldn't open $!);
1) Get rid of that + sign. That's used for opening a file for reading
and writing. You don't want to read from log.txt, you only want to
write to it.
2) Quote the arguments to open.
3) use lexical filehandles, not global barewords or typeglobs
open my $FIL, '>>', 'log.txt' or die "Couldn't open log.txt for
appending: $!";
> then how to print to this file handle(FIL) while i am using another file
> handle (INFILE)
perldoc -f print
The filehandle goes between the 'print' and the arguments you wish to
print.
while (my $line = <INFILE>) {
print $FIL $line;
}
>
> >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
> here is my code
>
> use Win32::SerialPort;
>
>
> #$serial is a Win32::SerialPort object that represents the comport.
> #The line below declares it and ties it to the file handle INFILE
> #using the configuration file HD_Queue.conf
> my $serial = tie( *INFILE, 'Win32::SerialPort', "tpj4.cfg" ) or
> die("Couldn't tie! $^E\n");
>
> #Infinite loop
> while (1) {
>
> #If there is data in the COM port buffer
> while (<INFILE>) {
>
> print;
In this case, specify $_ explicitly:
print $FIL $_;
Paul Lalli
.
- References:
- Write to file handle
- From: Swayam Panda
- Write to file handle
- Prev by Date: RE: Write to file handle
- Next by Date: sorting hash
- Previous by thread: Write to file handle
- Next by thread: RE: Write to file handle
- Index(es):
Relevant Pages
|