Keep It Simple, Stupid | |
PerlMonks |
Re^3: Array from list in input file?by Athanasius (Archbishop) |
on Dec 01, 2015 at 14:30 UTC ( [id://1149046]=note: print w/replies, xml ) | Need Help?? |
Hello SandraA, and welcome to the Monastery! Please enclose your code in <code> ... </code> tags, that will make it much easier to read (and $linearray[2] will display correctly). Your approach is essentially the same as that given by muba, and it should work fine, except:
...is there some smarter and better way? Well, if you’re into one-liners, then (assuming your data is in, say, a file called “data.txt” in the current directory) you can do this:
The -a, -n, and -E switches are explained in perlrun. But code stored in a file is, IMO, easier to debug, reuse, and maintain. Hope that helps,
In Section
Seekers of Perl Wisdom
|
|