From: Dr.Ruud on
Willem wrote:

> AFAIK, when you call <map> in void context, it turns into a <for> internally.

Don't think that.

For example, in some older versions of Perl, a map inside a map only
releases memory in the outsidest map, which can make things horrible.

--
Ruud
From: Ilya Zakharevich on
On 2010-06-26, C.DeRykus <derykus(a)gmail.com> wrote:
> On Jun 25, 11:16�pm, Ilya Zakharevich <nospam-ab...(a)ilyaz.org> wrote:
>> On 2010-06-26, C.DeRykus <dery...(a)gmail.com> wrote:
>>
>> > � � � () = <>;
>>
>> Try to do it with a terabyte file...
>>
>
> Hm, sounds like I need to look more closely...
>
> So a humongous temp array gets built with only
> the resulting assignment being optimized away...?

Hmm, IN PRINCIPLE, one could have coded recognition of this construct,
and would somehow advise pp_readline() that its output is going to be
ignored. However, given the frequency of this construct, I doubt this
was ever done.

> perl -MO=Concise -e "()=<>"
> 8 <@> leave[1 ref] vKP/REFC ->(end)
> 1 <0> enter ->2
> 2 <;> nextstate(main 1 -e:1) v:{ ->3
> 7 <2> aassign[t3] vKS ->8
> - <1> ex-list lK ->6
> 3 <0> pushmark s ->4
> 5 <1> readline[t2] lK/1 ->6
> 4 <#> gv[*ARGV] s ->5
> - <1> ex-list lK ->7
> 6 <0> pushmark s ->7
> - <0> stub lPRM* ->-

The only way I know to advise an OP is via flags. So one should
compare flags on the `readline' OP with those on "usual" list contents
readline. If they are identical, there is little chance that this
construct is memory-optimized. (But they may differ by "other
reasons" as well...)

Yours,
Ilya
From: Ilya Zakharevich on
On 2010-06-26, Willem <willem(a)turtle.stack.nl> wrote:
> I don't know if <> is smart enough to recognize void context though,
> can probably be tested with a large file and a memory checker tool.

I use void-context-<> all the time (to skip one line); but only with
defined $/.

I vaguely remember that about 10 years ago, I put some code to
optimize behaviour of pp_readline() in void context (or at least, had
a WISH to do so; no way to distinguish now, sigh). And, definitely,
about the same time I had the same problem as the OP: avoiding SIGPIPE
on the OTHER side of the pipe.

Putting 2 and 2 together, I MIGHT have put there
optimization-of-<>-with-undefined-$/-in-void-context. But no, I have
no memory of actually doing it. And I have strong doubts about
somebody else doing it as well...

So I think it is not wise to expect that the core of Perl would be
able to help with this problem. I would just do $/ = (1<<20), and do
a loop.

Hope this helps,
Ilya
From: Ilya Zakharevich on
On 2010-06-27, Willem <willem(a)turtle.stack.nl> wrote:
> ) void context always translates to scalar context for built-in functions.
> )
> ) void context usually translates to scalar context for user-defined functions.

> What about map ?

> AFAIK, when you call <map> in void context, it turns into a <for> internally.

Irrelevant: SIDE EFFECTS of map in scalar and list context are the same.

Hope this helps,
Ilya
From: John Kelly on
On Sun, 27 Jun 2010 23:53:10 +0000 (UTC), Ilya Zakharevich
<nospam-abuse(a)ilyaz.org> wrote:

>I had the same problem as the OP: avoiding SIGPIPE
>on the OTHER side of the pipe.

>So I think it is not wise to expect that the core of Perl would be
>able to help with this problem. I would just do $/ = (1<<20), and do
>a loop.

I went with the loop.

(1<<20) is a 1 meg of memory. (1<<15) may run nearly as fast on a large
file (untested).



--
Web mail, POP3, and SMTP
http://www.beewyz.com/freeaccounts.php