<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0">
  <channel>
    <title>'open file' Thread RSS Feed</title>
    <link>http://www.programmersheaven.com/</link>
    <description>Contains the latest posts from the thread 'open file' posted on the 'Perl' forum at Programmer's Heaven.</description>
    <language>en</language>
    <copyright>Copyright 2013 Programmers Heaven</copyright>
    <pubDate>Sat, 25 May 2013 00:50:08 -0700</pubDate>
    <lastBuildDate>Sat, 25 May 2013 00:50:08 -0700</lastBuildDate>
    <generator>Argotic Syndication Framework 2007.3.0.1, http://www.codeplex.com/Argotic</generator>
    <docs>http://www.rssboard.org/rss-specification</docs>
    <ttl>360</ttl>
    <image>
      <url>http://www.programmersheaven.com/images/ph.gif</url>
      <title>Programmers Heaven</title>
      <link>http://www.programmersheaven.com/</link>
      <width>88</width>
      <height>31</height>
    </image>
    <item>
      <title>open file</title>
      <link>http://www.programmersheaven.com/mb/perl/241464/241464/open-file/</link>
      <description>I'm trying to open a file but when the server runs the following it dies at the following line. It doesn't print out any error, just stops all togeather. Is file size an issue, its a 5Mb file.&lt;br /&gt;
&lt;pre class="sourcecode"&gt;open(FILE,"$basepath/reminders_location.txt") || print "Unable to open file: $!&amp;lt;br&amp;gt;\n";&lt;/pre&gt;&lt;br /&gt;
&lt;br /&gt;
Thanks,&lt;br /&gt;
David&lt;br /&gt;</description>
      <guid isPermaLink="true">http://www.programmersheaven.com/mb/perl/241464/241464/open-file/</guid>
      <pubDate>Mon, 09 Feb 2004 00:39:16 -0700</pubDate>
      <category>Perl</category>
    </item>
    <item>
      <title>Re: open file</title>
      <link>http://www.programmersheaven.com/mb/perl/241464/241517/re-open-file/#241517</link>
      <description>: I'm trying to open a file but when the server runs the following it &lt;br /&gt;
: dies at the following line. It doesn't print out any error, just &lt;br /&gt;
: stops all togeather. Is file size an issue, its a 5Mb file.&lt;br /&gt;
: &lt;pre class="sourcecode"&gt;open(FILE,"$basepath/reminders_location.txt") || print "Unable to open file: $!\n";&lt;/pre&gt;&lt;br /&gt;
: &lt;br /&gt;
Have you tried running the script from the shell?  Remember that errors go to STDERR, not STDOUT, and STDERR is not directed to CGI output.  I find it very, very unlikely that file size comes into it, but file permissions on the other had are possibly the issue - the user the script runs has will have the permissions to access the file, right?  Also try giving an access method:-&lt;br /&gt;
&lt;br /&gt;
open(FILE,"&amp;lt; $basepath/reminders_location.txt") || print "Unable to open file: $!\n";&lt;br /&gt;
&lt;br /&gt;
To read, for example.&lt;br /&gt;
&lt;br /&gt;
Jonathan&lt;br /&gt;
&lt;br /&gt;
###&lt;br /&gt;
for(74,117,115,116){$::a.=chr};(($_.='qwertyui')&amp;amp;&amp;amp;&lt;br /&gt;
(tr/yuiqwert/her anot/))for($::b);for($::c){$_.=$^X;&lt;br /&gt;
/(p.{2}l)/;$_=$1}$::b=~/(..)$/;print("$::a$::b $::c hack$1.");&lt;br /&gt;
&lt;br /&gt;</description>
      <guid isPermaLink="true">http://www.programmersheaven.com/mb/perl/241464/241517/re-open-file/#241517</guid>
      <pubDate>Mon, 09 Feb 2004 04:58:59 -0700</pubDate>
      <category>Perl</category>
    </item>
    <item>
      <title>Re: open file</title>
      <link>http://www.programmersheaven.com/mb/perl/241464/241559/re-open-file/#241559</link>
      <description>: : I'm trying to open a file but when the server runs the following it &lt;br /&gt;
