Re: sort
From: Jürgen Exner (jurgenex_at_hotmail.com)
Date: 12/20/03
- Next message: Jürgen Exner: "Re: sort"
- Previous message: Randal L. Schwartz: "Re: sort"
- In reply to: Martin: "Re: sort"
- Next in thread: Martin: "Re: sort"
- Reply: Martin: "Re: sort"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
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
- Next message: Jürgen Exner: "Re: sort"
- Previous message: Randal L. Schwartz: "Re: sort"
- In reply to: Martin: "Re: sort"
- Next in thread: Martin: "Re: sort"
- Reply: Martin: "Re: sort"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|