Perl idiom for getting a maximum number of elements in an array -


I wanted to close the first five elements of an array, so I stupid:

 < Code> @foo = @foo [0 .. 4];  

And heartily admired my own cleverness but breaking it once @foo ended with only three elements, because then I finally gave it Instead of two element elements with two element elements, I changed it to:

  @foo = @foo & gt; 5? @fu [0 .. 4]: @fu;  

It works but is somewhat ugly "Do I give everything to the first five elements of the array?" There is a better phrase to say.

You can set the last pointer of an array to reduce or extend it. Like your code, you will need to check to ensure that your non-element is not making the element.

  $ # foo = 4 if $ # foo> 4;  

Comments

Popular posts from this blog

c# - sqlDecimal to decimal clr stored procedure Unable to cast object of type 'System.Data.SqlTypes.SqlDecimal' to type 'System.IConvertible' -

Calling GetGUIThreadInfo from Outlook VBA -

Obfuscating Python code? -