Welcome to Discuss Everything Forums...

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed.


 

Reply to Thread

Post a reply to the thread: File input/output in PERL! How to do it?

Your Message

Click here to log in

What color is our footer?

 
 

You may choose an icon for your message from this list

Additional Options

  • Will turn www.example.com into [URL]http://www.example.com[/URL].

Rate Thread

You may rate this thread from 1-star (Terrible) to 5-stars (Excellent) if you wish to do so.

Topic Review (Newest First)

  • 03-08-2013, 02:00 PM
    Dovahkiin88

    File input/output in PERL! How to do it?

    This is my perl program
    open(MYINPUTFILE, "<sampleinput.txt");
    while(<MYINPUTFILE>)
    {
    my($line) = $_;
    chomp($line);
    $line =~ tr/[a-z]/[A-Z]/;
    print "$line\n";
    }
    close(MYINPUTFILE);
    open(MYOUTFILE, '>sampleoutput.txt');
    print MYOUTFILE "$line";
    close(MYOUTFILE);


    This program is basically supposed to
    1) Take text from sampleinput.txt
    2) Put it in the string variable called "line".
    3) Convert all text in "line" to upper case.
    4) Print the result.
    5) Store the contents of the "line" string in sampleoutput.txt

    The program seems to execute the first 4 steps correctly, but I can't get it to do the 5th i.e store the capitalized contents in the file.

    How to make it so?

Posting Permissions

  • You may post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts
  •