the homework: http://www.cs.rit.edu/~waw/networks/prob1.082.html
Ok, I am still confused why this question was asked for my data communications and networks class, but here is the question from my homework:
Write a computer program that reads the header on an e-mail message and deletes all lines except those that begin with
From:, To:, Subject: and Cc:.
CONTEST -- Who can write the shortest program that does this.
So after thinking for a bit I decided that the following Perl code was as small as I could do this.
#!/usr/bin/perl
while (<>) { print "$_" if ($_ =~ m/^(To:|From:|Subject:|Cc:)/); }
All this does is act like a filter for which the only output is lines that start with From:, To:, Subject: and Cc: as specified in the question. Since there aren't any specific details I think that the above code works to at least correctly answer the question.
Now, I wonder how small a program could possibly written for this? I can understand if no one wants to post code because they think I will use it for the assignment, but I am more or less looking for suggestions and techniques that could help me write the shortest program possible.
Also, I am quite sure by shortest he is referring to actual code length. He did mention that scripting languages were the way to go so I doubt he is considering something like the overhead involved with an interpreter. This also means that he does not care which language is used.
Thanks for looking!
EDIT: Thanks for the suggestions! I had been reading questions here for quite a while, hopefully in the future I can contribute more. Also, some of the suggestions I trimmed my Perl code down to 55 bytes. I don't think we will need to deal with something like a multi-line header.
BONUS: Who can identify a good reason why this was asked in a class where we are discussing things like packet switching and client/server architectures?
EDIT2: For the record, my professor said that someone did this with something like 55 bytes. The only way I see that as being possible is if he was only asking for a simple implementation like the one above.