RSS Forums RSS
Please support our Perl advertiser: Programming Forums
Views: 3348 | Replies: 2
Reply
Join Date: Jun 2005
Posts: 17
Reputation: bigfoot_80906 is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 0
bigfoot_80906 bigfoot_80906 is offline Offline
Newbie Poster

finding a character string

  #1  
Jun 15th, 2005
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?
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Jun 2005
Location: /dev/null
Posts: 10
Reputation: JEt3L is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 0
JEt3L JEt3L is offline Offline
Newbie Poster

Re: finding a character string

  #2  
Jun 16th, 2005
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?
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"
Reply With Quote  
Join Date: Jun 2005
Posts: 17
Reputation: bigfoot_80906 is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 0
bigfoot_80906 bigfoot_80906 is offline Offline
Newbie Poster

Re: finding a character string

  #3  
Jun 16th, 2005
thank you, that helps a lot
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes
Forums | Blogs | Tutorials | Code Snippets | Whitepapers | RSS Feeds | Advertising
All times are GMT -4. The time now is 11:58 am.
Newsletter Archive - Sitemap - Privacy Statement - Acceptable Use Policy - Contact Us
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC