--- 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/ use $_ like that. It's meant to be an 'it' in places like
What? You want me to pass the line around in a variable! :-) > > For each banana, look at it, smell it, and eat it. > > NOT > > When I say 'it', it means 'banana 3 from crate 5'. > For each apple, look at it, smell it, and eat it. > Do it to it. > > > 2. Will you bet your life on this equivalence: "not /^\s*$/ == /\S/"? I > > believe it's safer to negate an EXPR than to find some other EXPR2 that is > > equivalent to 'not EXPR'. > > Yes. (But I can think of more valuable things to bet on.) > > The first says, > > Does the entire string, from start to end, consist of zero or more 'space' > characters? > > The second says, > > Does the string contain a non-'space' character anywhere? > > The only difficulty could be with a zero-length string, which is still fine, > if > you think about it. I hear 'ya, but I like to avoid possible boundary conditions that make me think 'what if.' Just using 'not' avoids that mess. In this case the re was simple enough, but w/more complex ones... > > > 3. Hadn't thought about xor; good to know. > > Be careful though. 'xor' goes with the other low-precedence operators 'and' > and 'or', which have the high-precedence equivalents && and ||. 'xor' has > no equivalent. (The caret, ^, is a bitwise operator, which is completely > different.) > > > 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; }; > > Eek. Don't do that. It may work, but it's not at all obvious what $_ is in > the > context of a subroutine call. Having $nre dereference $re at each call isn't > your best bet either. > > > my $expr = $blank ? $re : $nre; > > do ... while (&$expr and not eof); > > The better syntax for a call to a subroutine reference is > > $expr->() > > which doesn't assume all sorts of things that could keep you awake at night > if > you knew. Ok, that's good to know. > > > 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; > > If not, don't bother. No it hums along fine. But using eval was *really* slow and clearly I was on the wrong track using it. Thanks. > > HTH, > > Rob > > > > -- > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > <http://learn.perl.org/> <http://learn.perl.org/first-response> > > __________________________________ Do you Yahoo!? Yahoo! SiteBuilder - Free web site building tool. Try it! http://webhosting.yahoo.com/ps/sb/ -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>