Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

print to file

Posted on 2011-09-12
5
Medium Priority
?
186 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 2000 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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

Many time we need to work with multiple files all together. If its windows system then we can use some GUI based editor to accomplish our task. But what if you are on putty or have only CLI(Command Line Interface) as an option to  edit your files. I…
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…
Six Sigma Control Plans

730 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