Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re: passing number of files in directory to subroutine

by rev_1318 (Chaplain)
on Sep 23, 2005 at 10:47 UTC ( [id://494462]=note: print w/replies, xml ) Need Help??


in reply to passing number of files in directory to subroutine

Besides making your code more Perlish (as GrandFather said, but I'd use / instead of \\), I think the problem is in your Calc subroutine...

Anyway, the code doesn't make much sense: What order do you expect the file to be in @onedir and @twodir? You'll have to do something with them to get the right order! Maybe something as:

my @onedir = sort grep !/^\./ readdir DIR1

Paul

Replies are listed 'Best First'.
Re^2: passing number of files in directory to subroutine
by GrandFather (Saint) on Sep 23, 2005 at 11:34 UTC

    I agree wrt / versus \\ - that's my C/Windows background shining through again :).

    Pretty sure the original problem was the missing / however.

    I also think you are correct raising the issue of the file orders in the two arrays. Most OS's don't guarantee the order that files are stored in a dir and you can be pretty sure it won't be alphabetical for example. OP may be wise to sort the arrays before he uses them if the pairing order is important.


    Perl is Huffman encoded by design.
      Hi. Your code worked a treat, thanks Grandfather. As regards to the ordering of the arrays .. advice duly noted. In this case, the files are called something along these lines:
      nameoffile012298.txt
      etc .. so for one file in one directory there is a corresponding file with the exact same name and number in the other directory. Seems to be working without the need for sorting right now but I shall be watchful :)
Re^2: passing number of files in directory to subroutine
by Angharad (Pilgrim) on Sep 23, 2005 at 11:08 UTC
    OK, but I thought that if it the data was in a array the order was the same as whwn you added the values in. (unlike hashes which I know are 'unordered'). There is nothing wrong with the Calc routine by the way .. that has been throughly tested.
      I thought that if it the data was in a array the order was the same as whwn you added the values in

      Yes, but the order in which the files are added to your array are not by default in alphabetic order. Most of the time, you get then in a different order, e.g. based on inode.

      Paul

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others goofing around in the Monastery: (1)
As of 2024-04-25 19:41 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found