in reply to Re: Parse data representing hash
in thread Parse data representing hash

Thank you for your advice, it correlates with what others have said by maintaining state in @keychain.

When truncating I suppose the best approach be something along the lines of splice @keychain, $tabs_count; (update: nevermind this question, the example provided by choroba covers this)

Replies are listed 'Best First'.
Re^3: Parse data representing hash
by AppleFritter (Vicar) on Jun 29, 2014 at 09:40 UTC

    Yes, splice is likely the best approach. From its documentation:

    Removes the elements designated by OFFSET and LENGTH from an array [...] If LENGTH is omitted, removes everything from OFFSET onward.

    So with zero-based arary indexing, it really is as simple as splice @keychain, $tabs_count;, yes.

    You could also use an array slice, BTW, e.g. @keychain = @keychain[0 .. ($tabs_count - 1)];, but that's less elegant and idiomatic.

      Thanks again

      Just to add to these approaches, another approach suggested below is to do $#keychain = $tabs_count

      Regards

        Oh, nice! I wasn't aware that you could assign to $#... to shorten (and grow?) an array. Thanks for sharing that tip, I doubt I'd have seen it below.