Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re^3: (Perl6) Groking Continuations (_!)

by tye (Sage)
on Apr 08, 2003 at 21:45 UTC ( [id://249087]=note: print w/replies, xml ) Need Help??


in reply to Re: Re: (Perl6) Groking Continuations (iterators)
in thread (Perl6) Groking Continuations

You've managed to lose another side effect. With your version, I can't use -x _ to see if the file that the iterator just handed to me is executable. I'd have to do another stat rather than using the results of the lstat that Perl so helpfully caches for me.

So you compressed all of the different items from the stack into two stacks that you keep handy using a closure (rather than a more tradition Perl object). I like it.

I agree that the chdir side-effect is problematic. Too bad Unix didn't provide an efficient way to save/restore chdir context (based on i-node instead of on a path string). I'd make the chdir optional with appropriate disclaimers in the documentation but that defeats the purpose of providing a simple example.

I think I'll try this technique on File::KGlob::unbrac (well, using a closure would be cheating since those subroutines are still Perl4-compatible code, though). (:

Thanks for the demonstration.

                - tye

Replies are listed 'Best First'.
Re: (Perl6) Groking Continuations (_!)
by Dominus (Parson) on Apr 09, 2003 at 17:36 UTC
    Says tye:
    Too bad Unix didn't provide an efficient way to save/restore chdir context (based on i-node instead of on a path string).

    Many unixes now provide an fchdir call which does what you want; instead of a pathname, it accepts an open file descriptor and then sets the cwd to the directory pointed to by the descriptor. To save the old cwd, you simply open the current directory. After you've done chdir, you can fchdir to the descriptor returned by the open when you want to go back.

    You can't have a system call that simply accepts an i-number, because such a call would bypass the filesystem's permission controls.

    --
    Mark Dominus
    Perl Paraphernalia

      Well, you probably could, but that would hardly be any more efficient than using a string path (trace up the .. chain instead of down the path of given directory names).

      Makeshifts last the longest.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://249087]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others meditating upon the Monastery: (5)
As of 2024-03-19 09:33 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found