In my laziness, impatience, and hubris I have reached the conclusion that this question is worthy of your attention. If I am mistaken, please put the blame on one of the aforementioned personality traits.
I'd like to access the result of a pattern match as an array without assigning it to a variable first. Doing this the non-lazy way goes like this:
@matches = "hello awesome" =~ /(el).*(om)/; print pop @awesome;
I've tried a couple of different approaches, which give different errors:
$ perl -we 'print pop ("hello awesome" =~ /(el).*(om)/);' Type of arg 1 to pop must be array (not pattern match (m//)) at -e lin +e 1, near "/(el).*(om)/)" Execution of -e aborted due to compilation errors.
$ perl -we 'print pop (@matches = "hello awesome" =~ /(el).*(om)/);' Type of arg 1 to pop must be array (not list assignment) at -e line 1, + near "/(el).*(om)/)" Execution of -e aborted due to compilation errors.
The Book $(man perldata) mentions that the Great Creator of perl has given it 'three built-in data types: scalars, arrays of scalars, and associative arrays of scalars, known as "hashes"'. However I see now that there are some quantum particles whose existence proves such dogma to be somewhat oversimplified. The psalm $(perldoc -f scalar) does provide a solution to my practical concerns:
but also mentions that "There is no equivalent operator to force an expression to be interpolated in list context because in practice, this is never needed."$ perl -we 'print ${["hello awesome" =~ /(el).*(om)/]}[1];' om
This revelation suggests that there may be a better way to do this, and also increases my hunger for understanding of the Great Mysteries of perl.
And so it is with humilityhubris that I submit my request for knowledgeassume that my lack of understanding of this aspect of perl is due to a flaw in the documentation, not in my (lack of)? reading of it. Or rather ask for clarification of this aspect of the voluminous and esoteric Literature from those appointed as its interpreters.
Thank you, o great esteemed Monks.
In reply to accessing the result of a match as an array by intuited
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |