Solved

pass binary array to subroutine

Posted on 2009-03-30
3
166 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
  • 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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
perl script help 5 229
Existing perl code to be changed for ftp to sftp handling 14 130
crawling gofundme 4 103
perl to convert excel to csv 3 148
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…
I have been pestered over the years to produce and distribute regular data extracts, and often the request have explicitly requested the data be emailed as an Excel attachement; specifically Excel, as it appears: CSV files confuse (no Red or Green h…
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…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

708 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now