10ff1 foreach.. - Perl Programming
Training, Open Source computer languages
PerlPHPPythonMySQLApache / TomcatTclRubyJavaC and C++LinuxCSS 
Search for:
Home Accessibility Courses Diary The Mouth Forum Resources Site Map About Us Contact
foreach..

Posted by kitwalker2886 (kitwalker2886), 9 June 2007
this is a doubt i came up with when i was tryin to pop out the entire contents of an array..
 
    foreach(@conseq)
    {
        pop @conseq;
     }

this code dint work properly.. i was still gettin some elements in the array..  But..
   
    foeach(0..scalar(@conseq))
    {
       pop(@conseq);
     }

  This code cleared out the entire array.. Any explanation why this is so..??



 


Posted by admin (Graham Ellis), 9 June 2007
Yes, it's because the first piece of code sets up a temporary list for perl to traverse and doesn't keep going back to the original each time.  Whther or not it behaves in this way doesn't matter in the second case as you're using a count.



This page is a thread posted to the opentalk forum at www.opentalk.org.uk and archived here for reference. To jump to the archive index please follow this link.

You can Add a comment or ranking to this page

© WELL HOUSE CONSULTANTS LTD., 2013: Well House Manor • 48 Spa Road • Melksham, Wiltshire • United Kingdom • SN12 7NY
PH: 01144 1225 708225 • FAX: 01144 1225 899360 • EMAIL: info@wellho.net • WEB: http://www.wellho.net • SKYPE: wellho
0