Hi Shomi, Appreciate your comments.Thanks
I find it difficult to understand, if i convert into has. i.e keys and corresponding values. if my keys are from @actzone and values are from @all. How can i do this, becuase there are 2 keys and values are multiple ex. alias: wwn: etc. how can i match this in a hash ? key zone: tstdetdr_B_AARA_30767_CL45 zone: artdetdr_B_AARA_30767_CL45 value zone: tstdetdr_B_AARA_30767_CL45 zone: artdetdr_B_AARA_30767_CL45 zone: dbtdetdr_B_AARA_30767_CL45 zone: tstdetdr_B_AARA_30767_CL45 10:00:00:00:c7:d5:cd:16:c6 50:00:00:08:44:9a:fb:79:90 zone: artdetdr_B_AARA_30767_CL45 10:00:00:00:c7:d5:cd:16:c9 50:00:00:08:44:9a:fb:64:90 zone: dbtdetdr_B_AARA_30767_CL45 10:00:00:00:c7:d5:cd:16:ca 50:00:00:08:44:9a:fb:74:90 zone: tstdetdr_B_AARA_30767_CL45 tstdetdr_B_AARA,30767_CL45 zone: artdetdr_B_AARA_30767_CL45 artdetdr_B,AARA_30767_CL45 zone: dbtdetdr_B_AARA_30767_CL45 dbtdetdr_B,AARA_30767_CL45 alias: tstdetdr_B_AARA 10:00:00:00:c7:d5:cd:16:c6 alias 30767_CL45 50:00:00:08:44:9a:fb:64:90 alias: artdetdr_B_AARA 10:00:00:00:c7:d5:cd:16:c9 alias: AARA_30767_CL45 50:00:00:08:44:9a:fb:64:90 On Fri, Aug 17, 2012 at 1:21 PM, Shlomi Fish <shlo...@shlomifish.org> wrote: > Hi jet speed, > > On Fri, 17 Aug 2012 12:10:47 +0100 > jet speed <speedj...@googlemail.com> wrote: > > > Hi All, > > > > I have the below program. i can match the entries in actzone.txt file > > in bluealias.txt and print it. > > > > what i would like to achive is to print the alias name and the reated > > wwn for each zone that matched in 2 formats in different file ex. as > > below. Please could you help me achieve this. > > Maybe try using a hash: > > http://perl-begin.org/topics/hashes/ > > Perhaps you'd like to peruse an introductory Perl tutorial: > > http://perl-tutorial.org/ > > Now allow me to comment on your code. > > > > > > > outputfile1 > > ------------ > > > > zone : tstdetdr_B_AARA_30767_CL45 > > alias: tstdetdr_B_AARA > > 10:00:00:00:c7:d5:cd:16:c6 > > alias: 30767_CL45 > > 50:00:00:08:44:9a:fb:64:90 > > > > outputfile2 > > -------------- > > > > zone : tstdetdr_B_AARA_30767_CL45, alias : tstdetdr_B_AARA, > > 10:00:00:00:c7:d5:cd:16:c6,alias: 30767_CL45, > > 50:00:00:08:44:9a:fb:64:90 > > > > ---- > > > > #!/usr/bin/perl > > > > use strict; > > use warnings; > > > > my (@all, @actzone); > > @all is not a descriptive variable name. "act" and "zone" should be > separated by underscores. > > > > > open (FILE, "bluealias.txt") || die "can't open alias $! \n"; > > 1. Don't use bareword filehandles. > > 2. Use three-args open. > > 3. Don't call your variable "file": > > http://perl-begin.org/tutorials/bad-elements/ > > > while (<FILE>) { > > s/\s+//g; > > push @all,$_; > > } > > while my ($line = <$fh>) would be preferable here. > > > chomp @all; > > You should do it inside the while loop. (but s/\s+// will also remove > the newline). > > > > > open (FILE, "actzone.txt" ) || die "can't open zone: $! \n"; > > Don't reuse the same variable for two different tasks. > > > while (<FILE>) { > > s/\s+//g; > > push @actzone,$_; > > } > > chomp @actzone; > > > > for my $zone (@actzone) { > > chomp $zone; > > for my $all (@all) { > > chomp $all; > > if ($zone =~ $all) { > > Shouldn't you use perldoc -f index here? Or maybe \Q and \E (see perldoc > -f quotemeta). > > > print "$all \n"; > > #print "$`"; > > } > > } > > } > > Your code is lacking indentation. > > Regards, > > Shlomi Fish > > -- > ----------------------------------------------------------------- > Shlomi Fish http://www.shlomifish.org/ > Interview with Ben Collins-Sussman - http://shlom.in/sussman > > There is no IGLU Cabal! Its members can be arranged in N! orders to form N! > different Cabals. The algorithm to find which order formulates the correct > IGLU Cabal is NP‐Complete. > > Please reply to list if it's a mailing list post - http://shlom.in/reply . >