: : dies at the following line. It doesn't print out any error, just &lt;br /&gt;
: : stops all togeather. Is file size an issue, its a 5Mb file.&lt;br /&gt;
: : &lt;pre class="sourcecode"&gt;open(FILE,"$basepath/reminders_location.txt") || print "Unable to open file: $!\n";&lt;/pre&gt;&lt;br /&gt;
: : &lt;br /&gt;
: Have you tried running the script from the shell?  Remember that errors go to STDERR, not STDOUT, and STDERR is not directed to CGI output.  I find it very, very unlikely that file size comes into it, but file permissions on the other had are possibly the issue - the user the script runs has will have the permissions to access the file, right?  Also try giving an access method:-&lt;br /&gt;
: &lt;br /&gt;
: open(FILE,"&amp;lt; $basepath/reminders_location.txt") || print "Unable to open file: $!\n";&lt;br /&gt;
: &lt;br /&gt;
: To read, for example.&lt;br /&gt;
: &lt;br /&gt;
: Jonathan&lt;br /&gt;
: &lt;br /&gt;
: ###&lt;br /&gt;
: for(74,117,115,116){$::a.=chr};(($_.='qwertyui')&amp;amp;&amp;amp;&lt;br /&gt;
: (tr/yuiqwert/her anot/))for($::b);for($::c){$_.=$^X;&lt;br /&gt;
: /(p.{2}l)/;$_=$1}$::b=~/(..)$/;print("$::a$::b $::c hack$1.");&lt;br /&gt;
: &lt;br /&gt;
: &lt;br /&gt;
&lt;br /&gt;
I dropped the file down to 3500 lines of text from 9576 and it loads fine. Tried it at 4000 and still wasn't loading. Its a 1.7 mb file where the original is 5.3 mb. And its another one of those cross server problems where it is working fine on one server but not the other heh. Gotta love it!&lt;br /&gt;
&lt;br /&gt;
David&lt;br /&gt;</description>
      <guid isPermaLink="true">http://www.programmersheaven.com/mb/perl/241464/241559/re-open-file/#241559</guid>
      <pubDate>Mon, 09 Feb 2004 07:35:17 -0700</pubDate>
      <category>Perl</category>
    </item>
    <item>
      <title>Re: open file</title>
      <link>http://www.programmersheaven.com/mb/perl/241464/241583/re-open-file/#241583</link>
      <description>: I dropped the file down to 3500 lines of text from 9576 and it loads fine. Tried it at 4000 and still wasn't loading. Its a 1.7 mb file where the original is 5.3 mb. And its another one of those cross server problems where it is working fine on one server but not the other heh. Gotta love it!&lt;br /&gt;
: &lt;br /&gt;
Strange, very strange.  Open should in theory just be obtaining a file handle - are you sure it's not actually failing at a later stage (e.g. when you attempt to read the entire file into an array)?  If you're sure that the open line is the problem then you can always try using the sysopen function instead.  That clears out the way any kinky stuff Perl is doing that causes the problem (I'm not familiar with the P5 I/O layer, so I'm not quite sure what it would do though...).&lt;br /&gt;
&lt;br /&gt;
Jonathan&lt;br /&gt;
&lt;br /&gt;
###&lt;br /&gt;
for(74,117,115,116){$::a.=chr};(($_.='qwertyui')&amp;amp;&amp;amp;&lt;br /&gt;
(tr/yuiqwert/her anot/))for($::b);for($::c){$_.=$^X;&lt;br /&gt;
/(p.{2}l)/;$_=$1}$::b=~/(..)$/;print("$::a$::b $::c hack$1.");&lt;br /&gt;
&lt;br /&gt;</description>
      <guid isPermaLink="true">http://www.programmersheaven.com/mb/perl/241464/241583/re-open-file/#241583</guid>
      <pubDate>Mon, 09 Feb 2004 09:44:59 -0700</pubDate>
      <category>Perl</category>
    </item>
    <item>
      <title>Re: open file</title>
      <link>http://www.programmersheaven.com/mb/perl/241464/241590/re-open-file/#241590</link>
      <description>&lt;strong&gt;&lt;span style="color: Red;"&gt;This message was edited by davidrtg at  2004-2-9 10:20:9&lt;/span&gt;&lt;/strong&gt;&lt;hr /&gt;&lt;br /&gt;
