Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

How do I read from one file and write my processed results to another file?

( #118844=categorized question: print w/ replies, xml ) Need Help??
Contributed by Zombie sandmuto on Oct 15, 2001 at 14:33 UTC
Q&A  > files


Description:

I have written code that accepts input from one file named pa1.dat. It checks whether the input is accepted by a certain finite automaton. If it is, then it is supposed to output the results in another file named pa1.out. The problem is that after compling successfully without any errors, the pa1.out file doesn't contain anything. Would you please tell me the correct syntax on how to get the data from one file and direct output to another file?

Answer: what statements are used in order to obtain results in another file?
contributed by davorg

This is still the Finite Automata problem from the University of Zimbabwe isn't it?

In order to read or write from a file, you need to first open a filehandle. Here's a link to the documentation on open.

You output data to a file using the print function. Documentation on print is here.

If you have any further questions, perhaps you could show us the code - we'd then be able to be more help.

Please (register and) log in if you wish to add an answer



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • Outside of code tags, you may need to use entities for some characters:
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others contemplating the Monastery: (4)
    As of 2014-09-20 00:17 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      How do you remember the number of days in each month?











      Results (151 votes), past polls