CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Intermediate:
Annotation program help!

 



wixdfast
Novice

Jan 16, 2009, 6:05 PM

Post #1 of 14 (1651 views)
Annotation program help! Can't Post

Hi, I'm working on this weeks programming class homework and I'm really struggling. If you could help out at all, I'd greatly appreciate it. Our instructions are to:
"When running, the user should be able to type whatever notes he wants for as long as he wants.
(You will terminate by typing CTRL+D)
When you type CTRL+D, the program terminates and you end up with an updated filename.txt file that all the notes will be stored in.
The filename.txt should then contain the following items:
-All the contents of your notes
-A date indicating when the notes were taken"

So again, even just helping getting starting, would be excellent. I normally understand this stuff, but this week I'm just not getting it. And our teacher doesn't really like giving us help, unless we absolutely need it. Horrible teacher, imho. Thanks again!


FishMonger
Veteran / Moderator

Jan 16, 2009, 6:34 PM

Post #2 of 14 (1646 views)
Re: [wixdfast] Annotation program help! [In reply to] Can't Post

perldoc -f open
perldoc -f localtime


KevinR
Veteran


Jan 16, 2009, 7:21 PM

Post #3 of 14 (1642 views)
Re: [wixdfast] Annotation program help! [In reply to] Can't Post

What have you tried so far?
-------------------------------------------------


shawnhcorey
Enthusiast


Jan 17, 2009, 5:18 AM

Post #4 of 14 (1637 views)
Re: [wixdfast] Annotation program help! [In reply to] Can't Post

Are you using Linux or Windows?

In Linux, CTRL+D is the end of file for input from a terminal. In Windows, it's CRTL+Z.

__END__

I love Perl; it's the only language where you can bless your thingy.

Perl documentation is available at perldoc.perl.org. The list of standard modules and pragmatics is available in perlmodlib.

Get Markup Help. Please note the markup tag of "code".


wixdfast
Novice

Jan 17, 2009, 4:38 PM

Post #5 of 14 (1625 views)
Re: [shawnhcorey] Annotation program help! [In reply to] Can't Post

Well the very rough beginning is:

#!/usr/bin/perl -w

