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

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Intermediate:
Post deleted by psr

 



psr
Novice

Apr 7, 2013, 10:23 AM

Post #1 of 2 (588 views)
Post deleted by psr

 


BillKSmith
Veteran

Apr 7, 2013, 11:31 AM

Post #2 of 2 (585 views)
Re: [psr] array elements [In reply to] Can't Post

The following line does not do what you expect.

Code
@array=0;

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

Code
@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,
Bill

(This post was edited by BillKSmith 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