In article <43b506a6$0$898$>,
Dave Weaver <> wrote:
>Raghuramaiah Gompa <> wrote:
>> I have a file that has lines like the following:
>>
>> Titl1=B2a
>> Command1=c:\chi\cw.exe
>> Title2=f2a
>> Directory1=c:\chi
>> Type1=1
>> Command2=c:\chi\cw.exe
>> Directory2=c:\chi
>> Options2=%@%
>> Type11=2
>> Title14=Ma3
>> Command14=c:\chi\cpb.bat
>> Options14=c:\temp\temp.bin
>> Use long names3=1
>> Title12=Dir
>> Command12=Tfd
>> Title13=a2h
>> Command13=c:\bat\a2h.bat
>> Options13=%@dpn%
>> Show13=2
>> Command31=C:\bat\tview.bat
>> Use long names31=1
>> Title31=tview
>> .....
>>
>> Basically Title,Command, Show,... constitute a group
>of commands
>> that are associated with the name described in
>Title. Now I want
>> to reorder them in the alphabetical order of names
>described in
>> Title. For instance, the new file should have :
>>
>> Title1=a2h Command1=c:\bat\a2h.bat Options1=%@dpn%
>> Show1=2
>>
>> and all the lines (Title2=B2a, ..) are changed
>accordingly (because
>> or the order a2h, B2a, Dir, f2a, Ma3, .... )
>
>Your description is not very clear.
>
>You want to group the lines where the number is in
>common (so Title14
>goes with Options14 and Command14, and so forth)?
>
>Then sort the groups them based on the value of the
>Title element?
>What about when there is no Title elelement, such as in Type11
>above?
>
>Then ouput in this new order, but renumber them, so the
>the first
>group is always Title1=... , then second has Title2=...
>and so on?
>
>Is that what you mean?
>
>The code below *might* do something like you want, but
>since your
>specification is lacking, the results may be too.
>
>Interesting (to me) sidenote: I noticed that when I
>added the lc()
>calls to the sort, the warnings about use of undefined
>variables
>(because Title isn't defined for some elements) went
>away. Shouldn't
>lc() warn if it's passed undef?
>
>
>#!/usr/bin/perl
>use warnings;
>use strict;
>
>my %items;
>while(<DATA>) {
> $items{$2}{$1} = $3 if /^(\w+?)(\d+)=(.+)/;
>}
>
>my $n = 1;
>for my $idx (
> sort {
> lc $items{$a}{Title} cmp lc $items{$b}{Title}
> } keys %items)
>{
> print map {
> "$_$n=$items{$idx}{$_}\n";
> } keys %{$items{$idx}};
> print "----\n";
> ++$n;
>}
>
>__DATA__
>Title1=B2a
>Command1=c:\chi\cw.exe
>Title2=f2a
>Directory1=c:\chi
>Type1=1
>Command2=c:\chi\cw.exe
>Directory2=c:\chi
>Options2=%@%
>Type11=2
>Title14=Ma3
>Command14=c:\chi\cpb.bat
>Options14=c:\temp\temp.bin
>Use long names3=1
>Title12=Dir
>Command12=Tfd
>Title13=a2h
>Command13=c:\bat\a2h.bat
>options13=%@dpn%
>Show13=2
>Command31=C:\bat\tview.bat
>Use long names31=1
>Title31=tview
>
First of all, I apologize for not making my question
clear. However, you (and others, too) understood exactly
what I want. Thank you all for the codes and help. Now I
am faced with another problem. This sorting must be done
only for a part of the text that is between the
line that contain [Buttons] and someother line that
starts with [ (it could be [Directories] or [Files]).
Rest of the document should be copied as it is. I tried
several ways and failed

Please help. .. Raghu