Hi,
I am trying to add the finishing touches to a code that I have created which sorts data entries in a file according to numeric value. This is the code:
[code=perl]
#!/usr/bin/perl
opendir(DH, "directory" ) || die "Cannot open directory";
my $file = "file";
closedir(DH);
open(NF, "new file") || die "Cannot open file";
open(FH,...
User Profile
Collapse
-
Sorting columns
Hi,
apologies for not replying to my last post, "Extracting maximum values", at that time I did not actually have any code and so could not provide it. I am, however, now following a different method, by trying to use the sort function in reverse to send the maximum values to the top of the column, so I can then simply print them to a new file. This is not school work by the way, I am in work trying to do this and I just think this... -
Extract maximum values
Hi,
I am currently working on a task which requires me to extract the top 10 maximum values from a column in a text file and print them to a new file. I am just wondering what would be the best way of doing this? I have done a bit of research on the &max function, but I am not sure if this would be the right thing for me. Thanks in advance. -
I shall try that tomorrow. Thanks. -
Remove last new line
Hi,
I have a slight problem which is probably easy to fix, but I am still fairly new to this language. Firstly, I shall show you the code:
[CODE=perl]
#!/usr/bin/perl
opendir(DIR, "directory" ) || die "Cannot open directory";
my @file = readdir(DIR);
closedir(DIR);
open(NF, ">file" || die "Cannot open file");
foreach my $file... -
Hi again,
I figured out the problem. I have opened the new output file within the loop, which is why it is constantly writing the data in over and over again. Bit of a schoolboy error. I moved the line that opens the new file to immediately after where I closed the directory, and also moved the line that closes the new file to the bottom, so none of it is inside the foreach loop. This has solved the problem, it only reads the data in once...Leave a comment:
-
I tried this and I had limited success. It wrote in every single line, but because the new file itself now has the 0000, 0004, 0100 and 0200 that I declared it must have, it is now writing the text in over and over again. I think what I need to do is to exclude the new filename so that it will ignore these numbers in this file. Is that right?
ThanksLeave a comment:
-
Ok, thanks, I will try that. I only put "file" in to save having the full file address and name....Leave a comment:
-
Writing to file
Hi,
I have almost got my script to do what I want it to do, but I have one final problem for which I have been searching for a solution. My code now successfully reads the content of every text file in the directory, and in the correct order. I have also managed to exclude the lines I didn't want. What I need to do now is to write this very long list of text to a new file. I have tried this, but what it seems to be doing is writing a line... -
Hi,
thanks for the help. I put the filenames into an array and used the sort function and it worked.Leave a comment:
-
Sorting filenames
Hi,
I started using Perl a few days ago on Linux and have a bit of a problem. I have created a code which reads the content of every file in a directory, which works, but reads them in the wrong order. I have been searching for a function which reads the files in numerical order according to the filename (the letters in each filename are the same but the numbers increase by one each time). This is the code:
[code=perl]
...
No activity results to display
Show More
Leave a comment: