Josimar Nunes de Oliveira <[EMAIL PROTECTED]> wrote:
:
: Hello Clarkson,
: Thanks for everything you explained.
You're welcome.
: The 'System Volume Information' is a restricted system folder
: (only SYSTEM can access) in NTFS.
I don't know much about win 2k. That file may
be inaccessible to the user running the script.
Sorry, but I don't know how to access it.
: For a moment I was in trouble in how to handle the @file
: resulted from the
: File::Find.
: It�s a basic problem that I need to understand how to access
: array and hash.
: I must improve my skill toward this subject.
: The final porpose isn�t important by now, only learning a
: litle more Perl:
: I tried this and worked fine:
:
: for (my $i=0; $i<=$#files; $i++){
: print "\n", $files[$i][0], ' => ', $files[$i][1];
: }
In perl you can usually step through a single
array *without* counting through its indexes. It
may look funny at first, but this is easier to
read.
foreach my $file ( @files ) {
print join( ' => ', @$file ), "\n";
}
Each time through the loop $file contains a
reference to another array. 'perldsc' has a lot
info on data structures like this.
: How to sort the @file by filename (first column of array)?
: How can take every occurrency of array with foreach(@files)
: or while (@files) like in loop above?
Sorting this array should be fairly
straight forward.
# ascending first column sort
@files = sort { $a->[0] cmp $b->[0] } @files;
# ascending second column sort
@files = sort { $a->[1] cmp $b->[1] } @files;
# Descending first column sort
@files = reverse sort { $a->[0] cmp $b->[0] } @files;
# Descending second column sort
@files = reverse sort { $a->[1] cmp $b->[1] } @files;
HTH,
Charles K. Clarkson
--
Head Bottle Washer,
Clarkson Energy Homes, Inc.
Mobile Home Specialists
254 968-8328
Or a 1 column sort sub routine where a negative value
will do a reverse (or descending) sort:
sort_files( -1, [EMAIL PROTECTED] );
foreach my $file ( @files ) {
print join( ' => ', @$file ), "\n";
}
sub sort_files {
my( $column, $array ) = @_;
my $descending = $column < 0;
$column = abs( $column ) - 1;
die if $column < 0;
# ascending sort
@$array =
sort
{ $a->[ $column ] cmp $b->[ $column ] }
@$array unless $descending;
# descending sort
@$array = reverse
sort
{ $a->[ $column ] cmp $b->[ $column ] }
$array;
}
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]