Re: What with this open file descriptor/"Read on closed filehandle " stuff?

From: Ben Morrow (usenet_at_morrow.me.uk)
Date: 03/04/04


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


Relevant Pages

  • Re: Garbage collection problem
    ... The whole point of optimization is to ... > same camp as Chris Smith on the matter. ... declare a scope for the variable I may be depending on the object remaining ...
    (comp.lang.java.programmer)
  • Re: Are low/lower cost USB Oscilloscopes any good?
    ... The company I work for doesn't have much of a budget for test equipment, but we have a budget for boards so I was considering making a pretty fast scope / analyser using a quad set of 500MS/s A-Ds and a couple of fast FPGAs and some memory. ... They couldn't find the RTL chips anymore for repairs, and some new buildings going in were going to cut some of those custom multi-core twinax cables and they couldn't replace or re-run them. ... He then gave the cable tech a student helper to help run the cables and install all the electical boxes. ... Power, TT control signal, ground, lighting control power, and the lighting level signal. ...
    (sci.electronics.design)
  • Re: Are low/lower cost USB Oscilloscopes any good?
    ... One of the advantages of a PC based scope is that it doesn't take ... going to cut some of those custom multi-core twinax cables and they ... run the cables and install all the electical boxes. ... Power, TT control signal, ground, lighting control power, and the ...
    (sci.electronics.design)
  • Re: Are low/lower cost USB Oscilloscopes any good?
    ... One of the advantages of a PC based scope is that it doesn't take ... going to cut some of those custom multi-core twinax cables and they ... run the cables and install all the electical boxes. ... Power, TT control signal, ground, lighting control power, and the ...
    (sci.electronics.design)
  • Re: Are low/lower cost USB Oscilloscopes any good?
    ... The company I work for doesn't have much of a budget for test equipment, but we have a budget for boards so I was considering making a pretty fast scope / analyser using a quad set of 500MS/s A-Ds and a couple of fast FPGAs and some memory. ... They couldn't find the RTL chips anymore for repairs, and some new buildings going in were going to cut some of those custom multi-core twinax cables and they couldn't replace or re-run them. ... He then gave the cable tech a student helper to help run the cables and install all the electical boxes. ... Power, TT control signal, ground, lighting control power, and the lighting level signal. ...
    (sci.electronics.design)