pass binary array to subroutine

&myFunc($str, (qw(1 0 1 1 0)))


myFunc()
{

my $str = @_[0];
@myArr = @_[1];

    if(myArr->0)
    {}
   
    if(myArr->1)
    {}

    if(myArr->2)
    {}

    if(myArr->3)
    {}

    if(myArr->4)
    {}

    if(myArr->5)
    {}

}


Is this correct and can you suggest a more elegant way to do this?
NewtonianBAsked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
ozoConnect With a Mentor Commented:
sub myFunc{
  my $str = shift;
  my @myArr = @_;
  for( @myArr ){
    if( $_ ){
      print $_
    }
  }
}
myFunc($str, qw(1 0 1 1 0));
0
 
ozoCommented:
my $str = $_[0];
@myArr = @_[1..$#_];
 if($myArr[0])
 {}

for( @myArr ){

}
0
 
NewtonianBAuthor Commented:
Awesome, thanks!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.