Perl
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
Go Back   Web Development Archives Mailing Lists Perl

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Web Development Archives Sponsor:
  #1  
Old July 4th, 2008, 06:20 AM
jet speed
Guest
Dev Archives Newbie (0 - 499 posts)
 
Posts: n/a  
Time spent in forums:
Reputation Power:
Optimize the script

Hi All,

I put togather a piece of code with some help, to capture the output as
below from a file "cxout1" as below. I am sure this can be written in few
lines or even differnt way of getting the same out put with use of hash etc.
Kindly help me to optimize the code. Any help would be much appericated.

output from the script


The Clarion Array Serial Number is CK200061101100

LUN INF PLICY-TYPE WNER PSEUD DEVICE
LUN 415 policy=CLAR current=SP A emcpower3a
LUN 815 policy=CLAR current=SP B emcpower4a

file contents cxout1



Pseudo name=emcpower3a
CLARN ID=CK200061101100 [JAZZ]
Logical device [LUN 415]
state=alive; policy=CLAR; priority=0; queued-I=0
: default=SP A, current=SP A

Host - Stor - -- I/ Path - -- Stats

HW Path I/ Paths Interf. Mode State Q-I
Errors

2310 pci@1c/pci@1/lpfc@4 c3t20d0s0 SP A0 active alive 0
1
2310 pci@1c/pci@1/lpfc@4 c3t21d0s0 SP A1 active alive 0
1

Pseudo name=emcpower4a
CLARN ID=CK200061101100 [JAZZ]
Logical device [LUN 815]
state=alive; policy=CLAR; priority=0; queued-I=0
: default=SP B, current=SP B

Host - Stor - -- I/ Path - -- Stats

HW Path I/ Paths Interf. Mode State Q-I
Errors

2310 pci@1c/pci@1/lpfc@4 c3t20d1s0 SP A0 active alive 0
1
2310 pci@1c/pci@1/lpfc@4 c3t21d1s0 SP A1 active alive 0
1



my code

#!/usr/bin/perl -w

use strict;
use warnings;
use List::MoreUtils qw(:all);
no warnings qw /syntax/;



#PRINT SERIAL NUMBER

my @sl;
my $filename;
$filename = "cxout1" ;
open (FILE, "<$filename") or die "Could not open $filename: $!";
while (<FILE>) {
next unless $_ =~ /CK/;
$_ = ~ (/\b(ID)\=(\w+)\s+/i) ;
push(@sl,$2);
}


# PRINT UNIQUE SERIAL NUMBER

my %seen = ();
my @uniq = ();
my $item;
foreach $item (@sl) {
unless ($seen{$item}) {
# if we get here, we have not seen it before
$seen{$item} = 1;
push(@uniq, $item);
}
}


print "\nThe Clarion Array Serial Number is @uniq\n\n";


# PRINT LUN INFRMATIN

my @luns;
#my $filename;
$filename = "cxout1" ;
open (FILE, "< $filename" ) or die "Could not open $filename: $!";
while (<FILE>) {
chomp;
# next unless $_ =~ /LUN/;
# $_ =~ /\[(LUN\s+\d+)\]/;
next unless /\[(LUN\s+\d+)\]/;
push(@luns,$1);

}

# PRINT PLICY INFRMATIN

my @pol;
#my $filename;
$filename = "cxout1" ;
open (FILE, "< $filename" ) or die "Could not open $filename: $!";
while (<FILE>) {
chomp;
next unless $_ =~ /policy/;
$_ = unpack ("x13 A14", $_);
push(@pol,$_);
}

# PRINT WNER INFRMATIN

my @own;
#my $filename;
$filename = "cxout1" ;
open (FILE, "< $filename" ) or die "Could not open $filename: $!";
while (<FILE>) {
chomp;
next unless $_ =~ (/\b(current)\=\w+/);
$_ = unpack ("x21 A14",$_);
push(@own, $_);
}

#PRINT PSEUD INFRMATIN

my @pseudo;
open (FILE, "< $filename" ) or die "Could not open $filename: $!";
while (<FILE>) {
chomp;
next unless $_ =~ (/\b(Pseudo)/);
$_ = unpack ("x12 A18", $_);
push (@pseudo, $_);
}

#CNSLIDATE & PRINT

my $result = each_array(@luns, @pol, @own, @pseudo);

print "LUN INF\t PLICY-TYPE\t\t WNER\t\t PSEUD DEVICE\t\t\n";


while ( my ($a, $b, $c, $d) = $result->() )
{

print "$a\t\t $b\t\t $c\t\t $d\t\t\n";
}





Thanks in Advance

Js

Reply With Quote
Reply

Viewing: Web Development Archives Mailing Lists Perl > Optimize the script


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 Off
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest Threads | Shoutbox
Forum Jump


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





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway
Stay green...Green IT