While that would work, since it is only a one line text file containing a single I.P. address a much simpler way would be:
#!/usr/bin/perl -w open(IPFILE, "<ipaddress"); chomp(my $ipaddress = <IPFILE>); The regex is, in this case at least, not really necessary. Note the the key here is the chomp() function which removes any newline characters in the string that gets passed to it. On Friday 02 November 2001 09:06 pm, Wagner-David wrote: > Uncertain what you are attempting to do, but: > > #!perl -w > while ( <DATA> ) { > chomp; > if ( /^(\d+\.\d+.\d+\.\d+)/ ) { #Extact the IP address here and stote as > $1 print "$1\n"; > } > } > __DATA__ > 192.168.0.2 > This should not print > > 199.88.22.111 > ^-------- Script ends here > Output: > 192.168.0.2 > 199.88.22.111 > > > Wags ;) > > -----Original Message----- > From: Daniel Falkenberg [mailto:[EMAIL PROTECTED]] > Sent: Friday, November 02, 2001 16:19 > To: [EMAIL PROTECTED] > Subject: Silly problem > > > G'day All, > > I have this very very simple problem that I can't figure out. Basically > I have a 1 line text file with an IP address in it like so... > > 192.168.0.2 > > Now all I want to do is open this file up and extract the IP address > from it. Now the good thing is I can do this OK but whenever I extract > it it seems to be appending a new line on the end of it. Can some one > help me and give me some ideas on what I am doing wrong? My code so far > looks like this... > > open (FH, "<$file"); #...and open the textfile for reading > @line=<FH>; #Store ppp0 as an array > $line =~ /^(\d+\.\d+.\d+\.\d+)/; #Extact the IP address here and stote > as $1 > print @test; > close(FH); > > printing @test works fine but it appends a new line. The code also > won't assign $1 to the IP address? > > Is it something simple I am doing wrong? > > Regards, > > Dan > > ============================== > VINTEK CONSULTING PTY LTD > (ACN 088 825 209) > Email: [EMAIL PROTECTED] > WWW: http://www.vintek.net > Tel: (08) 8523 5035 > Fax: (08) 8523 2104 > Snail: P.O. Box 312 > Gawler SA 5118 > ============================== -- Michael D. Risser Software Engineer/Linux Administrator ============================= Machine Vision Products, Inc. www.visionpro.com [EMAIL PROTECTED] -----BEGIN PGP PUBLIC KEY BLOCK----- Version: GnuPG v1.0.6 (GNU/Linux) Comment: For info see http://www.gnupg.org mQGiBDuCrxARBADE9hdFrB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