in reply to Re: Adding to array
in thread Adding to array

Both you and GrandFather follow the original code in calling chomp() on each partial list. Your solution only works if each file contributes only one line.

Surely a single chomp() after the loop is simpler and more efficient.

Anno

Replies are listed 'Best First'.
Re^3: Adding to array
by GrandFather (Saint) on Feb 28, 2007 at 20:54 UTC

    In the context of file i/o the (most likely) very minor time difference between using chomp on the list for each file or once for the total list is completely irrelevant.

    As a style issue it seems sensible to have the chomp close to the place where the lines being chomped are generated so that it is clear why the chomp is there. It's a pretty minor issue however and the distance between the i/o and a single chomp would be small in this case any way.


    DWIM is Perl's answer to Gödel
      In the context of file i/o the (most likely) very minor time difference between using chomp on the list for each file or once for the total list is completely irrelevant.

      I mentioned efficieny to point out that there's no penalty. I am aware it won't matter in an IO context.

      As a style issue it seems sensible to have the chomp close to the place where the lines being chomped are generated so that it is clear why the chomp is there.

      You have a point there. It is offset by the intermediate array you (more or less have to) use, which is a distraction, not a clarification in this case.

      It's a pretty minor issue however and the distance between the i/o and a single chomp would be small in this case any way.

      Right.

      Anno