Note that since you
can (but perhaps shouldn't) do this:
print "saved data to @{ [ $response->filename ] }\n";
This takes advantage of two things:
- Embedding an array in a quoted string causes the elements to all be interpolated, with the default array separator between them (set to one space when your script starts, but changeable if you like).
- Putting a method call inside an anonymous list constructor calls the method in list context and then uses the returned value(s) to create the anonymous array.
So what
@{ [ $obj->method ] } does is
- Call the method, getting a list of zero or more values back
- Produce a reference to an anonymous array
- Immediately dereference the array reference, producing an array consisting of the values returned from the method
- Interpolate the array into the string, thereby embedding the return values from the method call into the string
Why would you
not do that? Well, it's not exactly straightforward, to start with, and there's a perfectly reasonable way to do it without the arcane interpolation. I have used it on occasion when it improved readability, but it's probably not a good habit to get in to.