The Community Forums

Interact with an entire community of cPanel & WHM users!
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

File Operation Functions not working in perl???

Discussion in 'General Discussion' started by CamronFry, Jan 14, 2005.

  1. CamronFry

    CamronFry BANNED

    Joined:
    Jan 1, 2005
    Messages:
    49
    Likes Received:
    0
    Trophy Points:
    0
    Why wont file operations work? Ex.
    open(DATA, "$datafile");
    @record = <DATA>;
    close(DATA);
    foreach(@record){
    print "$_\n\n";
    }

    jailshell-2.05b$ perl -w readdata.cgi
    Use of uninitialized value in string at readdata.cgi line 13.
    Content-type: text/html

    HEADER

    readline() on closed filehandle DATA at readdata.cgi line 19.
    FOOTER


    Why isnt the open function working?
     
  2. chirpy

    chirpy Well-Known Member

    Joined:
    Jun 15, 2002
    Messages:
    13,475
    Likes Received:
    20
    Trophy Points:
    38
    Location:
    Go on, have a guess
    Without seeing the script, it's impossible to say and the snippet shown is terribly programmed to not show the problem.

    I would point out the very sloppy programming, which if cleaned up might show where you are going wrong with the code:

    open (DATA, "<$datafile") or die "Unable to open $datafile - $!";
    @record = <DATA>;
    close (DATA) or die "Unable to close $datafile - $!";
    chomp @record;
    foreach (@record) {print "$_\n\n"}

    As I said, though, without the script it's impossible to say.
     
Loading...

Share This Page