Ask a Question related to PERL Miscellaneous, Design and Development.
-
ed #1
file name of file that reference to type glob points to
Hey all. This is probably a elementary question, but I can't
seem to be able to find a builtin function or combination of functions
that will let me achieve this.
I want to get the full path to a file that is pointed to from a
reference to a type glob.
Below is a simple example of what I want to do.
## start perl script ##
use strict;
use warnings;
open(FH, '<', './testees/noname4.html')
or die("can't open file: $!");
&doSomething(\*FH);
close FH;
sub doSomething
{ my $FH = shift;
# I need the name of the file that
# $FH points to, to do something!
# something like filename($FH) would be nice.
}
## end perl script ##
There's a few things I can do to get around this problem.
But now I'm just curious of how this could be done.
tia,
--ed
ed Guest
-
Linked file uploaded - link still points to local file
Hi, We are faced with a strange problem in one of your Contribute sites: 2 users reported problems when linking and uploading files: user... -
File::Glob bug ?
The following script: use File::Glob ':glob'; my @test = ( '{random string}', '\\{random string\\}' ); for (@test) { -
HowTo Send Uploaded File with INPUT Type file to Sql Server Image Data Type
I have the following problem: I have the following form client side: <FORM.......> <FORM action="./WZUpload.asp" method="Post"... -
HowTo Send Uploaded File with INPUT Type file to Sql Server Image Data Type ?
I have the following problem: I have the following form client side: <FORM.......> <FORM action="./WZUpload.asp" method="Post"... -
variable file glob into grep without glob()
Hope I don't get shot for posting again, but I really need help with this ... I want to process lots (thousands) of files. I want to take a file... -
John W. Krahn #2
Re: file name of file that reference to type glob points to
ed wrote:
Why not just pass the file name to the sub and open it in the sub?>
> Hey all. This is probably a elementary question, but I can't
> seem to be able to find a builtin function or combination of functions
> that will let me achieve this.
>
> I want to get the full path to a file that is pointed to from a
> reference to a type glob.
> Below is a simple example of what I want to do.
>
> ## start perl script ##
> use strict;
> use warnings;
>
> open(FH, '<', './testees/noname4.html')
> or die("can't open file: $!");
> &doSomething(\*FH);
> close FH;
>
> sub doSomething
> { my $FH = shift;
> # I need the name of the file that
> # $FH points to, to do something!
> # something like filename($FH) would be nice.
> }
> ## end perl script ##
>
> There's a few things I can do to get around this problem.
> But now I'm just curious of how this could be done.
If you are running this on Linux then you can find the file name in the
/proc directory.
John
--
use Perl;
program
fulfillment
John W. Krahn Guest
-
ed #3
Re: file name of file that reference to type glob points to
On Tue, 01 Jul 2003 00:40:15 GMT, "John W. Krahn" <krahnj@acm.org>
wrote:
Well I'm creating a class where one of the arguments to the>
>Why not just pass the file name to the sub and open it in the sub?
>
constructor
can either be the path to the file to open, or an open filehandle.
Since more than one object is likely to work with the file I thought
it would be more efficient to have the option of passing the
filehandle
around instead of having each object manually open/close the file.
The reason I need the path is not just to open the file, I need to use
the path to make some modifications to it, then do something with it.
I could make it so the first parameter is either undef or a
filehandle, then they could pass the path in the second argument.
I could offer two ways of creating the object:
method 1:
#this would open the file using $path
$obj = new Obj(undef, $path, 'param3');
method 2:
#this doesn't need to open the file, but it still gets the
#path to the file it's working on from $path supplied in
#the second argument
$obj = new Obj(\*FH, $path, 'param3');
So if the first argument is undefined I'll open the file using the
value
supplied in the second argument, and then I also have the path to the
stuff I need to do with it.
If the file's already opened they can send the filehandle instead of
an undefined
value.
--ed
ed Guest
-
ed #4
Re: file name of file that reference to type glob points to
On Mon, 30 Jun 2003 19:45:10 -0500, [email]tadmc@augustmail.com[/email] (Tad
McClellan) wrote:
I just posted trying to explain it.>
>Why do you want to get the full path to a file that is pointed to from a
>reference to a type glob?
>
In the context of my object the files will always be text/* type>
>What "name" should it use when the FH is not associated with any file?
>
>eg:
>
> open FH, 'ls|' ...
>
files. Primarily Html. So the person using the object should only
pass a filehandle that points to an appropriate type of file.
But I get your point that filehandles can point to things that aren't
really files. So I guess because of that it probably wouldn't make
much sense for the language to provide a way to get the file name when
there doesn't necessarily have to be a name associated with it.
I think I should be ok though using the method I described in my last
post.
If you see any flaws in the method I described in my last post, please
let me know.
thanks,
--ed
ed Guest



Reply With Quote

