![]() |
|
go ahead... be a heretic | |
PerlMonks |
Re: Inserting Code Before an -n/-p Loopby Eily (Monsignor) |
on Dec 18, 2018 at 10:03 UTC ( [id://1227384]=note: print w/replies, xml ) | Need Help?? |
Neat trick indeed! When I read your post I immediatly thought about a problem I had a few weeks ago where I wished such a construct existed (BEGIN worked alright, but it makes the command a bit long and I like them to fit on one line :) ). Turns out my problem is exactly the one mentioned in the linked post. And Discipulus has a good point about being able to glob your arguments :) I was a little confused by the deparsed code because the print 'foo' doesn't come right after the 5; But it's just that -M'5; print "foo"' is actually turned into use 5; print 'foo'; and the first statement is turned into an equivalent BEGIN + require block :) It also works if you are already including a module without parameters It technically works with strict, but if you're going to use that kind of constructs you probably don't need strictures :P Also, if you want to say something in that BEGIN-like code, since the feature would only be added by -E after the inserted code, you'll have to do something like: -M'v5.10; say "just saying"' Edit: who needs O::Deparse anyway?
In Section
Meditations
|
|