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