loadf(); PERL Sub-function
I had this for years, and for a surprise, I’m still using this sub function. It’s simple and my code gets cleaner when I use this. I just want to share this to you, and you might find some use to this. Actually, I should be creating more sub-functions for repetitive tasks. I might come up with good useful ones like this. Heh. :p
sub loadf($) {
my @file = ( );
open(FILE, $_[0] . "\n") or die("[+] Couldn't Open " . $_[0] . "\n");
@file = <FILE>;
close(FILE);
return @file;
}
Usage:
my @array = loadf("file.txt");
This is very useful, especially if you’re loading multiple files in one script. All you need are descriptive array names! That’s it for this post, and I hope this snippet is useful enough. Thanks!