in reply to Re: trying to read files in @ARGV but getting GLOB error! :(
in thread trying to read files in @ARGV but getting GLOB error! :(

Oh! Good to know, thanks so much. That'll be so useful for the future. And no, you're right, I don't want to push the $i-file repeatedly, that was a mistake.

Thank you so much!

There is something strange happening though, I think it's because there is something wrong in this bit

for ($i=1; $i<=3; $i++) { open $input1, '<', "$path\/File-$molec1-cluster$i.out" or die $!; push @ARGV, "$path\/File-$molec1-cluster$i.out"; for ($j=2; $j<=3; $j++) { open $input2, '<', "$path\/File-$molec2-cluster$j.out" or die $!; push @ARGV, "$path\/File-$molec2-cluster$j.out";

When I print the contents of the files, the result is completely chaotic. I would expect the printing to be sequential like so

1st print file molec1-$i=1

2nd print file molec1-$i=2

3rd print file molec1-$i=3

4th print file molec2-$j=2

5th print file molec2-$j=3

but in my case the end result is a combination of $i-file with only the second option of $j-file repeated ($j=3), while the $j=2 is completely ignored.

What i'm getting is:

1st print file molec1-$i=1

2nd print file molec2-$j=3

3rd print file molec1-$i=2

4th print file molec2-$j=3 (repeat)

5th print file molec1-$i=3

6th print file molec2-$j=3 (repeat)

I don't understand why this pattern appears...?

Replies are listed 'Best First'.
Re^3: trying to read files in @ARGV but getting GLOB error! :(
by zentara (Cardinal) on Jun 26, 2017 at 12:43 UTC
    for ($i=1; $i<=3; $i++) { open $input1, '<', "$path\/File-$molec1-cluster$i.out" or die $!; push @ARGV, "$path\/File-$molec1-cluster$i.out"; for ($j=2; $j<=3; $j++) { open $input2, '<', "$path\/File-$molec2-cluster$j.out" or die $!; push @ARGV, "$path\/File-$molec2-cluster$j.out";

    I don't understand why this pattern appears...?

    Hi, it does look odd. The only thing I see is missing } sub-ending brackets in your code, maybe that missing sub closure is important. As always, a small-self-contained working example would be useful here. Because usually, when you need to make an example, you see the error yourself.


    I'm not really a human, but I play one on earth. ..... an animated JAPH
      No, the script has no syntax errors if that's what you mean by } sub-ending bracket missing? I just copied and pasted it quickly to show that I think this is where the problem lies. I still can't figure it out and it's been hours. I'll be posting an updated version of the script with an output included, I really can't figure this out :(

        Please pay heed to zentara's advice about the Short, Self-Contained, Correct Example: "a small-self-contained working example would be useful here. ... usually, when you ... make an example, you see the error yourself." Even if you never present this to anyone else, I know from personal experience that it can be enormously useful in debugging.


        Give a man a fish:  <%-{-{-{-<

        My other thought is maybe you have hyperthreading enabled on a multiple core computer, and it's gone haywire. :-) My suggestion is to start printing out $i and $j and your @array and your @ARGV at key points in the code and see what happens as it loops thru.

        I'm not really a human, but I play one on earth. ..... an animated JAPH