: : I dropped the file down to 3500 lines of text from 9576 and it loads fine. Tried it at 4000 and still wasn't loading. Its a 1.7 mb file where the original is 5.3 mb. And its another one of those cross server problems where it is working fine on one server but not the other heh. Gotta love it!&lt;br /&gt;
: : &lt;br /&gt;
: Strange, very strange.  Open should in theory just be obtaining a file handle - are you sure it's not actually failing at a later stage (e.g. when you attempt to read the entire file into an array)?  If you're sure that the open line is the problem then you can always try using the sysopen function instead.  That clears out the way any kinky stuff Perl is doing that causes the problem (I'm not familiar with the P5 I/O layer, so I'm not quite sure what it would do though...).&lt;br /&gt;
: &lt;br /&gt;
: Jonathan&lt;br /&gt;
: &lt;br /&gt;
: ###&lt;br /&gt;
: for(74,117,115,116){$::a.=chr};(($_.='qwertyui')&amp;amp;&amp;amp;&lt;br /&gt;
: (tr/yuiqwert/her anot/))for($::b);for($::c){$_.=$^X;&lt;br /&gt;
: /(p.{2}l)/;$_=$1}$::b=~/(..)$/;print("$::a$::b $::c hack$1.");&lt;br /&gt;
: &lt;br /&gt;
: &lt;br /&gt;
&lt;br /&gt;
Ahhhh.. its not that line, but the line that reads in into the array! &lt;pre class="sourcecode"&gt;(@location) = &amp;lt;FILE&amp;gt;;&lt;/pre&gt;&lt;br /&gt;
Any ideas why an array would be having problems with that size of information?&lt;br /&gt;
&lt;br /&gt;
EDIT: After some research I found that it could be a system memory thing. I'm going to see if I can figure a way to read each line in &amp;lt;FILE&amp;gt; and work with it that way instead of loading the whole thing into the array.&lt;br /&gt;
&lt;br /&gt;
EDIT: That did it, just did while(&amp;lt;FILE&amp;gt;) and all is well!&lt;br /&gt;
&lt;br /&gt;
Thanks once again Jonathan!&lt;br /&gt;
David&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;</description>
      <guid isPermaLink="true">http://www.programmersheaven.com/mb/perl/241464/241590/re-open-file/#241590</guid>
      <pubDate>Mon, 09 Feb 2004 10:06:31 -0700</pubDate>
      <category>Perl</category>
    </item>
    <item>
      <title>Re: open file</title>
      <link>http://www.programmersheaven.com/mb/perl/241464/241592/re-open-file/#241592</link>
      <description>: Ahhhh.. its not that line, but the line that reads in into the &lt;br /&gt;
: array!&lt;br /&gt;
&lt;pre class="sourcecode"&gt;: (@location) = &amp;lt;FILE&amp;gt;;&lt;/pre&gt;&lt;br /&gt;
: Any ideas why an array would be having problems with that size of &lt;br /&gt;
: information?&lt;br /&gt;
: &lt;br /&gt;
Probably because of the quantity of it.  If you're loading a file with 10,000 lines that's about 5 MB, it's going to require more than 5 MB of RAM.  Why?  Perl internals.  As a vast simplification, all individual items are stored in SVs (scalar values).  An AV (array value) is implemented as a collection of SVs, probably arranged in some kind of tree structure to make array index lookup logarithmic or better (I don't know that, they could have something better in there).  Each SV will have some overhead (data about the length of the value, reference count, etc) and the AV will have a little too.  Perl is pretty efficient in general, but the runtime just needs that extra data to keep track of memory usage and the like.  Still, I would *hope* it'd be able to manage this much even though it's not ideal.&lt;br /&gt;
&lt;br /&gt;
You're basically asking for a lot of memory, and it sounds like on a certain system it's just not willing to let you have it.  Possibly the server has one of those CGI resource limiting things set up to stop scripts hogging lots of resources.  Possibly there's something else getting in the way.&lt;br /&gt;
&lt;br /&gt;
Is there any reason you can not do it like this:-&lt;br /&gt;
&lt;br /&gt;
&lt;pre class="sourcecode"&gt;while ($line = &amp;lt;FILE&amp;gt;) {
    # Do stuff with $line
}&lt;/pre&gt;&lt;br /&gt;
&lt;br /&gt;
Or don't put $line and the data will be in $_.  That would probably be your best way to do it.  This way all the data ain't read in at once, the file is just read one line at a time.&lt;br /&gt;
&lt;br /&gt;
Jonathan&lt;br /&gt;
&lt;br /&gt;
###&lt;br /&gt;
for(74,117,115,116){$::a.=chr};(($_.='qwertyui')&amp;amp;&amp;amp;&lt;br /&gt;
(tr/yuiqwert/her anot/))for($::b);for($::c){$_.=$^X;&lt;br /&gt;
/(p.{2}l)/;$_=$1}$::b=~/(..)$/;print("$::a$::b $::c hack$1.");&lt;br /&gt;
&lt;br /&gt;</description>
      <guid isPermaLink="true">http://www.programmersheaven.com/mb/perl/241464/241592/re-open-file/#241592</guid>
      <pubDate>Mon, 09 Feb 2004 10:20:54 -0700</pubDate>
      <category>Perl</category>
    </item>
    <item>
      <title>Re: open file</title>
      <link>http://www.programmersheaven.com/mb/perl/241464/241647/re-open-file/#241647</link>
      <description>: : Ahhhh.. its not that line, but the line that reads in into the &lt;br /&gt;
: : array!&lt;br /&gt;
: &lt;pre class="sourcecode"&gt;: (@location) = &amp;lt;FILE&amp;gt;;&lt;/pre&gt;&lt;br /&gt;
: : Any ideas why an array would be having problems with that size of &lt;br /&gt;
: : information?&lt;br /&gt;
: : &lt;br /&gt;
: Probably because of the quantity of it.  If you're loading a file with 10,000 lines that's about 5 MB, it's going to require more than 5 MB of RAM.  Why?  Perl internals.  As a vast simplification, all individual items are stored in SVs (scalar values).  An AV (array value) is implemented as a collection of SVs, probably arranged in some kind of tree structure to make array index lookup logarithmic or better (I don't know that, they could have something better in there).  Each SV will have some overhead (data about the length of the value, reference count, etc) and the AV will have a little too.  Perl is pretty efficient in general, but the runtime just needs that extra data to keep track of memory usage and the like.  Still, I would *hope* it'd be able to manage this much even though it's not ideal.&lt;br /&gt;
: &lt;br /&gt;
: You're basically asking for a lot of memory, and it sounds like on a certain system it's just not willing to let you have it.  Possibly the server has one of those CGI resource limiting things set up to stop scripts hogging lots of resources.  Possibly there's something else getting in the way.&lt;br /&gt;
: &lt;br /&gt;
: Is there any reason you can not do it like this:-&lt;br /&gt;
: &lt;br /&gt;
: &lt;pre class="sourcecode"&gt;while ($line = &amp;lt;FILE&amp;gt;) {
:     # Do stuff with $line
: }&lt;/pre&gt;&lt;br /&gt;
: &lt;br /&gt;
: Or don't put $line and the data will be in $_.  That would probably be your best way to do it.  This way all the data ain't read in at once, the file is just read one line at a time.&lt;br /&gt;
: &lt;br /&gt;
: Jonathan&lt;br /&gt;
: &lt;br /&gt;
: ###&lt;br /&gt;
: for(74,117,115,116){$::a.=chr};(($_.='qwertyui')&amp;amp;&amp;amp;&lt;br /&gt;
: (tr/yuiqwert/her anot/))for($::b);for($::c){$_.=$^X;&lt;br /&gt;
: /(p.{2}l)/;$_=$1}$::b=~/(..)$/;print("$::a$::b $::c hack$1.");&lt;br /&gt;
: &lt;br /&gt;
: &lt;br /&gt;
&lt;br /&gt;
Yah, i'm thinking its that there is a restriction on the ammount of memory I can use on the server.&lt;br /&gt;
Got it working with the while(&amp;lt;FILE&amp;gt;)!&lt;br /&gt;
&lt;br /&gt;
Thanks again,&lt;br /&gt;
David&lt;br /&gt;</description>
      <guid isPermaLink="true">http://www.programmersheaven.com/mb/perl/241464/241647/re-open-file/#241647</guid>
      <pubDate>Mon, 09 Feb 2004 15:10:02 -0700</pubDate>
      <category>Perl</category>
    </item>
  </channel>
</rss>