print "Enter annotation.pl then the filename.txt to begin the program\n";
open (FILE, ">>filename.txt);)
$timestampe = `date`;


The bolded part being from the teachers notes. Not sure whether to use his or FisherMonger's instructions.

And to shawnhcorey, I'm using Windows, but I'm using Cygwin as the terminal window.


FishMonger
Veteran / Moderator

Jan 17, 2009, 8:11 PM

Post #6 of 14 (1616 views)
Re: [wixdfast] Annotation program help! [In reply to] Can't Post


Quote
$timestampe = `date`;

The bolded part being from the teachers notes.


If that's what your instructor is teaching you, then I'd agree; you have a horrible teacher. No self respecting experienced Perl programmer would ever use that line of code and should not teach others to use it. Use localtime in scalar context.


shawnhcorey
Enthusiast


Jan 18, 2009, 5:30 AM

Post #7 of 14 (1607 views)
Re: [wixdfast] Annotation program help! [In reply to] Can't Post

Since your instructor has given you some code, I shall too. This is considered the proper way to start all Perl scripts:

Code
#!/usr/bin/perl 

use strict;
use warnings;


The three argument open is considered better than the two argument one and you should always check to make sure it works.

Code
open my $journal_fh, '>>', 'filename.txt' or die "could not open filename.txt: $!\n";


And you should check prints and closes to the file handle to make sure they work too.

Code
print $journal_fh scalar( localtime ), "\n" or die "could not print to filename.txt: $!\n";


For the rest of the program, see `perldoc File::Copy`.

__END__

I love Perl; it's the only language where you can bless your thingy.

Perl documentation is available at perldoc.perl.org. The list of standard modules and pragmatics is available in perlmodlib.

Get Markup Help. Please note the markup tag of "code".


wixdfast
Novice

Jan 18, 2009, 12:50 PM

Post #8 of 14 (1595 views)
Re: [shawnhcorey] Annotation program help! [In reply to] Can't Post

Thank you shawnhcorey. But I'm still a little confused. When you said the File::Copy, did you mean this?
http://perldoc.perl.org/File/Copy.html
Where/how would I implement that into the code? I'm sorry I'm just really getting frustrated with this. Again, any help would be greatly appreciated. Thanks again!


wixdfast
Novice

Jan 18, 2009, 2:41 PM

Post #9 of 14 (1588 views)
Re: [wixdfast] Annotation program help! [In reply to] Can't Post

Here is a scan of the actual homework assignment. Hope this helps! Thanks again guys!
http://i44.tinypic.com/10yjl7o.jpg


FishMonger
Veteran / Moderator

Jan 18, 2009, 8:23 PM

Post #10 of 14 (1577 views)
Re: [wixdfast] Annotation program help! [In reply to] Can't Post

File::Copy is not needed. I think Shawn was confused as to the exact requirements of your homework.

90% of the script is very basic and I'm having a hard time figuring out what part(s) you're having trouble with and how to guide you without doing the assignment for you, which I'm not going to do.

Please explain what portion(s) you need help with and show us your complete code along with any errors/warnings that you're receiving.


wixdfast
Novice

Jan 20, 2009, 4:16 PM

Post #11 of 14 (1560 views)
Re: [FishMonger] Annotation program help! [In reply to] Can't Post

Well, to be honest, that'd be ok with me, but that's up to you. So far I've gotten:
#!/usr/bin/perl -w

$word = <STIND>;
print "Enter the text you wish to write.:\n";
while (1)
{
$input =<STDIN>;
if($input eq $word)
{
print $input . "Type CTRL+D to exit the program.:\n";
}
if ($input eq "CTRL+D\n")
{
last;
}
}
exit;

It works, but I doubt it's even close to what he wants. If you wanted to do it for me, or atleast spell it out for me, I'd be eternally grateful. It'd save me a lot of trouble and headaches. I've already spent 8+ hours on this one project alone. I'm thinking that if I can't get this project done I might just drop the class. But whatever you decide, I'll be content with. You've already given me lots of help and I really do appreciate it. It's nice to know that there are some great people still in this world. Thank you very much for you time.


FishMonger
Veteran / Moderator

Jan 21, 2009, 5:58 AM

Post #12 of 14 (1550 views)
Re: [wixdfast] Annotation program help! [In reply to] Can't Post

Here's a basic outline.

Open a filehandle to the filename that was passed to the script.

Tell the user what you expect them to do before receiving any additional input.

Check each line of input for the CTRL-D character, not the string "CTRL-D".
perldoc -f ord
perdoc -f chr

Send each line of input to the output file, with the exception of the CTRL-D char.

When the CTRL-D char is received, output the timestamp to the file and exit.


wixdfast
Novice

Jan 21, 2009, 3:46 PM

Post #13 of 14 (1544 views)
Re: [FishMonger] Annotation program help! [In reply to] Can't Post

Here's what I've gotten thus far, but it doesn't quite work:

#!/usr/bin/perl -w

$file = $ARGV[0];

open(FILEHANDLE, ">>$file");

$timestamp = `date`;

print($timestamp);

$input = <STDIN>;

print(FILEHANDLE $input);

if ($input = <CTRL-D>)
{
print(FILEHANDLE $timestamp);

exit;
}


How do I fix the two error syntax errors at 16 and 20? Thanks!


FishMonger
Veteran / Moderator

Jan 21, 2009, 7:07 PM

Post #14 of 14 (1541 views)
Re: [wixdfast] Annotation program help! [In reply to] Can't Post

You need to lookup the ascii code for the CTRL-D and test for that code value.

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives