5 $re_sect_pre = '^(?:\xEF\xBB\xBF|\xFE\xFF)?\s*\[';
7 $re_sect = $re_sect_pre . '(.+?)' . $re_sect_post;
10 $re_key = $re_key_pre . '(.+?)' . $re_key_post;
11 $re_comment = '^\s*[\x23;]';
17 seek $srt_hnd, 0, Fcntl
::SEEK_SET
;
20 if(/$re_sect_pre\Q$sect\E$re_sect_post/)
22 $section_offset = tell $srt_hnd;
32 seek $srt_hnd, $offset, Fcntl
::SEEK_SET
;
42 if(not grep {$key eq $_} @ref_keys)
52 ($srt_file, $ref_file) = @ARGV;
53 open $srt_hnd, '<', $srt_file or die "$srt_file: $!\n";
54 open $ref_hnd, '<', $ref_file or die "$ref_file: $!\n";
61 $old_section = $section;
63 if(defined $old_section)
65 keys_left
($section_offset);
69 push @ref_sections, $section;
70 undef $section_offset;
71 $section_header = seek_to_section
($section);
74 print $section_header;
77 elsif(defined $section_header)
87 seek $srt_hnd, $section_offset, Fcntl
::SEEK_SET
;
90 if(/$re_key_pre\Q$key\E$re_key_post/)
100 if(defined $section_offset)
102 keys_left
($section_offset);
105 seek $srt_hnd, 0, Fcntl
::SEEK_SET
;
112 $do_print = not grep {$sect eq $_} @ref_sections;
127 inisort - Sort keys in an INI file according to the order of keys in an other INI file
131 inisort [<B<UNSORTED>>] [<B<REFERENCE>>] > [<B<SORTED>>]