Re: looping questions



lerameur <lerameur@xxxxxxxxx> wrote:
Hello,

this is not a perl problem (maybe it is). The function does work, but
gave me error . there are 4 files into the traffic directory, the loop
goes into 24 possiblility, copies the four files and gives me 20
errors. I decided to add an IF statement to only copy if the file
exists. what is wrong with my IF loop ?
thanks

Ken

for my $hours ('00'..'23') {

$file23 = glob("$timestamp2$hours*") ;

You don't want to use scalar glob here. globs are kind of weird,
and it won't notice that it's argument changed until the is done iterating
through all of the files that matched its initial invocation (and has
returned undef once). Then it will look at its argument again, and start
iterating over that result. If you know that no more than one file will
match, or you only care about one of the matches in cases where there are
more than one, you could get it by using a list context:

my ($file23) = glob("$timestamp2$hours*") ;

print "$timestamp2: " ,$timestamp2, "\n";
print "file23: " ,$file23, "\n";
if ($file23 == 1){

That is wrong. It is not clear what exactly is wrong because we don't
what you want it to do.

Xho

--
-------------------- http://NewsReader.Com/ --------------------
The costs of publication of this article were defrayed in part by the
payment of page charges. This article must therefore be hereby marked
advertisement in accordance with 18 U.S.C. Section 1734 solely to indicate
this fact.
.



Relevant Pages

  • Re: lambda closure question
    ... > What I want to do is pre-load functions with arguments by iterating ... setattr(myclass, item, lamdba self: func(self, item)) ... And that's the correct explanation, ... > reference will always get modified as the loop iterates. ...
    (comp.lang.python)
  • Re: Iterate through member variables of a class
    ... I did that because the OP was asking about iterating through member ... variables of a class by using a while loop. ... you can add or remove elements from the array and the ... So it would be better if I declared the int as a size_t instead? ...
    (comp.lang.cpp)
  • Re: Holding Returned Data in Arrays
    ... whether or not new items are available whilst you loop depends on the ... implementation of the thing you are iterating. ... In the case of Getfiles() you can see that it returns an array. ...
    (microsoft.public.dotnet.framework.clr)
  • Re: Another question about performance
    ... Just a simple iterating 10,000,000 of int in intgive u such ... Not on my box - iterating through 10,000,000 ints using foreach ... want to do *something* with the value inside the loop... ...
    (microsoft.public.dotnet.languages.csharp)