CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
Search Posts SEARCH
Who's Online WHO'S
Log in LOG

Home: Perl Programming Help: Intermediate: Re: [psr] array elements: Edit Log


Apr 7, 2013, 11:31 AM

Views: 1231
Re: [psr] array elements

The following line does not do what you expect.


It assigns zero to the first element of the array. To set an array to an empty list, use:

@array = ();

To set the length of an array to any non-zero value, set the last element to an arbitrary value.

Congratulations for using lexical variables. However declaring all of them at the beginning of your file largely defeats their value. You should declare each variable in the smallest possible scope. Always use strict and warnings.

Update: I have noticed another likely error. You return a zero for index if the zero-th element matches or if there is no match at all. I recommend using the last_index routine in the module List::MoreUtils. (It returns -1 for no-match)
Good Luck,

(This post was edited by BillKSmith on Apr 7, 2013, 12:44 PM)

Edit Log:
Post edited by BillKSmith (Veteran) on Apr 7, 2013, 12:44 PM

Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives