
Karazam
User
Mar 9, 2011, 11:29 AM
Post #13 of 16
(1239 views)
|
|
Re: [tbone587] Taking input multiples times and storing into array
[In reply to]
|
Can't Post
|
|
Not sure if you mean to read the whole file into a variable first, or extract info and put that into a variable. First case, if $mac holds the MAC address, then
open my $fh, '<', "/path/to/$mac.cfg" or die $!; my @cfg = <$fh>; for my $line ( @cfg ) { # do stuff with $line } close $fh; In the second case then rather
open my $fh, '<', "/path/to/$mac.cfg" or die $!; while (<$fh>) { # each line is now in $_, do stuff with that } close $fh; The three argument form of open with a lexical filehandle is the preferred way, although you may often see the old "open(FH, '< filename')". And always have a die after so you know if things go wrong. See perlopentut for more details.
(This post was edited by Karazam on Mar 9, 2011, 11:32 AM)
|