Professional Web Applications Themes

file name of file that reference to type glob points to - PERL Miscellaneous

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 ...

  1. #1

    Default 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

  2. #2

    Default 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
    John W. Krahn Guest

  3. #3

    Default Re: file name of file that reference to type glob points to

    On Tue, 01 Jul 2003 00:40:15 GMT, "John W. Krahn" <krahnjacm.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
    ed Guest

  4. #4

    Default Re: file name of file that reference to type glob points to

    On Mon, 30 Jun 2003 19:45:10 -0500, [email]tadmcaugustmail.com[/email] (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


    ed Guest

Similar Threads

  1. Linked file uploaded - link still points to local file
    By jgorres in forum Macromedia Contribute General Discussion
    Replies: 0
    Last Post: March 22nd, 10:05 AM
  2. File::Glob bug ?
    By Jaap Karssenberg in forum PERL Modules
    Replies: 0
    Last Post: June 28th, 01:39 AM
  3. Replies: 3
    Last Post: October 18th, 06:56 AM
  4. Replies: 2
    Last Post: October 16th, 08:29 AM
  5. variable file glob into grep without glob()
    By qanda in forum PERL Miscellaneous
    Replies: 1
    Last Post: September 15th, 08:27 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139