dru145 has asked for the wisdom of the Perl Monks concerning the following question:
I am trying to save the ip, server name, port #, service, and description to separate arrays, but I'm having trouble since the data is not all on one line. Should I try and join the lines first? Here is what I have so far. I'm able to capture the ip and server name, but it fails to capture the rest. I know it's because of my next unless (/\*/); statement. I'm thinking I need a loop statement or two to get it to do want I want, but it's just not coming to me. I would appreciate any help. TIA+ 192.168.89.1 acmeorp.acme.com |___ 21 File Transfer Protocol [Control] * + 192.168.31.3 ftp.acme.com |___ 21 File Transfer Protocol [Control] |___ 220 ftp.acme.com FTP server ready... * + 192.168.33.19 acmeftp.acme.com |___ 21 File Transfer Protocol [Control] |___ 220-acme Secure FTP Server.. WarFTPd 1.71.02 ( +Feb 14 2000) Ready.. (C)opyright 1996 - 2000 by Jarle (jgaa) Aase +- all righ * + 192.168.29.21 orcweb.acme.com |___ 21 File Transfer Protocol [Control] |___ 220 sandbox FTP server (Version 1.1.214.7 Thu Aug + 10 09:57:38 GMT 2000) ready... * + 192.168.11.22 commerce.acme.com |___ 21 File Transfer Protocol [Control] |___ 220 commerce Microsoft FTP Service (Version 4.0). +.. * + 192.168.19.24 webapp.acme.com |___ 21 File Transfer Protocol [Control] |___ 220 WEBAPP1PRI Microsoft FTP Service (Version 5.0 +)...
Thanks,#!/usr/bin/perl -w use strict; my $infile = './ftp.txt'; my $outfile = './fileout.csv'; my (@ips, @names, @ports, @service, @desc); open INFILE, "$infile" or die "Can't open $infile: $!\n"; while (<INFILE>){ chomp; next unless (/\*/); my ($ip, $name, $port, $service, $desc) = (split /\s+/)[2,3,6]; push (@ips, $ip); push (@names, $name); push (@ports, $port); } close INFILE; foreach (@ips){ print "Here are the ip's:$_\n"; } foreach (@names){ print "Here are the server names:$_\n"; } foreach (@ports){ print "Here are the ports:$_\n"; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Splitting Across Multiple Lines
by ChOas (Curate) on Mar 13, 2002 at 16:05 UTC | |
|
Re: Splitting Across Multiple Lines
by krazken (Scribe) on Mar 13, 2002 at 19:52 UTC |