Solved

print to file

Posted on 2011-09-12
5
173 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
  • 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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

A year or so back I was asked to have a play with MongoDB; within half an hour I had downloaded (http://www.mongodb.org/downloads),  installed and started the daemon, and had a console window open. After an hour or two of playing at the command …
In the distant past (last year) I hacked together a little toy that would allow a couple of Manager types to query, preview, and extract data from a number of MongoDB instances, to their tool of choice: Excel (http://dilbert.com/strips/comic/2007-08…
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…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

707 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now