David <[EMAIL PROTECTED]> wrote: > Steve Grazzini wrote: >> >> And besides, open() is not particularly easy to >> override. You'd have to account for all of: >> >> open FH, $path; >> open FH, "> $path"; >> open FH, ">", $path; >> open FH, ">", \$sstream; >> open FH, "command |"; >> open FH, "| command"; > > i don't recommand people do all of the above. if > the need arise to access the open() function that > came with Perl, CORE::open() is good enough.
Right -- you don't want to implement open(), just validate the arguments before calling the builtin. But there are still two issues. 1) Before validating a path, you have to determine whether you've been passed one, since several standard forms of open() don't open a regular file at all. I left out a few of these: open FH, "<&stdin"; # dup STDIN open FH, "<&0"; # ditto open FH, "-"; # ditto open FH, "|-"; # fork + pipe And I've probably *still* forgotten others. 2) You can't break the semantics of the builtin. This means you have to turn the first argument (a string, a globref, an undefined scalar, etc) into a filehandle. And then you need to call the builtin with the correct number and type of arguments. This is also trickier than it appears on first blush. Look what happens when you try: use subs qw/open/; sub open { CORE::open(@_) } open IN, $0 or die "open: '$0': $!\n"; print while <IN>; Anyway there's a lot to learn in IPC/Open3.pm if the OP really wants to do this. -- Steve perldoc -qa.j | perl -lpe '($_)=m("(.*)")' -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]