[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

Re: [MacPerl] Read entire file?



On 12:50 PM 12/27/00 Dan Baker <dan@dtbakerprojects.com> wrote:

> the overhead really isnt that bad... its fast.

I'm sure it isn't.  But I am opposed to paying for something I'm not
going to make use of if there is an easy alternative.

> depending on what you are trying to do with the text, you usually end
> up looping thru line by line anyway. You may not NEED to turn it into
> a scalar to process... it is possible to use modifiers in regx
> expressions to work across line breaks if that is what you need to
> do; no need for a loop if your logic can be handled in a regx.

My search string can contain a line break.  I am using those modifiers,
but if the lines are separate entities in the array, I'll never be able
to find a string that spans them - that's why I need to have all the
lines lumped together in one scalar.

    my $file_data   = "";

    open(FILEHANDLE, "<$CIncludes$file") or croak "Couldn't open
$CIncludes$file: $!";
    read(FILEHANDLE, $file_data, -s "$CIncludes$file", 0);
    close(FILEHANDLE) or croak "Couldn't close $CIncludes$file: $!";

    while ( $file_data =~ m/search pattern that spans lines/go )
    {
        my $output  = ( defined($2) ? "$1$2 $3;\n" : "$1 $3;\n" );

        # twiddle output
        
        print OUTPUTFILE "/*$file*/ $output";
    }
    

-- 
Jim Correia                                Bare Bones Software, Inc.
correia@barebones.com                     <http://web.barebones.com>

# ===== Want to unsubscribe from this list?
# ===== Send mail with body "unsubscribe" to macperl-request@macperl.org