Re: [Q] How to eval an EXPR once and make it stick

2004-01-27 Thread Rob Dixon
Sam wrote: > > # Print lines (or not) until a blank line is found (or not) > > # This function works fine. But in the spirit of learning...read on. > > sub print_lines_ok { > > my ($output, $blank_lines) = @_; > > if ($blank_lines) { > do { > print if $output; > >

Re: [Q] How to eval an EXPR once and make it stick

2004-01-28 Thread Jeff 'japhy' Pinyan
On Jan 27, Rob Dixon said: >Sam wrote: >> >> sub print_lines_ok { >> my ($output, $blank_lines) = @_; >> if ($blank_lines) { >> do { >> print if $output; >> $_ = <>; >> } while (/^\s*$/ and not eof); >> } else { >> do { >> pri

Re: [Q] How to eval an EXPR once and make it stick

2004-01-28 Thread John W. Krahn
Sam wrote: > > # Print lines (or not) until a blank line is found (or not) > # This function works fine. But in the spirit of learning...read on. > > sub print_lines_ok { > my ($output, $blank_lines) = @_; > if ($blank_lines) { > do { > print if $output; You are prin

Re: [Q] How to eval an EXPR once and make it stick

2004-01-28 Thread Rob Dixon
John W. Krahn wrote: > > Sam wrote: > > > > # Print lines (or not) until a blank line is found (or not) > > # This function works fine. But in the spirit of learning...read on. > > > > sub print_lines_ok { > > my ($output, $blank_lines) = @_; > > if ($blank_lines) { > > do { > >

Re: [Q] How to eval an EXPR once and make it stick

2004-01-28 Thread Sam
Thanks for all your responses; I learned a bit. 1. I wasn't clear on $_ in my email; that's being read elsewhere in program so it's already set by the time print_lines is called. 2. Will you bet your life on this equivalence: "not /^\s*$/ == /\S/"? I believe it's safer to negate an EXPR than

Re: [Q] How to eval an EXPR once and make it stick

2004-01-28 Thread Rob Dixon
Sam wrote: > > Thanks for all your responses; I learned a bit. Good: well done. > 1. I wasn't clear on $_ in my email; that's being read elsewhere in program so > it's already set by the time print_lines is called. You /mustn't/ use $_ like that. It's meant to be an 'it' in places like For e

Re: [Q] How to eval an EXPR once and make it stick

2004-01-28 Thread Sam
--- Rob Dixon <[EMAIL PROTECTED]> wrote: > Sam wrote: > > > > Thanks for all your responses; I learned a bit. > > Good: well done. > > > 1. I wasn't clear on $_ in my email; that's being read elsewhere in > program so > > it's already set by the time print_lines is called. > > You /mustn't/ us

Re: [Q] How to eval an EXPR once and make it stick

2004-01-28 Thread Tassilo von Parseval
On Wed, Jan 28, 2004 at 09:11:51AM -0800 Sam wrote: > 4. As for the generalized case, I learned about using refs. Anonymous subs > also work. > > my $re = sub { return /^\s*$/; }; > my $nre = sub { return not &$re; }; > my $expr = $blank ? $re : $nre; > do ... while (&$expr and not eof); >

Re: [Q] How to eval an EXPR once and make it stick

2004-01-28 Thread John W. Krahn
Sam wrote: > > Thanks for all your responses; I learned a bit. > > 1. I wasn't clear on $_ in my email; that's being read elsewhere in program so > it's already set by the time print_lines is called. > > 2. Will you bet your life on this equivalence: "not /^\s*$/ == /\S/"? Yes I will. :-)

Re: [Q] How to eval an EXPR once and make it stick

2004-01-28 Thread John W. Krahn
Sam wrote: > > --- Rob Dixon <[EMAIL PROTECTED]> wrote: > > Sam wrote: > > > > > > But I'm not sure which is faster though. > > > > If you don't know, it doesn't matter. > > > > If your software is /too/ slow and you would die for a 10% speed increase > > then > > check out > > > > use Benchmark

Re: [Q] How to eval an EXPR once and make it stick

2004-01-29 Thread Rob Dixon
Sam wrote: > > Rob wrote: > > > > Sam wrote: > > > 1. I wasn't clear on $_ in my email; that's being read elsewhere in > > > program so it's already set by the time print_lines is called. > > > > You /mustn't/ use $_ like that. It's meant to be an 'it' in places like > > What? You want me to pass

Re: [Q] How to eval an EXPR once and make it stick

2004-01-29 Thread Rob Dixon
John W. Krahn wrote: > > Instead of using eval inside of a loop it is a > lot faster if you eval the whole loop. > > # slow > my $expr = '/$regex/'; > while ( ) { > if ( eval $expr ) { > do { something() }; > } > } > > # a lot faster > my $loop = <<'LOOP'; > while ( ) { >