Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

open file

davidrtgdavidrtg Posts: 95Member
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.
[code]open(FILE,"$basepath/reminders_location.txt") || print "Unable to open file: $!

";[/code]

Thanks,
David

Comments

  • JonathanJonathan Posts: 2,914Member
    : 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.
    : [code]open(FILE,"$basepath/reminders_location.txt") || print "Unable to open file: $!
    ";[/code]
    :
    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:-

    open(FILE,"< $basepath/reminders_location.txt") || print "Unable to open file: $!
    ";

    To read, for example.

    Jonathan

    ###
    for(74,117,115,116){$::a.=chr};(($_.='qwertyui')&&
    (tr/yuiqwert/her anot/))for($::b);for($::c){$_.=$^X;
    /(p.{2}l)/;$_=$1}$::b=~/(..)$/;print("$::a$::b $::c hack$1.");

  • davidrtgdavidrtg Posts: 95Member
    : : 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.
    : : [code]open(FILE,"$basepath/reminders_location.txt") || print "Unable to open file: $!
    ";[/code]
    : :
    : 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:-
    :
    : open(FILE,"< $basepath/reminders_location.txt") || print "Unable to open file: $!
    ";
    :
    : To read, for example.
    :
    : Jonathan
    :
    : ###
    : for(74,117,115,116){$::a.=chr};(($_.='qwertyui')&&
    : (tr/yuiqwert/her anot/))for($::b);for($::c){$_.=$^X;
    : /(p.{2}l)/;$_=$1}$::b=~/(..)$/;print("$::a$::b $::c hack$1.");
    :
    :

    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!

    David
  • JonathanJonathan Posts: 2,914Member
    : 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!
    :
    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...).

    Jonathan

    ###
    for(74,117,115,116){$::a.=chr};(($_.='qwertyui')&&
    (tr/yuiqwert/her anot/))for($::b);for($::c){$_.=$^X;
    /(p.{2}l)/;$_=$1}$::b=~/(..)$/;print("$::a$::b $::c hack$1.");

  • davidrtgdavidrtg Posts: 95Member
    [b][red]This message was edited by davidrtg at 2004-2-9 10:20:9[/red][/b][hr]
    : : 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!
    : :
    : 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...).
    :
    : Jonathan
    :
    : ###
    : for(74,117,115,116){$::a.=chr};(($_.='qwertyui')&&
    : (tr/yuiqwert/her anot/))for($::b);for($::c){$_.=$^X;
    : /(p.{2}l)/;$_=$1}$::b=~/(..)$/;print("$::a$::b $::c hack$1.");
    :
    :

    Ahhhh.. its not that line, but the line that reads in into the array! [code](@location) = ;[/code]
    Any ideas why an array would be having problems with that size of information?

    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 and work with it that way instead of loading the whole thing into the array.

    EDIT: That did it, just did while() and all is well!

    Thanks once again Jonathan!
    David






  • JonathanJonathan Posts: 2,914Member
    : Ahhhh.. its not that line, but the line that reads in into the
    : array!
    [code]: (@location) = ;[/code]
    : Any ideas why an array would be having problems with that size of
    : information?
    :
    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.

    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.

    Is there any reason you can not do it like this:-

    [code]while ($line = ) {
    # Do stuff with $line
    }[/code]

    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.

    Jonathan

    ###
    for(74,117,115,116){$::a.=chr};(($_.='qwertyui')&&
    (tr/yuiqwert/her anot/))for($::b);for($::c){$_.=$^X;
    /(p.{2}l)/;$_=$1}$::b=~/(..)$/;print("$::a$::b $::c hack$1.");

  • davidrtgdavidrtg Posts: 95Member
    : : Ahhhh.. its not that line, but the line that reads in into the
    : : array!
    : [code]: (@location) = ;[/code]
    : : Any ideas why an array would be having problems with that size of
    : : information?
    : :
    : 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.
    :
    : 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.
    :
    : Is there any reason you can not do it like this:-
    :
    : [code]while ($line = ) {
    : # Do stuff with $line
    : }[/code]
    :
    : 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.
    :
    : Jonathan
    :
    : ###
    : for(74,117,115,116){$::a.=chr};(($_.='qwertyui')&&
    : (tr/yuiqwert/her anot/))for($::b);for($::c){$_.=$^X;
    : /(p.{2}l)/;$_=$1}$::b=~/(..)$/;print("$::a$::b $::c hack$1.");
    :
    :

    Yah, i'm thinking its that there is a restriction on the ammount of memory I can use on the server.
    Got it working with the while()!

    Thanks again,
    David
Sign In or Register to comment.