in reply to how to put the value in proper format
But the code you show has very little to do with the output you claim or that you say you want as the vars $port, $speed and $link are neither instantiated nor assigned a value.
Downvoted, for abusing the Monastery's goodwill.
Update: Thanks jethro for msg which made me realize I'd misread the "=" in lines 8, 9 and 10 as an attempt at assignment. It isn't of course; it's merely redundant since the text includes the verb "is." However....
OP's position counts are for the header rather than the actual data... and the inclusion of commented lines that bear no relevance to the problem simply wastes the Monks' time.
#!/usr/bin/perl use 5.014; # 990400 # all global; too lazy to work hard on OP's code my ($line, $ind, $port, $speed, $link); while (<DATA>) { $line = $_; if ( $line =~ /\bup\b/ ) { print "port is ", $port, substr($line,1,2). ", "; print "speed is ", $speed, substr($line,7,5). ", "; print "link is ", $link, substr($line,42,4)."\n"; } } # NB Port 10 Link status changed to "up" (and indented as in Port 19) __DATA__ ------------------------------------------------------------------ Port Speed Duplex Flow Ctrl Link Name ---- ----- -------- --TX-----RX-- ------ ------ 1 10000 full no no down 1 2 10000 full no no down 2 3 10000 full no no down 3 4 10000 full no no down 4 5 10000 full no no down 5 6 10000 full no no down 6 7 10000 full no no down 7 8 10000 full no no down 8 9 10000 full no no down 9 10 10000 full no no up 10 11 10000 full no no down 11 12 10000 full no no down 12 13 10000 full no no down 13 14 10000 full no no down 14 15 10000 full no no down 15 16 10000 full no no down 16 17 1G/10G full no no down 17 18 1G/10G full no no down 18 19 1000 full no no up 19 20 10000 full no no down 20
Output:
C:\> 990400.pl port is 10, speed is 10000, link is up port is 19, speed is 1000, link is up
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: how to put the value in proper format
by laksh (Novice) on Aug 29, 2012 at 12:06 UTC |