Looking at perltidy I don't see such an option. Is there any tool which does this?
Asked
Active
Viewed 212 times
2
-
2I'd be nervous about any tool that tried to do that. Since the values can be the results of complex operations, it would have to understand Perl source at a much lower level than what perltidy and other syntax highlighters can handle. – brian d foy Apr 11 '12 at 11:31
-
If you refer to the fact that keys themselves might be the results of complex operations then it's not my case. We can assume all keys are string constants. – Piotr Dobrogost Apr 11 '12 at 13:52
1 Answers
3
I prefer to sort my keys "logically". Fields like 'name' and 'id' come first, sometimes something like 'long name' or 'description' after name.
If you need to do something like this, you could use a editor with a shell facility to
- pass the data into a perl program
- eval the selection
- use
Data::Dumper
and set$Data::Dumper::Sortkeys = 1;
- And then do
Data::Dumper->Dump( [ $eval_hash ], [ '$VAR1' ] )
- Strip off the front part
s/\A[^=]+=\s+//
- Replace the selection with the output

Axeman
- 29,660
- 2
- 47
- 102
-
There's no special logic in this case. These hashes more or less reflect XML Schema files so keys correspond to tags' names. – Piotr Dobrogost Apr 11 '12 at 15:46
-
There's a problem with this approach. Some values in a hash are function invocations so after evaluating the hash we get results of calling these functions and the original source is lost. – Piotr Dobrogost Apr 11 '12 at 20:52