in reply to how to put the value in proper format

What do you think of this?
use Modern::Perl; while (<DATA>) { # get rid of header block last if /--TX--/; }; while (<DATA>) { my ($port, $speed, $duplex, $TX, $RX, $link, $name) = split; next unless $link eq 'up'; say <<EOP; Port is $port Speed is $speed Link is $link EOP } __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 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

CountZero

A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James

My blog: Imperial Deltronics

Replies are listed 'Best First'.
Re^2: how to put the value in proper format
by ulaksh (Acolyte) on Aug 29, 2012 at 21:29 UTC

    here I dont have to use using Modern::Perl;

    need urgent help :I dont know how to check the condition like if the line contain "Link" in the first line then check the port link is up or down and if it is up then get the same out as above.

    Please let me know how to do that.
      Sorry, I am not sure if I understand your question.

      There is only one line in your file that contains the word "LINK" and that is in the second line of the header.

      Furthermore, the script already prints the information for all lines where the LINK field shows the value of "up".

      Whether you use Modern Perl is up to you, but if you do not use it, at least use strict; use warnings.

      CountZero

      A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James

      My blog: Imperial Deltronics