Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
Actually, the topic is so broad and full of complexities, you need to ask a more specific question, showing some code.

As far as the code $text = <FILE> goes, look at the difference

#!/usr/bin/perl use warnings; use strict; open (FILE,"< $0 ") or die "Couldn't open: $!"; # check the difference between these two lines my $text = do {local $/; <FILE>}; #my $text = <FILE>; close FILE; print "$text\n";
In the abscence of a code example, these links may get you started. Basically, you can read a file line by line(default behavior), or sysread it in chunks. The diamond operator <> adds some magic. See diamond operator and "perldoc -f read"

Some filehandles you cannot seek on, like a socket filehandle. See read and sysread and run "perldoc -q file" and read all the sections. Remember, if you are on a unix style OS, you have file descriptors associated with each filehandle in /proc/$pid/fd. See How to close all open file descriptors after a fork? and close filehandles Remember, the file descriptors (numbers) in /proc/$pid/fd/ is where the real action takes place( at least on linux).... the filehandles are just convenience handles.

Alot of us Perl hackers are lazy, and don't close filehandles after use, just letting the system clean them up when the program exits. :-)

The one common gotcha encountered with the mix of unix and win32 systems, is that the 2 system have different line endings, so when the default line-by-line reading behavior is used to read a windows file on linux, proper line reading can get broken. Read "perldoc -f binmode".

I'm not really a human, but I play one on earth.
Old Perl Programmer Haiku

In reply to Re: File Reading and Closing confusion by zentara
in thread File Reading and Closing confusion by Anonymous Monk

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, 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
  • 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.
  • Log In?

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

    How do I use this? | Other CB clients
    Other Users?
    Others about the Monastery: (7)
    As of 2021-04-14 12:08 GMT
    Find Nodes?
      Voting Booth?

      No recent polls found