Link to home
Start Free TrialLog in
Avatar of onyourmark
onyourmark

asked on

print to file

Hi. Can someone tell me how to take this kind of code and have it be written to a new csv file called missingfiles.csv and with each line be a new line in the csv file?

Thank you.
for (my $t = $start_time; $t <= $end_time; $t += $step) {
        my $file_name_pattern = strftime("%y-%m-%d_%H-*-*_sina.csv", localtime($t));
	my @matched = glob($file_name_pattern);
        print "File matching with $file_name_pattern is missing\n" unless @matched;
}

Open in new window

Avatar of parparov
parparov
Flag of United States of America image

Since the code is mine, I'll have to stand for answer, I guess. :)

What do you want the CSV fields in each line be?
Avatar of onyourmark
onyourmark

ASKER

Hi. Yes it is! By the way, I am not sure what happened with the points but I have applied for them to fix the situation.

For this, there were so many missing files that the command prompt cannot show them all. I just want to have the same output as the command prompt but in a text file.
Try this:
 
open(my $fh, ">", "files.csv")or die $!;
for (my $t = $start_time; $t <= $end_time; $t += $step) {
        my $file_name_pattern = strftime("%y-%m-%d_%H-*-*_sina.csv", localtime($t));
	my @matched = glob($file_name_pattern);
        print $fh "File matching with $file_name_pattern is missing\n" unless @matched;
}
close $fh;

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of parparov
parparov
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thank you for all.