I am reading from a text file with two columns. The first column contains the name of a device, and the second column contains the IP address for this device. how do i get the name and address and assign them to separate variable names?

I am reading from a text file with two columns. The first column contains the name of a device, and the second column contains the IP address for this device. how do i get the name and address and assign them to separate variable names?

not really sure what you meant by two columns. Is it seperated by a tab?
a space? Or did you mean 2 rows?
I'll put in an example for both. ;)

###.seperated by a single space.###
#example name 123.123.123.123
open(fh,"<file") || die "error $!\n";
my @string;
my ($name,$ip);
         while(<fh>) {
         chomp;
         ($name,$ip)=split(/ /,$_);
         ##################
         #Process next
         }
################################
########seperated by a tab or more than 1 space ###########
while(<fh>) {
chomp;
s/\s/xmarkx/;
s/\s//g;
($name,$ip)=split(/xmarkx/,$_);
}

##############################

hope that helps

You can also go and read the perl manpage.
type "man perlretut" for regex examples and definition on linux.
on windows you can type >"perldoc perlretut"

thank you, that helps a lot

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.