Solved

pass binary array to subroutine

Posted on 2009-03-30
3
204 Views
Last Modified: 2012-05-06
&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?
0
Comment
Question by:NewtonianB
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 84

Expert Comment

by:ozo
ID: 24024727
my $str = $_[0];
@myArr = @_[1..$#_];
 if($myArr[0])
 {}

for( @myArr ){

}
0
 
LVL 84

Accepted Solution

by:
ozo earned 500 total points
ID: 24024754
sub myFunc{
  my $str = shift;
  my @myArr = @_;
  for( @myArr ){
    if( $_ ){
      print $_
    }
  }
}
myFunc($str, qw(1 0 1 1 0));
0
 

Author Closing Comment

by:NewtonianB
ID: 31564618
Awesome, thanks!
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
perl to display a matrix report for 3-dimenional array 3 75
Regular Expression question to filter with negation. 6 109
batch script for automated email 12 142
Perl Untar File 1 78
I've just discovered very important differences between Windows an Unix formats in Perl,at least 5.xx.. MOST IMPORTANT: Use Unix file format while saving Your script. otherwise it will have ^M s or smth likely weird in the EOL, Then DO NOT use m…
Email validation in proper way is  very important validation required in any web pages. This code is self explainable except that Regular Expression which I used for pattern matching. I originally published as a thread on my website : http://www…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…

710 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question