S
surfunbear
This is a problem I often have. I would like to know if there
is a good alternative to using a temporary file.
Suppose I have:
$cmd = "ps -ef | grep $myuserid";
I could then do something like:
`$cmd > $tmpfile`;
open(TMP, $tmpfile);
while(<TMP>)
{
# various complex patterns processed etc.
...
...
}
It seems a little messy creating a temporary file and so on.
That's how I usually do it, but to do it right you have to
make it unique with pid as part of the name, make sure you delete it
when your done etc. On some machine the path to the temporary file may
change and so on.
What I really want to do is somehow run these piped commands from
inside
my script and then read the results in memory ideally or in a temporary
file. I read you can create a temporary file with a handle, but since
it has no name, I can't pipe to it.
The version of perl we have at work does not have File::Temporary, but
even if it did, I'm not sure I could get a filename recognizable by an
execed shell, I did read the method using IO::File, but it's the same
thing with that of course.
is a good alternative to using a temporary file.
Suppose I have:
$cmd = "ps -ef | grep $myuserid";
I could then do something like:
`$cmd > $tmpfile`;
open(TMP, $tmpfile);
while(<TMP>)
{
# various complex patterns processed etc.
...
...
}
It seems a little messy creating a temporary file and so on.
That's how I usually do it, but to do it right you have to
make it unique with pid as part of the name, make sure you delete it
when your done etc. On some machine the path to the temporary file may
change and so on.
What I really want to do is somehow run these piped commands from
inside
my script and then read the results in memory ideally or in a temporary
file. I read you can create a temporary file with a handle, but since
it has no name, I can't pipe to it.
The version of perl we have at work does not have File::Temporary, but
even if it did, I'm not sure I could get a filename recognizable by an
execed shell, I did read the method using IO::File, but it's the same
thing with that of course.