Please support our Perl advertiser: Programming Forums
Views: 3348 | Replies: 2
![]() |
•
•
Join Date: Jun 2005
Location: /dev/null
Posts: 10
Reputation:
Rep Power: 4
Solved Threads: 0
•
•
•
•
Originally Posted by bigfoot_80906
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?
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/,$_);
}
##############################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"
![]() |
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)





Linear Mode