Hello! Understanding Perl, help with sorting ...

The following code:

open(FILE,"<file"); @text = <FILE>; chomp(@text); close(FILE); 

Each line in the file is the data written through the separator "|" i.e.

 фио|адрес|телефон| фио|адрес|телефон| 

It is necessary to sort by name, and there can be both Russian and English characters. Thank!

  • chomp (@text); will it work? - Andryusha
  • one
    perldoc -f chomp ... CHOMP (LIST) - KneLL

3 answers 3

 sort { [split /\|/, $a]->[0] cmp [split /\|/, $b]->[0] } @text; 

About Russian smoke about locale and unicode.

     #!/usr/bin/perl use strict; use warnings; open FILE,'file.txt'; chomp(my @info =<FILE>); print sort @info ; 

    This option is not good?

       <Handle> chomp; 

      So it will work too.