in reply to Need help in parsing an input
Hello sandeepda, and welcome to the Monastery!
If I’ve understood your question correctly, the following script should give you an idea of how to proceed:
#! perl use Modern::Perl; my %ports; while (<DATA>) { next unless /^http/; my @records = split /\s+/; if (exists $ports{$records[2]}) { warn "Attempt to give port $records[2] a second name"; } else { $ports{$records[2]} = $records[0]; } } say join(' and ', get_listener_name($_)) for 6712, 4516; sub get_listener_name { my ($port_to_be_checked) = @_; my @results = ('FALSE', 'a1=null'); if (exists $ports{$port_to_be_checked}) { @results = ('TRUE', 'a1=' . $ports{$port_to_be_checked} . '(li +stener name)'); } return @results; } __DATA__ name ip port ------------------------------------ http-listener-1 * 6712 http-listener-2 * 8709
Output:
21:40 >perl 486_SoPW.pl TRUE and a1=http-listener-1(listener name) FALSE and a1=null 21:40 >
Hope that helps,
| Athanasius <°(((>< contra mundum | Iustus alius egestas vitae, eros Piratica, |
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Need help in parsing an input
by sandeepda (Novice) on Jan 17, 2013 at 12:29 UTC | |
by Athanasius (Archbishop) on Jan 17, 2013 at 13:07 UTC | |
by sandeepda (Novice) on Jan 17, 2013 at 13:23 UTC | |
by 2teez (Vicar) on Jan 17, 2013 at 14:15 UTC | |
by sandeepda (Novice) on Jan 17, 2013 at 14:25 UTC |