Hi Monks,
Was just trying some statements and wondered why a similar one doesn't work.I might be wrong on some basics. But why the 2nd statement fails. I mean if such a thing works, then we can directly use it to print a single element returned from a function or method(like in Java).e.g.print ("adf","ff","f"); # Gladly prints the list print ("adf","ff","f")[1]; #Gives a syntax error $val=("adf","ff","f")[1];print $val; #Works easily print join "",("adf","ff","f"); #Works print join "",("adf","ff","f")[1]; #Works since treated in list contex +t
Similarly in Java we can do:(sort {$a<=>} @lst)[0] # an alternative way to get min value from some + numeric list.
obj.method()[2] #when we know that method returns an array
Tried to search a little about this, but could not find a reasonable thread for the same. Sorry again if this is some conceptual weakness of mine.
In reply to Getting single element from an array by gurpreetsingh13
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |