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

Re: Vector manipulation (scalar)

by tye (Sage)
on Jun 26, 2015 at 19:39 UTC ( [id://1132218]=note: print w/replies, xml ) Need Help??


in reply to Vector manipulation

my $vect1 = $val1->[3.­.5];. When I print test here, I get: 2

Yep. 3..5 is being evaluated in scalar context because dereferencing to get a scalar wants a scalar index:

% say "[0..9]->[4,5]" Useless use of a constant (4) in void context at (eval 1) line 1. 5

You probably want:

my $vect1 = [ @{ $val1 }[3.­.5] ];

- tye        

Replies are listed 'Best First'.
Re^2: Vector manipulation (scalar)
by jcklasseter (Sexton) on Jun 29, 2015 at 12:02 UTC
    Thanks! I got is working on a variant of that, I had to do some dereferencing and re-vectorizing, but it worked! Final snippet:
    my $vect1 = [ @{ $val1 }[3..5] ]; my $vect2 = [ @{ $val2 }[3..5] ]; my $norm = [ @{ $val1 }[0..2] ]; my $varvec1 = V( @$vect1 ); my $varvec2 = V( @$vect2 ); my $varnorm = V( @$norm ); my $nvect1 = $varvec1 - $varnorm ; my $nvect2 = $varvec2 - $varnorm ;

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others meditating upon the Monastery: (5)
As of 2024-04-23 18:13 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found