Note that there are some explanatory texts on larger screens.

plurals
  1. POWhat is the smallest program possible to parse an email message header?
    primarykey
    data
    text
    <p>the homework: <a href="http://www.cs.rit.edu/~waw/networks/prob1.082.html" rel="nofollow noreferrer">http://www.cs.rit.edu/~waw/networks/prob1.082.html</a></p> <p>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:</p> <blockquote> <ol start="8"> <li><p>Write a computer program that reads the header on an e-mail message and deletes all lines except those that begin with</p> <p>From:, To:, Subject: and Cc:.</p></li> </ol> <p>CONTEST -- Who can write the shortest program that does this.</p> </blockquote> <p>So after thinking for a bit I decided that the following Perl code was as small as I could do this.</p> <pre><code>#!/usr/bin/perl while (&lt;&gt;) { print "$_" if ($_ =~ m/^(To:|From:|Subject:|Cc:)/); } </code></pre> <p>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.</p> <p>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.</p> <p>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.</p> <p>Thanks for looking!</p> <p>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.</p> <p>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?</p> <p>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.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload