![]() |
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 |
Re: file name of file that reference to type glob points to
ed wrote:
> > 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. Why not just pass the file name to the sub and open it in the sub? If you are running this on Linux then you can find the file name in the /proc directory. John -- use Perl; program fulfillment |
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: > >Why not just pass the file name to the sub and open it in the sub? > Well I'm creating a class where one of the arguments to the 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 |
Re: file name of file that reference to type glob points to
On Mon, 30 Jun 2003 19:45:10 -0500, tadmc@augustmail.com (Tad
McClellan) wrote: > >Why do you want to get the full path to a file that is pointed to from a >reference to a type glob? > I just posted trying to explain it. > >What "name" should it use when the FH is not associated with any file? > >eg: > > open FH, 'ls|' ... > In the context of my object the files will always be text/* type 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 |
| All times are GMT. The time now is 12:30 AM. |
Powered by vBulletin®. Copyright ©2000 - 2013, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.