I have a subroutine that takes a filehandle as an argument. How do I make a filehandle from a file path specified on the command line? I don't want to do any processing of this file myself, I just want to pass it off to this other subroutine, which returns an array of hashes with all the parsed data from the file.
Here's what the comm...
I have a Windows C++ program that is doing something like:
FILE* pf = ...;
*stdout = *pf; // stdout is defined in stdio.h
I'm looking for an explanation about what happens when you change the value of the stdout file handle. Is this just a way of redirecting stdout?
-cr
...
In Unix C programming, is it considered good practice to explicitly close file handles before the process exits, or is it instead good practice to let the OS close the file handles and thus avoid unnecessary code?
Which of the two would generally be considered as the preferred alternative?
Example:
int main (int argc, char* argv[])
{
...
Is there a way to check if a file is already open in Perl?
I want to have a read file access, so don't require flock.
open(FH, "<$fileName") or die "$!\n" if (<FILE_IS_NOT_ALREADY_OPEN>);
# or something like
close(FH) if (<FILE_IS_OPEN>);
...
Hello,
I need some help understanding the following Perl code snippet. I have the following two questions.
1.
What does local *PIPER mean? Even though I've done some Perl programming before the local * syntax is new to me. Is it a pointer?
2.
What is the purpose of
curl http://www.somesite.net/cgi-bin/updateuser.cgi? -d "userid=$use...
Hi,
Does C++ have access to infile data through a filehandle? For example the typical idiom in Perl is:
while (<DATA>) {
chomp;
# do sth with $_
}
__DATA__
Foo
Bar
What's the way to do that in C++ ?
...
When I read through Programming Perl, 2nd Edition, Page 51, something confuses me :
sub newopen {
my $path = shift;
local *FH; #not my!
open (FH, $path) || return undef;
return *FH;
}
$fh = newopen('/etc/passwd');
My I know, why we are not recommenced to use my? So far, I cannot see anything will go wrong if we use...
I want to set up a pipeline of processes from within Perl (running on Linux), consisting of two parts run at separate times.
Eg:
Start the consumer process:
open( OUT, "| tar xvf - " ) || die "Failed: tar: $!";
then much later start the producer process:
open( IN, "gpg -d $file |" ) || die "Failed: gpg: $!";
but then somehow redi...
You are given either an IO::File object or a typeglob (\*STDOUT or Symbol::symbol_to_ref("main::FH")); how would you go about determining if it is a read or write handle? The interface cannot be extended to pass this information (I am overriding close to add calls to flush and sync before the actual close).
Currently I am attempting to...
Dear all,
I have the following template function which prints to cout:
template <typename T> void prn_vec(const std::vector < T >&arg, string sep="")
{
for (unsigned n = 0; n < arg.size(); n++) {
cout << arg[n] << sep;
}
return;
}
// Usage:
//prn_vec<int>(myVec,"\t");
/...
Dear all,,
I want to read line-by-line from a given input file,, process each line (i.e. its words) and then move on to other line...
So i am using fscanf(fptr,"%s",words) to read the word and it should stop once it encounters end of line...
but this is not possible in fscanf, i guess... so please tell me the way as to what to do...
...
I am doing a lot of image processing in GDI+ in .NET in an ASP.NET application.
I frequently find that Image.FromFile() is keeping a file handle open.
Why is this? What is the best way to open an image without the file handle being retained.
NB: I'm not doing anything stupid like keeping the Image object lying around - and even if I ...
I have a list of filenames. I have to create a file for each of those names, write lines to the various files (in no particular order), then close them.
How can I do that in perl? I envision something like the following code (which will not work in that form and give syntax errors):
my @names = qw(foo.txt bar.txt baz.txt);
my @handles...
Ok, I have a bit of an issue here. I realize that I don't need to set a $handle to *::HTML to get this snippet to work, however this code is taken out of context from its use and I do in fact need this to work with the $handle. The output I am receiving is below the snippet however the output I want is for the file.html to contain "what\...
In my application comes with an uninstaller
Everything is working fine, except that I can't find no way to delete the uninstaller.exe file when it's all done.
I tried to copy the current assembly exe into a temp directory, but the file-handle of the original file is still locked...
Any ideas?
...
Hi all,
I have a third-party component that copy an image and opens it for a certain task, but it seems that it's no releasing the file handle.
I've read the documentation of that component, but it was released like in 2004 and there's a certain method to release the handle, but of course it needs an (int bmpPtr).
so it's obviously a p...
I am working on a log parsing script using Perl. I am reading the log file as follows:
open(LOGFILE, "$logFile") || die "Error opening log file $logFile\n";
while(<LOGFILE>)
{
#Processing statements goes here.
}
Now in processing statements I want to check if the file reading pointer is on the last line. if yes then wan...
Hi,
I'm trying to read from two files, and generate output in a third. I first wanted to edit the first one on the go but I didn't find a suitable method save for arrays.
My problem is that the third file (output) is empty whenever I uncomment the "_ref_param_handling" function. BUT the following is what puzzles me the most: If I do a ...
I have an application that IMPLICITLY opens a handle on a dll/file. At some point in the application, I want to release this handle. How can I do it? My application is in C#.
...
I want to add a line to top and bottom of the file. I can do it following way.
open (DATA, "</usr/old") || die "cant open old\n"; #file to which line has to be added
my @body=<DATA>;
close(DATA);
open (FILE, ">/usr/new") || die "cant open new\n"; #file after stuff has been added
print FILE "9 431";
print FILE "\n";
my $body=@bod...