I have a little problem here. Well, not very little
I have a directory of files with the data about people. The structure of each file is:
Here're the samples of five files:
Anna|456328172|Other Data|Other Data|Other Data
Peter|754839273|Other Data|Other Data|Other Data
Alex|643728923|Other Data|Other Data|Other Data
Ted|367898766|Other Data|Other Data|Other Data
What I need is to read the directory for all text files with these data. Sort all data in the files starting with the highest SS Number, and print all sorted stuff to the screen. Like if with sample data files above the output should look like this:
Alex - 643728923 - Other Data - Other Data - Other Data
Anna - 456328172 - Other Data - Other Data - Other Data
John - 384750295 - Other Data - Other Data - Other Data
Ted - 367898766 - Other Data - Other Data - Other Data
Here's what I came up with so far:
$number_to_show = "20"; # The default number of SS to show.
$use_flock = "1"; # File locking? (0=No, 1=Yes)
opendir(SSDIR, "$ss_dir");
@all_ss = grep(/\.txt$/,readdir(SSDIR));
closedir(SSDIR);
foreach $one_ss (@all_ss)
{
open (SS,"$ss_dir$one_ss");
if ($use_flock == "1")
{
flock SS, 2;
}
@entries = <SS>;
foreach $line (@entries)
{
@fields = split(/\|/,$line);
if ($z<$number_to_show)
{
$z++;
# Do the sorting from highest SS number to lowest.
# Print the sorted stuff to the screen.
}
}
close (SS);
}
The only thing I can't figure out is how to sort the data.
Please, help me out here.
Thank you.
I have a directory of files with the data about people. The structure of each file is:
Code:
Name|Social Security Number|Other Data|Other Data|Other DataHere're the samples of five files:
Code:
John|384750295|Other Data|Other Data|Other Data Anna|456328172|Other Data|Other Data|Other Data
Peter|754839273|Other Data|Other Data|Other Data
Alex|643728923|Other Data|Other Data|Other Data
Ted|367898766|Other Data|Other Data|Other Data
What I need is to read the directory for all text files with these data. Sort all data in the files starting with the highest SS Number, and print all sorted stuff to the screen. Like if with sample data files above the output should look like this:
Code:
Peter - 754839273 - Other Data - Other Data - Other Data Alex - 643728923 - Other Data - Other Data - Other Data
Anna - 456328172 - Other Data - Other Data - Other Data
John - 384750295 - Other Data - Other Data - Other Data
Ted - 367898766 - Other Data - Other Data - Other Data
Here's what I came up with so far:
Code:
$ss_dir = "/home/private/ss/"; # Social Security directory. $number_to_show = "20"; # The default number of SS to show.
$use_flock = "1"; # File locking? (0=No, 1=Yes)
opendir(SSDIR, "$ss_dir");
@all_ss = grep(/\.txt$/,readdir(SSDIR));
closedir(SSDIR);
foreach $one_ss (@all_ss)
{
open (SS,"$ss_dir$one_ss");
if ($use_flock == "1")
{
flock SS, 2;
}
@entries = <SS>;
foreach $line (@entries)
{
@fields = split(/\|/,$line);
if ($z<$number_to_show)
{
$z++;
# Do the sorting from highest SS number to lowest.
# Print the sorted stuff to the screen.
}
}
close (SS);
}
The only thing I can't figure out is how to sort the data.
Please, help me out here.
Thank you.