Re: grep substitute

2002-12-14 Thread A. Pagaltzis
* Scott Wiersdorf [EMAIL PROTECTED] [2002-12-14 13:01]:
 perl -n0777
 exit !(/pattern/)
 
 Necessary Improvements:
 
 - concisely get the pattern from the command-line (e.g., pattern as
   $ARGV[0] and the file as $ARGV[1]) such that the syntax is more like
   grep (e.g., grep 'pattern' filename = perl -args 'pattern' filename)?
 
 Extra Credit:
 
 - is there a short way to do it without slurping the whole file?

perl -neexit(/$SHELLVAR/||next) file

-- 
Regards,
Aristotle



Re: Metaprogramming

2002-12-14 Thread Randal L. Schwartz
 Bernie == Bernie Cosell [EMAIL PROTECTED] writes:

Bernie In fact, unless I'm misunderstanding how the closure works, $constant 
Bernie is exactly correct and '42' would be incorrect... 

No, that's wrong.  Read my other post.

-- 
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
[EMAIL PROTECTED] URL:http://www.stonehenge.com/merlyn/
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!



Re: Metaprogramming

2002-12-14 Thread Bernie Cosell
On 14 Dec 2002, at 16:32, Randal L. Schwartz wrote:

  Rafael == Rafael Garcia-Suarez [EMAIL PROTECTED] writes:
 
 Rafael What do you expect B::Deparse::coderef2text to do here ? Output
 Rafael something equivalent to { 42 + shift } ?
 
 Yes.  Because that would be a serialization of the current behavior.

This is where we disagree.  This deparse [to { 42 + shift}] would, IMO, 
but a uselessly broken change of the essential semantics of the 
subroutine.  Granted that either way is wrong, I think that {$constant + 
shift} is closer to being useful [if you can't actually have it correct] 
that would be { 42 + shift }.

The *essential* semantics, to my view, is that the subroutine is 
referencing a variable -- the parser has virtually no way to determine 
that the variable is actually a constant [barring some incredibly 
complicated and subtle global flow analysis], but it for-sure knows that 
the subroutine is referencing a variable [and that *NOT* a true 
constant].

I think it is a different problem, which I'm also not as sure about as 
you are, to determine exactly *when* the current value of a variable 
ought to be included as part of the semantics of a subroutine or not.

For example, in the case of your getter/setter subroutine, we would 
almost certainly agree that any deparse that *didn't* include the 
existence of and references to the share vbl would be useless.  But I'm 
not as convinced that dumping the *current*value* is necessarily 
obviously the right thing to do.  What if the shared variable were a 
global instead of a closed-lexical, would that change whether you dumped 
the value along with the subroutine or not?

But then, that kind of discussion isn't very much fun..:o)

  /B\

-- 
Bernie Cosell Fantasy Farm Fibers
mailto:[EMAIL PROTECTED] Pearisburg, VA
--  Too many people, too few sheep  --