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 (@file)
{
@file = sort(@file);
open(FH, $file) or die "$!";
while (<FH>)
{
if ((/Jan-\d\d/) || (/Feb-\d\d/) || (/Mar-\d\d/) || (/Apr-\d\d/) || (/May-\d\d/) || (/Jun-\d\d/) || (/Jul-\d\d/) || (/Aug-\d\d/) || (/Sep-\d\d/) || (/Oct-\d\d/) || (/Nov-\d\d/) || (/Dec-\d\d/))
{
chomp;
print NF "$_\n";
}
}
}
close(NF);
close(FH);
[/CODE]
As you can see, I am printing the lines of the file with each line on a new line. However, I would like to somehow tell it not to make a new line if it is the last line in the file. I have tried removing it through the command prompt, and even tried manually removing it using a text editor, but it is always there. I am using this file to plot data, and as such there must not be a new line at the end because the values for that line will be 0. Any help would be appreciated, thanks in advance.
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 (@file)
{
@file = sort(@file);
open(FH, $file) or die "$!";
while (<FH>)
{
if ((/Jan-\d\d/) || (/Feb-\d\d/) || (/Mar-\d\d/) || (/Apr-\d\d/) || (/May-\d\d/) || (/Jun-\d\d/) || (/Jul-\d\d/) || (/Aug-\d\d/) || (/Sep-\d\d/) || (/Oct-\d\d/) || (/Nov-\d\d/) || (/Dec-\d\d/))
{
chomp;
print NF "$_\n";
}
}
}
close(NF);
close(FH);
[/CODE]
As you can see, I am printing the lines of the file with each line on a new line. However, I would like to somehow tell it not to make a new line if it is the last line in the file. I have tried removing it through the command prompt, and even tried manually removing it using a text editor, but it is always there. I am using this file to plot data, and as such there must not be a new line at the end because the values for that line will be 0. Any help would be appreciated, thanks in advance.
Comment