Re: What with this open file descriptor/"Read on closed filehandle " stuff?
From: Ben Morrow (usenet_at_morrow.me.uk)
Date: 03/04/04
- Next message: Tony Muler: "Re: new to perl"
- Previous message: Tony Muler: "Re: new to perl"
- In reply to: Rex Gustavus Adolphus: "Re: What with this open file descriptor/"Read on closed filehandle " stuff?"
- Next in thread: Rex Gustavus Adolphus: "Re: What with this open file descriptor/"Read on closed filehandle " stuff?"
- Reply: Rex Gustavus Adolphus: "Re: What with this open file descriptor/"Read on closed filehandle " stuff?"
- Reply: Rex Gustavus Adolphus: "Re: What with this open file descriptor/"Read on closed filehandle " stuff?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Thu, 4 Mar 2004 13:19:20 +0000 (UTC)
[please wrap attribution lines at 72 columns]
uffesterner@spamhole.com (Rex Gustavus Adolphus) wrote:
> Ben Morrow <usenet@morrow.me.uk> wrote in message
> news:<c14sju$c84$1@wisteria.csv.warwick.ac.uk>...
> >
> > You don't really need to declare these up here: it's better to keep
> > variables in as small a scope as possible, and simply declare them the
> > first time you use them.
>
> I guess this is mostly a matter of personal taste (TMTOWTDI), or is
> there any special reason your way is better?
It is not so much a matter of taste as a matter of good programming
practice. If variables are declared in the smallest scope possible
there is the minimal chance of confusion with other variables of the
same name. Also, it is then (usually) possible to see at a glance the
whole scope the variable is valid over.
> > Don't call subs with & unless you need to (here you don't).
>
> Isn't this another case of TMTOWTDI?
No, the two different ways of calling subs have different semantics (see
perlsub). Even if it makes no difference in this case, it will confuse
someone else reading your code (they will spend time trying to work out
why you needed the &-semantics).
> > On older perls (pre-5.6), glob is performed by forking a csh(1). This is
> > a Bad Thing, so it was replaced with File::Glob in 5.6.
>
> But even if it is performed that way, why is the program running out
> of file descriptors eventually?
> Seems to me like a bug in the pre-5.6-glob() or File::Copy::move then.
Yes, it does; unless you are performing many globs simultaneously?
> But File::Glob isn't available right now (pre-5.6 perl as it is),
> so I figure I could do it this way:
But you can install File::Glob from CPAN and use that. It is a much
better solution. (See the FAQ if you don't have root to install new
modules globally.)
> I forgot to mention it in my first post, but more often than not
> there's
> actually no need to glob() at all since $filename seldom contains
> wildcards.
>
> I change this code
> @files = glob($filename);
> to this:
> $_ = $filename;
> # check for existence of ? and/or *
> if ( m/.*[\?|\*].*/ ) {
> @files = glob($filename);
> } else {
> push(@files,$filename);
> }
>
> It's not a perfect solution, but will at least make the number of
> glob()-call much less.
There is still a bug waiting to bite, though.
> I guess it won't help much if the real problem is the
> File::Copy::move-call
Just for the hell of it, you could try installing the latest version of
File::Copy from CPAN as well.
Ben
-- don't get my sympathy hanging out the 15th floor. you've changed the locks 3 times, he still comes reeling though the door, and soon he'll get to you, teach you how to get to purest hell. you do it to yourself and that's what really hurts is you do it to yourself just you, you and noone else ** ben@morrow.me.uk
- Next message: Tony Muler: "Re: new to perl"
- Previous message: Tony Muler: "Re: new to perl"
- In reply to: Rex Gustavus Adolphus: "Re: What with this open file descriptor/"Read on closed filehandle " stuff?"
- Next in thread: Rex Gustavus Adolphus: "Re: What with this open file descriptor/"Read on closed filehandle " stuff?"
- Reply: Rex Gustavus Adolphus: "Re: What with this open file descriptor/"Read on closed filehandle " stuff?"
- Reply: Rex Gustavus Adolphus: "Re: What with this open file descriptor/"Read on closed filehandle " stuff?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|