Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re: intersection of scalar with 1D array and 2D array Matlab=>Perl

by NetWallah (Canon)
on Aug 30, 2014 at 04:07 UTC ( [id://1099058]=note: print w/replies, xml ) Need Help??


in reply to intersection of scalar with 1D array and 2D array Matlab=>Perl

A few modules that are likely to do the job well: Other than that, some perlish syntax correction (NO logic correction) to your code:
while ( defined (my $scalar=<$TEST>) ) # This will accommodate the cas +e when $seclar is Zero { chomp($scalar); my ( $a, $b ) =firstidx { $_ == $scalar } @arrayPFA; # $a and $b ar +e NOT good names - they have special meanings in perl if(!defined $a) { $data=$arrayPFA[$b]; } elsif(if any { ! defined($scalar) } @arrayT;) # No idea what is inte +nded here... { $data=1.0; } else { $data=0.0; }; };

        "You're only given one little spark of madness. You mustn't lose it."         - Robin Williams

  • Comment on Re: intersection of scalar with 1D array and 2D array Matlab=>Perl
  • Download Code

Replies are listed 'Best First'.
Re^2: intersection of scalar with 1D array and 2D array Matlab=>Perl
by choroba (Cardinal) on Aug 30, 2014 at 07:45 UTC
    This will accommodate the case when $seclar is Zero
    Not needed:
    $ perl -MO=Deparse -e 'while (my $scalar = <$TEST>) {1}' while (defined(my $scalar = <$TEST>)) { do { '???' }; } -e syntax OK

    Relevant: To Kill a Meme: while(defined($line = <>))

    لսႽ† ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ
      Correct, scary, and certainly not obvious.

      Thanks for the education.

      More discussion on this issue is at stack overflow.

              "You're only given one little spark of madness. You mustn't lose it."         - Robin Williams

Re^2: intersection of scalar with 1D array and 2D array Matlab=>Perl
by f77coder (Beadle) on Aug 30, 2014 at 04:28 UTC

    Thanks for suggestion.

    I tried List::Compare and most of the flavors but they all bomb because I'm comparing a scalar to an array. All want 1D arrays to compare. I'll have a look at the others.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1099058]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others surveying the Monastery: (2)
As of 2024-04-25 20:43 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found