Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
I'm trying to parse CLI output but occasionally have a column with no data. Any regex tricks I can use to capture that? Here is my code:
use strict; use warnings; use Data::Dumper; my $string = ""; my @data = (); while(<DATA>) { push @data, $_; $_ =~ s/\n/ /g; $string .= $_; } my %hash = (); foreach ( @data ) { chomp; my @array = split (/\s+/, $_); print Dumper(@array); print "\n"; } __DATA__ Port Alias Oper Admin Speed Duplex Type (truncated) Status Status (bps) ------------ ---------------- -------- ------- ------ ------- -------- +---------- vlan.0.4094 up up other host.0.1 up up 10.0M other ge.1.1 down up 10.0M half 10-t + rj45 ge.1.2 down up 10.0M half 10-t + rj45 ge.1.3 down up 10.0M half 10-t + rj45 ge.1.4 down up 10.0M half 10-t + rj45 ge.1.5 down up 10.0M half 10-t + rj45
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: regex help
by moritz (Cardinal) on Sep 15, 2009 at 13:34 UTC | |
by desemondo (Hermit) on Sep 16, 2009 at 10:29 UTC | |
Re: regex help
by dHarry (Abbot) on Sep 15, 2009 at 13:44 UTC | |
Re: regex help
by grizzley (Chaplain) on Sep 16, 2009 at 07:04 UTC | |
Re: regex help
by ph0enix (Friar) on Sep 16, 2009 at 13:20 UTC |
Back to
Seekers of Perl Wisdom