Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery

Re^2: @array elements multiplication with another array elements.

by AnomalousMonk (Canon)
on Nov 03, 2012 at 16:20 UTC ( #1002115=note: print w/replies, xml ) Need Help??

in reply to Re: @array elements multiplication with another array elements.
in thread @array elements multiplication with another array elements.

$#arr returns a zero indexed length of items list $#arr = 3

I think it is fundamentally misleading to refer to what  $#array returns as a "length". Rather, I would say it is the highest index of the array, and depends on what the $ARRAY_BASE special variable (aka $[ – see perlvar) has been set to (but don't do that!).

Replies are listed 'Best First'.
Re^3: @array elements multiplication with another array elements.
by Don Coyote (Pilgrim) on Nov 04, 2012 at 12:31 UTC

    Thanks Anomolous, point noted. I should also reflect that it is not truly the map operator that is using the $#arr construct to obtain the highest array index as such, rather it is being used by the .. range operator. As map expects a list of some description to work with after the modifiying operation. In this case we give the list in scalar context of a range, much like the for iterator, so perl goes ah yah, this is some funky for loop right, and cooly proceeds.

    I will now look into how the $ARRAY_BASE special variable affects the $# variable. I would not have thought a difference would be made, being as the highest index of an array is always going to be the highest index? (unless $[ is set higher perhaps... hmm...).

    *Footsteps echo quietly away as Coyote trundles off into the dark echoing corridors of the echosome vaults.

      I will now look into how the $ARRAY_BASE special variable affects the $# variable.

      By all means investigate the-special-variable-whose-name-must-not-be-written to learn its heterodoxy, but never use this impious and odious monstrosity lest your script be shunned throughout all lands and ages, and your name be cursed by maintainers.

      >perl -wMstrict -le "$[ = 654; my @ra = 0 .. 12; print $#ra; " Use of assignment to $[ is deprecated at -e line 1. 666

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1002115]
[jdporter]: ok, I need a recipe for piping lines "through" an external program which is itself a filter
[jdporter]: without using a tmp file
[1nickt]: tobyink perl -MTypes::Standard= is_Int -Mstrict -wE 'say 1 if is_Int 1.0'
[jdporter]: so that I can use the existing expand unix util. Otherwise, I'll probably use Text::Tabs.
[1nickt]: pryrt I guess I don;t really care if user 42 logs on as 42.0 ... more of an academic question at this point.
[LanX]: jdporter: open PIPE,'-|' ?
[LanX]: oh you want the result line by line?
[jdporter]: ok, LanX, then what?
[jdporter]: It doesn't have to be line by line. Just "my program" "writes" to the external prog and also/then "reads" from it.
LanX open (You are not allowed to open to a command that pipes both in and out, but see IPC::Open2, IPC::Open3, and Bidirectional Communication with Another Process in perlipc for alternatives.)

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (13)
As of 2017-05-24 20:27 GMT
Find Nodes?
    Voting Booth?