[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: not wanting to delete somebody's home directory



On Sat 06 Jul 2019 at 12:31:25 (-0000), Curt wrote:
> On 2019-07-06, songbird <songbird@anthive.com> wrote:
> > Curt wrote:
> >> On 2019-07-05, mick crane <mick.crane@gmail.com> wrote:
> > ...
> >>> I'm incrementing the number by the loop and some software sees 2 as 
> >>> bigger that 10 or something like this. I can probably get around that by 
> >>
> >> Not sure exactly what you mean by some software, but you must be sorting
> >> lexicographically (the numbers are treated as strings, in which case
> >> alphabetically speaking 1 goes before 2).
> >>
> >> I don't think anybody's pointed this out yet (to my surprise) so I
> >> thought I would (maybe I missed it), although my ignorance is nearly
> >> total in the matter.
> >
> >   i have no perl programming experience so i could
> > not speak to that issue.
> 
> This wasn't a criticism of anyone but rather an observation.
> 
> In the bash shell I have wondered about this sorting "anomaly" myself and so
> looked it up this very day. As the simple (and pretty obvious, really) answer
> was completely amenable to my intellectual powers, I was kind of enjoying
> myself believing I'd mastered a trivial programming concept and wished to share
> my joyful discovery with the group. That it happened to be the result of the
> OP's explicit interrogation and so proves itself to be on-topic is a matter of
> pure serendipity.
> 
> ;-)
> 
> # sort numerically ascending
> my @articles = sort {$a <=> $b} @files;
>     
> # sort numerically descending
>  my @articles = sort {$b <=> $a} @files;
> 
> The default must be to sort lexicographically.

Um, typically the default sorting method is by the underlying binary
representation of the characters. Anything else means that some
interpretation of the semantics is taking place, eg folding the
cases together, ignoring punctuation, interpreting strings of digits
as numbers, honouring multipliers like k/M/G, interpreting combining
characters, and of course maltreating the binary characters as 8-bit bytes.

It wasn't clear to me where the OP was intending to sort: within perl
or in the shell. As I posted, my recommendation was to rename the
files within perl, but after they've all been generated, in order that
the number of files (and hence the number of digits required) is known.

Cheers,
David.


Reply to: