Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??

You need to specify a 'mode' when you use open. This means that you specify whether you want to read from or write to a particular file (you can do both, but you don't need that for now).

use strict; use warnings; my $INPUT; my $OUTPUT; open($INPUT, "<", "my_input_file.txt"); #the "<" tells it you want to +read from the file open($OUTPUT, ">" "my_output_file.txt"); #the ">" tells it you want to + write to the file. while(my $line=<$INPUT>){ #.. do some changes to $line .. print $OUTPUT $line #prints $line (after I've done whatever chang +es) to the file I opened as $OUTPUT }

check out here for some more info on filehandles. Also bear in mind that you can either not declare a filehandle, and just use a plain text word, e.g.  open(INPUT,"<","input_file.txt); or you can declare a variable as I did in the example above. IMO it's a better habit to get into to use a variable, as you start to get into trouble when/if you try to pass filehandles around subs (later..!)

hope this helps.
Those are my principles. If you don't like them I have others.
-- Groucho Marx

In reply to Re^4: a REFERENCE of array of hashes by why_bird
in thread a REFERENCE of array of hashes by fseng

Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":

  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?

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

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (3)
As of 2023-06-06 22:09 GMT
Find Nodes?
    Voting Booth?
    How often do you go to conferences?

    Results (29 votes). Check out past polls.