Solved

print to file

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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

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 …
Email validation in proper way is  very important validation required in any web pages. This code is self explainable except that Regular Expression which I used for pattern matching. I originally published as a thread on my website : http://www…
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…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

813 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

19 Experts available now in Live!

Get 1:1 Help Now