How flush file in perl under mac?

956 views Asked by At

I have perl, v5.10.0 built for darwin-thread-multi-2level in remote iMac. And I want to run some perl script which prints to file some data and flushes after each line of output.

  1. $file_handle->flush();
  2. autoflush $file_handle;

I have tried this two versions with use IO::Handle; in top of the file, but the result I'm getting is Can't locate object method "autoflush" via package "FileHandle".

3

There are 3 answers

2
Rich Parker On

Are you sure the "use IO::Handle;" doesn't have a typo?

It looks to me like the module hasn't loaded.

0
user2208755 On

use FileHandle; solved my issue. I was having issues with Net::SCP::Expect. This happened under CentOS 6.3.

I was getting errors like:
-can't locate object method autoflush via package filehandle
-can't locate object method blocking via package filehandle

0
mscha On

Where are you getting your $file_handle from? Looks like it's a FileHandle instance, not an IO::Handle object.

You could try

use FileHandle;

at the top of the script, instead of IO::Handle. Alternatively, change your code so that $file_handle is no longer a FileHandle instance.

PS: you really shouldn't be running 5.10.0, it's got quite a few bugs. 5.10.1 or anything newer is a lot better.