barazani has asked for the wisdom of the Perl Monks concerning the following question:
-----------------------------------hostname:host1 ip:192.168.1.1 cpu:PIII other info:fjfjfjfjfjjf ::: hostname:host2 ip:192.168.1.2 cpu:PIII other info:fjfjfjfjfjjf ::: hostname:host2 ip:192.168.1.2 cpu:PIII other info:fjfjfjfjfjjf :::
#!/usr/bin/perl -w use diagnostics; $/ = ":::\n"; # define ::: as paragraph delimiter #figure out how many paragraphs are there ? open(HOSTDB,"hostdb") or die "cannot open hostdb"; $record = 0; while(<HOSTDB>){ $record++; } print "number of records - $record\n"; close(HOSTDB); open(HOSTDB,"hostdb") or die "cannot open hostdb"; $host1 = <HOSTDB>; $host2 = <HOSTDB> ; $host3 = <HOSTDB>; close(HOSTDB); chomp($host1); chomp($host2); chomp($host3); #this is just for me to see what's been proccessed ... #print "paragraph1 = $host1"; #print "--------------------------\n"; #print "paragraph2 = $host1 "; #print "--------------------------\n"; #print "paragraph3 = $host1 "; #print "--------------------------\n"; foreach( $host_record = 1 ; $host_record <= $record ; $host_record++ ) +{ print "------host.$host_record--------\n"; $field = 0; for $field (split /\n/, ${"host".$host_record}) { print "Field contains: `$field'\n"; } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: proccessing file paragraphs -braindead i am ..
by Joost (Canon) on Dec 13, 2002 at 15:04 UTC | |
by barazani (Initiate) on Dec 13, 2002 at 15:50 UTC | |
|
Re: proccessing file paragraphs -braindead i am ..
by Chady (Priest) on Dec 13, 2002 at 14:59 UTC |