but then my x gets called for every line (with -n)

resetting the accumulator

 ls .. -1 | perl -Mstrict -nle 'print "5";my$x;BEGIN{$x=1123};print $x'
5
1123
5

5

5

5

5

5

-- vish





On 27 July 2011 14:41, Gaal Yahas <[email protected]> wrote:
> perl -Mstrict -wle 'my $x; BEGIN { $x = 42 } print $x'
>
> You almost never need INIT.
>
> On Wed, Jul 27, 2011 at 4:37 PM, Avishalom Shalit <[email protected]>
> wrote:
>>
>> THANKS,
>> i was not aware of that,
>> so, is it possible to use strict, and declare variables in a one liner
>> outside of BEGIN ?
>> (i now realize of course that the my is local to the block)
>> where should my%t=(); be ? (it isn't in INIT)
>>
>> without the strict , it works
>>
>>  head -2 U__E__103.tsv | perl -MData::Dumper -wple
>> 'INIT{my%t=();};BEGIN{my @months=qw(jan feb mar apr may jun jul aug
>> sep oct nov dec);@t{map uc,@months}=1..12;} ;
>> s/(?<=\d\d-)(...)(?=-\d\d)/$t{"$1"}/e;print$1;'
>>
>> also of course i can remove the init block
>> and it still works (with %t as a global probably)
>>
>>
>>
>> -- vish
>>
>>
>
> --
> Gaal Yahas <[email protected]>
> http://gaal.livejournal.com/
>
> _______________________________________________
> Perl mailing list
> [email protected]
> http://mail.perl.org.il/mailman/listinfo/perl
>
_______________________________________________
Perl mailing list
[email protected]
http://mail.perl.org.il/mailman/listinfo/perl

Reply via email to