in reply to Re: Reading Multiple Input Files
in thread Reading Multiple Input Files

Good call! I used

for ($i=0; $i<$Num_of_Files; $i++) { open(Read, $file[$i]); @Read = <Read>; ...}

I used this instead of for my $file1 (@filenames) { ... } so I could assign a name for each of the output files.

A coworker suggested that I use use strict but I don't see the usefulness of this. Why do you use it?

Replies are listed 'Best First'.
Re^3: Reading Multiple Input Files
by Old_Gray_Bear (Bishop) on May 27, 2011 at 23:24 UTC
    I had a node around here about why to use strict....

    Ah, here it is -- On Commenting Out 'use strict;' .... It's a tad dusty, I wrote it three or four jobs back, but it is still applicable.

    ----
    I Go Back to Sleep, Now.

    OGB

Re^3: Reading Multiple Input Files
by CountZero (Bishop) on May 28, 2011 at 07:18 UTC
    Ouch, C-style for loops in Perl.

    A more Perlish approach is

    while ( my ($index, $file) = each @filenames) {... }

    No need to calculate the number of files, you don't need to use indexes to access the filename and you still have the $index variable to use in composing the output filenames.

    CountZero

    A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James

        Oops, sorry indeed. I forgot to mention I run everything under "use Modern::Perl;";

        CountZero

        A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James

Re^3: Reading Multiple Input Files
by Anonymous Monk on May 27, 2011 at 23:24 UTC