Hi Dave,
 
I think there are 3 possible ways to check the last element in your IF
condition inside Foreach loop.
 
1. $list[-1] eq $element
2. $list[$#list] eq $element
3. $list[scalar(@list)-1] eq $element
 
  See the example code and replace the if with other set of conditions given
above
      
@list = qw/a d b y I s n p/;
Foreach $element (@list) {
    If ($list[-1] eq $element) {
        Print "last element is $element";
     }
 } 
 
Output : last element is p 
 
Regards,
Vijaya 
 
 
 

<<IMSTP9.gif>>

Reply via email to