Alberto Manuel =?ISO-8859-1?Q?Brand=E3o_Sim=F5es?= <[EMAIL PROTECTED]> writes:
>Only to be sure,
> this means that when we use $/ with something other than "\n" Perl will
>slurp all the file to memory?
No. It slurps till it finds $/ value. Each "line" you get with <>
ends with $/ (if possible)
i.e. in your case it is as if perl is "matching" m#^.*?</tu>$#
to build lines.
So if you file isn't really separated like that large chunks of it may be
read into memory.
So
$/ = "</tu>";
my $header = <>;
Is going to read till it finds a '</tu>'
>
>Thanks
>Alberto
>
>On Mon, 2004-01-05 at 21:24, Billy Patton wrote:
>> Albert,
>>
>> try this
>>
>> while (<>)
>> {
>> s!header([^/>]+)/>!<header$1></header>!;
>> ...
>> print;
>> }
>>
>> Process a single line at a time, not the whole file.
>>
>> ___ _ ____ ___ __ __
>> / _ )(_) / /_ __ / _ \___ _/ /_/ /____ ___
>> / _ / / / / // / / ___/ _ `/ __/ __/ _ \/ _ \
>> /____/_/_/_/\_, / /_/ \_,_/\__/\__/\___/_//_/
>> /___/
>> Texas Instruments ASIC Circuit Design Methodlogy Group
>> Dallas, Texas, 214-480-4455, [EMAIL PROTECTED]
>>
>> On Mon, 5 Jan 2004, Alberto Manuel BrandÃo SimÃes wrote:
>>
>> > but maybe you guys(hope this is the correct way :-/) know how to help
>> > me...
>> > I have this simple script:
>> >
>> > $/ = "</tu>";
>> >
>> > my $header = <>;
>> >
>> > # <header/> -> <header></header>
>> > $header =~ s!<header([^/>]+)/>!<header$1></header>!;
>> >
>> > # <body version...> -> <body>
>> > $header =~ s!<body[^>]+>!<body>!;
>> >
>> > # tmx version -> <tmx version="1.1">
>> > $header =~ s!<tmx version[^>]+>!<tmx version="1.1">!;
>> >
>> > # srclang -> srclang="foo"
>> > if ($header =~ m!(xml:)?lang=(["'])([^"']+)\2!) {
>> > $lang = $3;
>> > $header =~ s!srclang=(["'])[^"']+\1!srclang="$lang"!;
>> > }
>> >
>> > $header =~ s/xml:lang/lang/g;
>> > # xml:lang -> lang
>> > print $header;
>> >
>> > while(<>) {
>> > s/xml:lang/lang/g;
>> > print
>> > }
>> >
>> > Basically, a filter working on chunks (about 300bytes chunks).
>> > The problem is that I cannot process a 400MB file, because of
>> > out-of-memory.
>> > What is wrong? how can I solve it?
>> > Thanks a lot, and sorry for being a little OT.
>> >
>> > Alberto
>> >
>> >