-3

Please advice how to pass 3 variables in an array with relation.

@item = ($a , $b , $c);
@record = push(@array, @item);

I want to assign value in a @array so that if I look for any instance I should get value of all a,b,c.

Is there any way apart from comma to assign a value in array. like $a:$b:$c or $a>$b>$c I need this because i am want to grep 1 record(a) and get (a:b:c)

@array1 = grep(!/$a/, @array);

expected output should be a:b:c 

Thanks,

  • 1
    How do you mean the expected output should be "a:b:c"? Executing a `grep` and assigning its return value to an `@array` won't output anything. – Kaoru Jun 24 '14 at 08:51
  • Actually I am pushing 3 different variables to an array. and I want if any one of the match I want to remove all 3 from array. for example if there are : abc def zte fgi adf I want to remove abc and adf as i am grepping for a – user3717017 Jun 24 '14 at 09:10

1 Answers1

1

The question is not very clear. Maybe you should rephrase it. However, I understand you want an array with groups of three elements.

You might want to use array references.

@item = ($a , $b , $c);
push(@array, \@item);

or

$item = [$a , $b , $c];
push(@array, $item);

Also, pushwon't return an array as you expect. Perldoc says:

Returns the number of elements in the array following the completed "push".

Now if you want to filter these groups of three elements, you can do something like that:

my @output = ();
L1: foreach ( @array ){
    L2: foreach( @$_ ){
        next L1 if $_ eq $a; 
    }
    push @output, $_;
}

Please note that if you want an exact match you should use the eq operator instead of a regex...

Pierre
  • 1,204
  • 8
  • 15