Your problems are with basic open/read/write/close to files. The first parameter to open should not be the file name... it should be a file handle.

It is better to split the second parameter in two. See this simple example:

# Write to text file: open(my $fh, ">", $filename) or die "Failed open for write! $!"; print $fh "Foo\n"; # Prints to file close $fh; # Close file # Read from text file: open($fh, "<", $file_to_read) or die "Couldn't open! $!"; my $line = <$fh>; # Reads a line. chomp $line; # Removes eol chars (CR,LF) close $fh;

It is much better to write small test programs to check things like this out. I personally use oneliners all the time, like this:

perl -e 'open($fh, ">", "tst") or die "$!"; print $fh "XX\n"; close $f +h;'

What you really need is a good first book. There is a review link at the top of this page, it is better to go there, but you won't go wrong with "Perl Cookbook". Otherwise, for a quick look, try the shell cmds:

perldoc -f open perldoc perldoc perldoc perlrun perldoc Tk # (Added as Edit.)
(There is also a nice website, perldoc.perl.org.)

Edit: I'm thinking of trying out Devel::REPL instead of one-liners. It seems neat.


In reply to Re: Further On Down the Line by BerntB
in thread Further On Down the Line by socrtwo

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



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • 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, details, 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, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            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.