Perl Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming LanguagesPerl Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old August 29th, 2012, 08:01 AM
lakshmikant lakshmikant is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2010
Posts: 12 lakshmikant User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 59 m 6 sec
Reputation Power: 0
How to get the value of using condition check

I have a file
------------------------------------------------------------------
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

and my script is
open FILE,"interfacelink.txt" or die "cannot open file : $!";
my ($line, $ind, $port, $speed, $link);
$ind=$line=~ /Link/;
while (<FILE>) {

$line = $_;
if ( $line =~ /\bLink\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";

}

}

when I run the script I got the output
port is 19, speed is 1000, link is up

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

Last edited by lakshmikant : August 29th, 2012 at 08:11 AM. Reason: checking one more condition

Reply With Quote
  #2  
Old August 29th, 2012, 08:55 AM
FishMonger FishMonger is offline
Contributing User
Dev Shed Intermediate (1500 - 1999 posts)
 
Join Date: Apr 2009
Posts: 1,678 FishMonger User rank is General 3rd Grade (Above 100000 Reputation Level)FishMonger User rank is General 3rd Grade (Above 100000 Reputation Level)FishMonger User rank is General 3rd Grade (Above 100000 Reputation Level)FishMonger User rank is General 3rd Grade (Above 100000 Reputation Level)FishMonger User rank is General 3rd Grade (Above 100000 Reputation Level)FishMonger User rank is General 3rd Grade (Above 100000 Reputation Level)FishMonger User rank is General 3rd Grade (Above 100000 Reputation Level)FishMonger User rank is General 3rd Grade (Above 100000 Reputation Level)FishMonger User rank is General 3rd Grade (Above 100000 Reputation Level)FishMonger User rank is General 3rd Grade (Above 100000 Reputation Level)FishMonger User rank is General 3rd Grade (Above 100000 Reputation Level)FishMonger User rank is General 3rd Grade (Above 100000 Reputation Level)FishMonger User rank is General 3rd Grade (Above 100000 Reputation Level)FishMonger User rank is General 3rd Grade (Above 100000 Reputation Level)FishMonger User rank is General 3rd Grade (Above 100000 Reputation Level)FishMonger User rank is General 3rd Grade (Above 100000 Reputation Level) 
Time spent in forums: 1 Month 2 Weeks 3 Days 19 h 9 m 28 sec
Reputation Power: 1170
The code you posted won't produce the results that you stated from the sample data you posted.

Based on you sample data, I'd loop over the lines skipping any that don't start with a number, then use the split function to breakup the line into their separate fields. If you use an array slice, you can extract just the 3 needed fields instead of all 7.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPerl Programming > How to get the value of using condition check

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap