Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

what's the easiest way to find the length of a length of text if there is no eof marker.

Replies are listed 'Best First'.
Re: length of a file
by arturo (Vicar) on Nov 17, 2000 at 00:43 UTC
    If it's a Perl string, the unhelpfully named length function (see perlfunc:length) would do the job. If it's a text file, use the -s filetest, as in

    my $size = -s $filename;

    Philosophy can be made out of anything. Or less -- Jerry A. Fodor

Re: length of a file
by rpc (Monk) on Nov 17, 2000 at 06:11 UTC
    If it's a string or a filehandle, you can do
    my $size = (stat($file))[7];
Re: length of a file
by AgentM (Curate) on Nov 17, 2000 at 00:39 UTC
    Hmmm...all files end in EOF but if you want to stop before then, let's say on a marker like 'STOP', then simply search for it while reading it in and split() appropriately.
    AgentM Systems nor Nasca Enterprises nor Bone::Easy nor Macperl is responsible for the comments made by AgentM. Remember, you can build any logical system with NOR.

      Actually, it's not at all true that all files end in EOF (as a character, at least). If I do echo test > test.txt, you'll see a 4-byte file (at least under Win32, and I'd be terribly surprised to see it different under other OS's).

        Sorry, but all files are required to end in EOF in POSIXland. Why should you be surprised? Does it make sense to do otherwise? Are you sure that Windows doesn't simply ignores EOFs in its editors and byte counts?
        AgentM Systems nor Nasca Enterprises nor Bone::Easy nor Macperl is responsible for the comments made by AgentM. Remember, you can build any logical system with NOR.
Re: length of a file
by arturo (Vicar) on Nov 17, 2000 at 00:43 UTC
    If it's a string, the unhelpfully named perlfunc:length would do the job. If it's a text file, use the -s filetest, as in

    my $size = -s $filename;
    UPDATE I'm going to ask to have this deleted. -- the later post accordingly =)

    Philosophy can be made out of anything. Or less -- Jerry A. Fodor