'N'other way of acquiring the contents of the files ... but may not be what you want?
#! /usr/bin/perl -w use 5.018; #1123337 my @arr; my @files=("Die2.txt", "Die1.txt", "Die1.bak", ); # assumes that you have code to ID the fil +es # you want and collect them into an array for (@files) { open (my $InFile, '<', $_) or die "cannot open $_, $!"; while (<$InFile>) { my $var = $_; push @arr, $var; } } say @arr;
UPDATED: with the notes below.
And a note: If the way you phrased "... how I can get my already working script's array to read the contents of different files" is merely because English is not your native language it's not a big deal because I see I'm not the only Monk to decipher it (well, I hope we've done so accurately).
But if that phrasing accurately reflects your understanding of arrays, note that neither that array or any other can "read the contents" of anything. You have to explicitly tell Perl that you want data PUSHed onto an array... and that means you have to collect the data first -- by the method shown here, or by that in the prior ( ++ ) reply.
You could, of course, read about the record-input separator ($/, the $INPUT_RECORD_SEPARATOR ( aka "the field record separator" at Perl.com )and use that instead of the while loop above; which would spare you the need for Ln 19. Setting $/ = undef; will cause your read to slurp the entire file.
In reply to Re: How do I get different files into an array
by ww
in thread How do I get different files into an array
by amagana
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |