Solved

print to file

Posted on 2011-09-12
5
180 Views
Last Modified: 2012-05-12
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

0
Comment
Question by:onyourmark
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 9

Expert Comment

by:parparov
ID: 36527249
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?
0
 

Author Comment

by:onyourmark
ID: 36527418
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.
0
 

Expert Comment

by:mw_cedavis
ID: 36529023
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

0
 
LVL 9

Accepted Solution

by:
parparov earned 500 total points
ID: 36529236
Oh, then it's not really a CSV file, because the output is not CSV-formatted.

The easiest way is to redirect the output into the file:

perl MissingFiles.pl directory start_file end_file > target.csv

Open in new window

0
 

Author Closing Comment

by:onyourmark
ID: 36535128
Thank you for all.
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

On Microsoft Windows, if  when you click or type the name of a .pl file, you get an error "is not recognized as an internal or external command, operable program or batch file", then this means you do not have the .pl file extension associated with …
I have been pestered over the years to produce and distribute regular data extracts, and often the request have explicitly requested the data be emailed as an Excel attachement; specifically Excel, as it appears: CSV files confuse (no Red or Green h…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Six Sigma Control Plans

734 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question