http://www.perlmonks.org?node_id=1003652


in reply to ordering array of sentences

If the list of sentences is longer, searching for a word before another word might slow the program down (Benchmark). Schwartzian transform to the rescue:
#!/usr/bin/perl use warnings; use strict; use feature 'say'; my @sentences = ('I am searching for a word', 'What are you searching for?', 'Today I have been searching for a new job', ); my $query = 'searching'; # Not @query, it is a scalar, not an array +. say for map $_->[1], sort { $a->[0] cmp $b->[0] } map { /(\w+)\s+searching/; [$1, $_] } @sentences;
لսႽ† ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