Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re: how to put the value in proper format

by johngg (Abbot)
on Aug 29, 2012 at 09:26 UTC ( #990414=note: print w/replies, xml ) Need Help??


in reply to how to put the value in proper format

If you want your output for the chosen port to be all on one line, as might be suggested by the last line of your post, don't put the line feeds (\n) in the first two print statements.

However, it does not look like the output you show was produced by that code, the equals sign is after the port/speed/link values in the print statements. Using substr here seems like a lot of hard work and is potentially fragile. I think it would be better to split the line.

$ perl -Mstrict -Mwarnings -E ' > open my $inFH, q{<}, \ <<EOF or die $!; > ------------------------------------------------------------------ > 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 down 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 > EOF > > while ( <$inFH> ) > { > next unless m{^\s*\d}; > my( $port, $speed, $link ) = ( split )[ 0, 1, 5 ]; > next unless $link eq q{up}; > say qq{port is = $port: speed is = $speed: link is = $link}; > }' port is = 19: speed is = 1000: link is = up $

I hope this is helpful.

Cheers,

JohnGG

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://990414]
help
Chatterbox?
[shmem]: holli: all of our machinery is more perfect in its realm than any human being in theirs (Günther Anders), which doesn't mean not having fun, albeit dangerous sometimes.
[ww]: That's a big "if", holli.
[holli]: well the google car drove 5 times as far as the average human without an accident didnt it?
[ww]: Less than confident that ai+hardware is up (yet) to randomness and counterintuitive behavior on streets of NY
[ww]: (and having lived both, Boston traffic challenges are even >.

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (12)
As of 2017-11-21 13:18 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    In order to be able to say "I know Perl", you must have:













    Results (301 votes). Check out past polls.

    Notices?