OT: $0

Andy Armstrong andy at hexten.net
Sun May 17 14:01:36 BST 2009


On 17 May 2009, at 00:41, Adrian Lai wrote:
> 2009/5/17 Andy Armstrong <andy at hexten.net>:
>> So the question becomes what's the shortest one-liner that will  
>> cause what
>> ps displays to be the same as what $0 contains?
>>
>> My first attempt is
>>
>> ( $0 .= ' ' ) =~ s/ $//;
>
> $0.='';
>
> would appear to be sufficient to replicate.


Ah - interesting. I wonder why that works but $0 = $0 doesn't. Not  
because it's optimised away I think:

$ perl -MO=Concise -e '$0 = $0;'
6  <@> leave[1 ref] vKP/REFC ->(end)
1     <0> enter ->2
2     <;> nextstate(main 1 -e:1) v:{ ->3
5     <2> sassign vKS/2 ->6
-        <1> ex-rv2sv sK/1 ->4
3           <#> gvsv[*0] s ->4
-        <1> ex-rv2sv sKRM*/1 ->5
4           <#> gvsv[*0] s ->5
-e syntax OK

$ perl -MO=Concise -e '$0 = $1;'
6  <@> leave[1 ref] vKP/REFC ->(end)
1     <0> enter ->2
2     <;> nextstate(main 1 -e:1) v:{ ->3
5     <2> sassign vKS/2 ->6
-        <1> ex-rv2sv sK/1 ->4
3           <#> gvsv[*1] s ->4
-        <1> ex-rv2sv sKRM*/1 ->5
4           <#> gvsv[*0] s ->5
-e syntax OK


-- 
Andy Armstrong, Hexten



More information about the london.pm mailing list