User Profile

Collapse

Profile Sidebar

Collapse
dh87lfc
dh87lfc
Last Activity: Dec 3 '07, 11:29 AM
Joined: Oct 3 '07
Location:
  •  
  • Time
  • Show
  • Source
Clear All
new posts

  • dh87lfc
    started a topic Sorting problem
    in Perl

    Sorting problem

    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,...
    See more | Go to post

  • dh87lfc
    started a topic Sorting columns
    in Perl

    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...
    See more | Go to post

  • dh87lfc
    started a topic Extract maximum values
    in Perl

    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.
    See more | Go to post

  • dh87lfc
    replied to Remove last new line
    in Perl
    I shall try that tomorrow. Thanks.
    See more | Go to post

    Leave a comment:


  • dh87lfc
    started a topic Remove last new line
    in Perl

    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...
    See more | Go to post

  • dh87lfc
    replied to Writing to file
    in Perl
    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...
    See more | Go to post

    Leave a comment:


  • dh87lfc
    replied to Writing to file
    in Perl
    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?

    Thanks
    See more | Go to post

    Leave a comment:


  • dh87lfc
    replied to Writing to file
    in Perl
    Ok, thanks, I will try that. I only put "file" in to save having the full file address and name....
    See more | Go to post

    Leave a comment:


  • dh87lfc
    started a topic Writing to file
    in Perl

    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...
    See more | Go to post

  • dh87lfc
    replied to Sorting filenames
    in Perl
    Hi,
    thanks for the help. I put the filenames into an array and used the sort function and it worked.
    See more | Go to post

    Leave a comment:


  • dh87lfc
    started a topic Sorting filenames
    in Perl

    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]
    ...
    See more | Go to post
    Last edited by numberwhun; Oct 3 '07, 11:38 AM. Reason: add code tags
No activity results to display
Show More
Working...