in reply to why each/keys/values can't work on slice?

Why would you want to use keys @bb[1..5] when you can use 1..5?

Why would you want to use values @bb[1..5] when you can use @bb[1..5]?

Replies are listed 'Best First'.
Re^2: why each/keys/values can't work on slice?
by Anonymous Monk on Jan 11, 2023 at 03:04 UTC
    well,that’s just a example, slice could contains single elements and range even like @bb1,3,-1 etc.IMHO, slice is an accessor of array. So I am really curious why Perl emphasize keys,each only work on array and hash except for slice.

      Then you could use 1, 3, -1 instead of keys @bb[ 1, 3, -1 ].

      Generally speaking,

      You could use LIST instead of keys @bb[ LIST ].

      You could use @bb[ LIST ] instead of values @bb[ LIST ].