#!/usr/bin/perl use strict; use warnings; my @lines = split /\n/, <<EOF; I need your help. I have an array containing sentences. I want to order the sentences according to a given word I am a nice boy You are a nice boy They are not good at all EOF print "$_\n" for order_line(@lines); sub order_line { return sort by_3d_word_from_right @_; } sub by_3d_word_from_right { { lc((split ' ', $a)[-3]) cmp lc((split ' ', $b)[-3]) } }
In reply to Re: sort array
by Cristoforo
in thread sort array
by welle
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |