in reply to Re^2: Looking for function similer to member() in SKILL
in thread Looking for function similer to member() in SKILL

Hello all,
Thank to all. I found out that there is a perl module member.pm available which should perform the same function as Skill language member().
Again I am stuck in the loop. I want to print the pair of integer values for only the member of @arr e.g. in this case the pair integer values for Stack3 and Stack5 should be printed. Somehow the member function is reading only the first element of my array.Somebody advice where I am doing wrong?

Here is my code;
#!/usr/bin/perl -w sub member { my $target = shift or die "No target in member/2 "; for (0..$#_) { return $_ if $_[$_] eq $target; } return undef ; } @arr = qw/DRAM1.new_quad_stack.3 DRAM1.new_quad_stack.5 /; open (IN , "$file"); while () { next unless /@arr[member($_,@arr)]/ ; while () { last if /End/ ; print $_ ; } } close IN ;
And here is the file;
*******Voltage********* *[PRD=S][BLD=4.0.0][OS=2000][CN=MUCW6086][USR= +Djordjev][PYM=1023.004MB][PKM=] *[DC=Y][PSE=Y][TLML=N][NRTB=Y][IPC=N][PC=N][DLD=N][TS=232303] *[FN=CA_2T_400_8ranks.cur][DT=Wed_Jul_14_02:15:17_2004][LC=red][LS=RL] +[LP=NN][LW=1][LM=NN][LMS=1][LMI=1] **************Curve*************** DRAM1.new_quad_stack.3 DRAM1.new_quad_stack.1::GND red V1. 0.000000e+000 1.508947e+0003 1.162272e-012 1.508947e+0003 2.324544e-012 1.508947e+0003 3.486816e-012 1.508947e+0003 4.649088e-012 1.508947e+0003 5.811360e-012 1.508946e+0003 **************End*************** *[PRD=S][BLD=4.0.0][OS=2000][CN=MUCW6086][USR=Djordjev][PYM=1023.004MB +][PKM=] *[DC=Y][PSE=Y][TLML=N][NRTB=Y][IPC=N][PC=N][DLD=N][TS=232303] *[FN=CA_2T_400_8ranks.cur][DT=Wed_Jul_14_02:15:17_2004][LC=cyan][LS=RL +][LP=NN][LW=1][LM=NN][LMS=1][LMI=1] **************Curve*************** DRAM1.new_quad_stack.4DRAM1.new_quad_stack.1::GND cyan V2. 0.000000e+000 1.508947e+0004 1.162272e-012 1.508947e+0004 2.324544e-012 1.508947e+0004 3.486816e-012 1.508947e+0004 4.649088e-012 1.508947e+0004 5.811360e-012 1.508947e+0004 **************End*************** *[PRD=S][BLD=4.0.0][OS=2000][CN=MUCW6086][USR=Djordjev][PYM=1023.004MB +][PKM=] *[DC=Y][PSE=Y][TLML=N][NRTB=Y][IPC=N][PC=N][DLD=N][TS=232303] *[FN=CA_2T_400_8ranks.cur][DT=Wed_Jul_14_02:15:18_2004][LC=red][LS=RL] +[LP=NN][LW=1][LM=NN][LMS=1][LMI=1] **************Curve*************** DRAM1.new_quad_stack.5DRAM1.new_qua +d_stack.1::GND red V3. 0.000000e+000 1.508947e+0005 1.162272e-012 1.508947e+0005 2.324544e-012 1.508947e+0005 3.486816e-012 1.508947e+0005 4.649088e-012 1.508947e+0005 5.811360e-012 1.508947e+0005 **************End***************

20050627 Edit by ysth: code tags

Replies are listed 'Best First'.
Re^4: Looking for function similer to member() in SKILL
by Limbic~Region (Chancellor) on Jun 27, 2005 at 12:41 UTC
    Anonymous Monk,
    Please read Writeup Formatting Tips to make your posts clearer in the future. Additionally, you may want to look at perlstyle or Perltidy to make your code clearer. You should also start using strictures and warnings and possibly even diagnostics as they will help you to find problems on your own.

    Now on to specific problems with your code. The next unless /@arr[$index]/ should be using the $ sigil as you are talking about a single element. In fact, this line makes little sense anyway as you are checking to see if the line matches your array, and then you are checking it again by matching using a regex. There is no need to match twice. Of course, this won't work for a couple of reasons - the first is that you are not chomping the line so it will never match because of a newline at the end. The second is that you aren't even reading the file - your while () { ... } should really be while ( <IN> ) { ... }.

    There are more problems but I think you need to take a step back. Try starting out with the smallest piece of working code you can imagine and build on it checking the result each time. The first time it doesn't do what you expect, look there for the problem. For instance - start out reading a file and printing the contents.

    Cheers - L~R

      Hi L~R,
      Sorry I made a mistake posting the message. In my actual code I am reading
      while (<IN>) {...}. Also I tried using chomp but I don't get the right output.

      regards riz.
        riz,
        In my actual code...

        It is rather difficult to help if you don't actually post your actual code. I was hoping something would indicate why you have a valid reason why you can't use a hash instead of an array?

        I am not trying to be mean, but you are not being very effective in asking your question. Perhaps in addition to the other suggestions I provided, you might want to look at How do I post a question effectively?.

        Cheers - L~R