Re: Write to file handle




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

.



Relevant Pages

  • Re: PPC 2003 Thread
    ... // Create a read thread for reading data from the communication port. ... DWORD dwError; ... >> not get signaled and the Kernel Tracker tool shows that my main thread is ...
    (microsoft.public.windowsce.embedded.vc)
  • Serial port :bytesAvailable
    ... I am reading binary data from a serial port (it is actually ... have no problem reading data, I am reading data from an eye ...
    (comp.soft-sys.matlab)
  • Re: EAGAIN mystery on accept()
    ... Thanks a real lot Michael for reading my mail. ... lsof showed this to be the only process with a socket on this port ... > In an earlier post you said that tcpdump showed no incoming packets. ... > interface that you're not sniffing, ...
    (comp.unix.solaris)
  • Re: Possibly OT: sending email from shell scripts on cygwin
    ... written by email experts I expect if I went to a mail NG with this I'd ... you by reading your Thunderbird config files" or something :-). ... wrt the info on port 25 being for outgoing and 110 being for incoming ... before I copied my cygwin environment off it. ...
    (comp.unix.shell)
  • Re: Newbie:file and string handling ...
    ... > open (INFILE, $old_file) or die ... That's the "textbook" method of reading a file into an array (which is ... So my preference is to use a CPAN module. ... Opening and closing the file is provided by the module, ...
    (perl.beginners)