Re: sort

From: Jürgen Exner (jurgenex_at_hotmail.com)
Date: 12/20/03


Date: Sat, 20 Dec 2003 17:51:58 GMT


[Please do not top post! Trying to re-arrange into chronological order]
[Please trim your quotes to a reasonable length]
Martin wrote:
> "Martin" <martin@gmx.de> schrieb im Newsbeitrag
> news:bs1u94$4pv$04$1@news.t-online.com...
>> I want to walk through a directory path and get the sorted
>> filepaths of my files.
[...]
>> but the filenames do not get sorted. I can print them with print
>> @SortLinks, but ther is on sorting.
[...]
[...]

As I suspected (see inline below)

> find(\&bearbeiten, $start_verzeichnis);
>
> sub bearbeiten {
> # Diese Subroutine wird für jede rekursiv gefundene Datei einmal
> aufgerufen.
> return unless /\.html$/ || /\.shtml$/ ;
> my @Links = "";

Here you initialize @Links as the list, that contains an empty string (why?)

> push (@Links, "$File::Find::name\n") ;

Then you push _one_ filename onto that list

> my @SortLinks = sort (@Links);

You sort that one-element list which effectivly doesn't do anything.

> print @SortLinks;

And then you print the content of that one-element list.

This process is repeated for every file found, resetting @Links to the list
containing the empty string for each iteration. Of course the net effect is
that you are printing all files in the order as they are being traversed by
File::Find.

Solution:
@Links must become global, i.e. move the declaration out of the bearbeiten()
function.
And then move the sort() and print() calls out of the bearbeiten function,
too, to the end of the program. Or do you really want to sort once for every
file found? Because that is what you are doing now.

jue



Relevant Pages

  • Re: sort
    ... > Martin wrote: ... > You sort that one-element list which effectivly doesn't do anything. ... Of course the net effect ... > And then move the sortand printcalls out of the bearbeiten function, ...
    (comp.lang.perl.misc)
  • Re: Can this VBA for work on text files be modified for a different job ?
    ... you'll need to start it by typing ... For the Option Explicit, in the VBE, use Tools | Options... ... As to your chronological order concern: you could address this either of two ... If the files are created in proper chronological order, then your could sort ...
    (microsoft.public.excel)
  • Re: Looking for an picture management program - ideas please.
    ... image directory indicating its date or it allows me to sort the ... me chronological order if sorted alphabetically. ... June Canal Holiday ...
    (Ubuntu)
  • Strange find and replace query
    ... so I can sort the data in chronological order. ... Not sure if really the workbook needs to be viewed, ... Dim EndCell As String ...
    (microsoft.public.excel.programming)
  • Re: sorting in outlook express
    ... Enquire, plan and execute. ... Or you can use Edit | Find and search by From and specify a date range, or sort by date from the results. ... be in chronological order. ... sort by sender. ...
    (microsoft.public.windows.inetexplorer.ie6_outlookexpress)