<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>killianfaughnan.com &#187; reading</title>
	<atom:link href="http://killianfaughnan.com/tag/reading/feed/" rel="self" type="application/rss+xml" />
	<link>http://killianfaughnan.com</link>
	<description>Just another WordPress site</description>
	<lastBuildDate>Wed, 23 Feb 2011 09:05:06 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	
		<item>
		<title>Reading From A File In Perl</title>
		<link>http://killianfaughnan.com/2008/11/12/reading-from-a-file-in-perl/</link>
		<comments>http://killianfaughnan.com/2008/11/12/reading-from-a-file-in-perl/#comments</comments>
		<pubDate>Wed, 12 Nov 2008 08:47:37 +0000</pubDate>
		<dc:creator>kfaughnan</dc:creator>
				<category><![CDATA[perl]]></category>
		<category><![CDATA[files]]></category>
		<category><![CDATA[reading]]></category>

		<guid isPermaLink="false">http://killianfaughnan.com/?p=21</guid>
		<description><![CDATA[Opening a file eading from a file in Perl is pretty simple. After all, the language is pretty much built around dealing with text. The first step is to open the file, in which case you just need to use the following: open(INFILE,"&#60; myfile.txt") or die "Can't open file: $!"; In this statement we are [...]]]></description>
			<content:encoded><![CDATA[<h3>Opening a file</h3>
<p>eading from a file in Perl is pretty simple. After all, the language is pretty much built around dealing with text. The first step is to open the file, in which case you just need to use the following:</p>
<pre>  open(INFILE,"&lt; myfile.txt") or die "Can't open file: $!";</pre>
<p>In this statement we are using the <a title="Perl Open Function" href="http://perldoc.perl.org/functions/open.html" target="_blank">open()</a> function with a filehandle and filename as arguments. We will use this filehandle for all further actions on the file. The rest of the statement will print the error &#8220;Can&#8217;t open file: $!&#8221; where $! is the filename, should the script be unable to open the file.</p>
<h3>Reading an open file and printing it&#8217;s contents</h3>
<p>To read a file which already has an open filehandleyou can use the following:</p>
<pre>  while(&lt;INFILE&gt;){
    print $_;
  }</pre>
<p>This while loop will read through the file line by line, printing the contents, until it reaches the last line where it will terminate. In Perl $_ is a special character. It represents the &#8220;default input and pattern matching space&#8221;, which in the context above means that each line of the file is assigned to $_ in turn as the file is being read. So when we use print $_ we are printing the current line, and with each iteratation of the loop that line changed to the next.</p>
]]></content:encoded>
			<wfw:commentRss>http://killianfaughnan.com/2008/11/12/reading-from-a-file-in-perl/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

