Let's Get Together

AUTHOR

David Romano

In this event, you need to combine the contents of several text files into one. There are a number of things you need to do in order to succeed at this event:

  • 1.

Find all the text files (files with a .txt file extension) in the folder C:\Scripts. (Make sure you use C:\Scripts; if you use any other folder you wonโ€™t receive the points for this event.)

  • 2.

Create a new file named C:\Temp\Newfile.txt. (Once again, the full path and name for the file your script creates must match this exactly.)

  • 3.

Copy the first line โ€“ and only the first line โ€“ from each text file in C:\Scripts into your new file.

Thatโ€™s it. When your script completes you should have a new file in your C:\Temp folder named Newfile.txt. Newfile.txt should contain the first line โ€“ followed by a carriage-return linefeed โ€“ from each text file in C:\Scripts.

http://web.archive.org/web/20081227065437/http://www.microsoft.com/technet/scriptcenter/funzone/games/games08/bevent3.mspx

use v6;



my $run-dir = $*PROGRAM-NAME.IO.dirname;
my @files = dir($run-dir).sort;
my $output = $*SPEC.catdir($run-dir, 'newfile.txt');
$output.IO.unlink if $output.IO.e;

# only select .txt files required for this event
for @files.grep: { .match(/test.*\.txt $$/) } {
    my $inputfh = open $_, :r;
    my $outputfh = open $output, :a;
    $outputfh.say( $($inputfh.get) ); # $(...) forces item context
    .close for $inputfh, $outputfh;
}

# vim: expandtab shiftwidth=4 ft=perl6

See Also

advanced-2008

Could I Get Your Phone Number?

advanced-2008

Skating on Thin Ice

advanced-2008

You Call That a Strong Password?

advanced-2008

Blackjack!

beginner-2007

One of These Things is not Like the Others

beginner-2008

Pairing Off

beginner-2008

Pairing off

beginner-2008

Pairing Off

beginner-2008

Coffee Break

beginner-2008

Coffee Break

beginner-2008

Random Guess

beginner-2008

Random Guess

beginner-2008

Bowling

README.md

The Camelia image is copyright 2009 by Larry Wall. "Raku" is trademark of the Yet Another Society. All rights reserved.