in reply to get the line of ith occurrence of '>' without OPENING THE FILE

I wrote a program with only one operation:
open( FILE, "bigfile" ) or die...
it dies, but Ok with a smaller file. That is why I say I can not open it
  • Comment on Re: get the line of ith occurrence of '>' without OPENING THE FILE

Replies are listed 'Best First'.
Re: Re: get the line of ith occurrence of '>' without OPENING THE FILE
by dws (Chancellor) on Oct 06, 2002 at 00:09 UTC
    Except in very rare circumstances, the size of the file has nothing to do with whether you can open it or not. If   open(FILE, "bigfile") or die... is failing for you, avail yourself of "$!", which usually holds a valuable error message.   open(FILE, "bigfile") or die "bigfile: $!"; will do the trick.

    Also, double-check that you have a file name "bigfile" (and not "bigfile.txt") in the same directory as the script. If you're on a Unix system, then case in the filename is significant (e.g., "bigfile" isn't the same as "Bigfile").

    And please, in the future post your questions once. There might be a slight delay before your question is "approved", at which point it will be visible when you look in Newest Nodes.

Re: Re: get the line of ith occurrence of '>' without OPENING THE FILE
by diotalevi (Canon) on Oct 05, 2002 at 22:54 UTC

    Oh I see. I'd like to direct you to scottstef's How to ask questions the smart way. and jeffa's How (Not) To Ask A Question. What you've posted so far is very unhelpful. At a bare minimum you should include your program text (or more likely just the part that fails) and a description of the errors you get.

    __SIG__
    printf "You are here %08x\n", unpack "L!", unpack "P4", pack "L!", B::svref_2object(sub{})->OUTSIDE

Re: Re: get the line of ith occurrence of '>' without OPENING THE FILE
by LEFant (Scribe) on Oct 06, 2002 at 17:12 UTC
    Ginger, (I am assuming this Anonymous Monk is Ginger again) you can display an informative message when an open fails as follows:
    open FILE, "bigfile" or die "Open failed because: $!\n";
    What if the reason open failed is not "file too big to be opened?" What if it is "this account does have read permission for bigfile?"

    Revealing the mystery operating system and including a copy of the ls -l or dir, or whatever that might provide sufficient clues to us hapless volunteers to get you where you want to go. Something I have ruled out has been the source of my problems; perhaps the same is true of yours. Bob

Re: Re: get the line of ith occurrence of '>' without OPENING THE FILE
by joe++ (Friar) on Oct 06, 2002 at 18:10 UTC
    If open fails mysteriously (and you have no idea what the error message might be - you should inspect $! but others pointed this out already), you might try the sysopen() and sysread() family.

    Here you can use a buffer with a certain length and read that number of bytes at a time into thiis buffer.

    OTOH, If the problem is that you can not split on the default line endings, you might also try setting $/ to something more suitable (e.g. when the file doesn't contain newlines and you're reading a line at at time).

    { local $/ = '>'; # you were looking for this one, right? open(FILE, "bigfile.big") or die $!; while (<FILE>) { # do interesting stuff # e.g. merely count lines... } close FILE; }

    --
    Cheers, Joe