in reply to read files into 2D arrays and print element?

you are pushing your matrices successively into the same @list for all files.

print $list[3*$n][0] to get the upper left element from matrix $n (starting with 0)

Please next time indent your code properly, it's not nice to force us struggling thru this.

Cheers Rolf
(addicted to the Perl Programming Language and ☆☆☆☆ :)
Je suis Charlie!

Replies are listed 'Best First'.
Re^2: read files into 2D arrays and print element?
by fasoli (Beadle) on Nov 29, 2016 at 17:14 UTC

    I'm sorry about the lack of indentation - I don't know how to indent and, you'll probably be shocked by this, but this is actually me doing a good job at indenting... It's crap I know, it also makes me struggle. All I wanted to say with this is that this wasn't lazy formatting, this was just me not having a clue.

    I've tried to understand it but it goes over my head as all the tips I've read are probably more intuitive rather than explanatory, or they assume certain fluency in perl/general programming. I apologise for the bad formatting, I need to learn how to do it at some stage.

      Essentially, any time you are operating in a block (typically defined by statements that use { and } to denote a block), you indent a single time:

      for (@things){ # this is a block. indent once if ($_ eq 'blah'){ # this is an inner block, indent twice while (1){ # 2nd level inner block # indent three times } if (0){ # another 2nd level inner block } # back in 1st inner block } # back in outer block } # back to top level

      In that case you could do a lot worse than perltidy.

      > I don't know how to indent

      My editor does it for me, which one do you use?

      I'm sure you'll find someone here telling you how to do it there.

      Cheers Rolf
      (addicted to the Perl Programming Language and ☆☆☆☆ :)
      Je suis Charlie!

        I am using either vi or gedit. I think Notepad++ helps a bit but I can't get it on some computers (Uni computers, can't download stuff etc).

        I understood indenting is done in blocks, as it was also pointed out earlier. As in, when something *separate* from the other things is happening, I should indent. But I don't think I was doing it correctly.

        Can I bother you all with one more thing? I've commented on my question asking one more thing, hopefully you'll be able to point what I'm doing wrong? I've spent days on this bit and still no luck.