"Hacksaw" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > > Hacksaw wrote: > > > > > > > I know this is a no brainer, but this line of code does not always work: > > > > last if( /^\n/ or /^\s+\n/ ); > > > > > > Why not > > > > > > last if /^\s*$/; > > > > > > You don't need the () in this version of the construction. > > > > That's logically identical to > > > > last unless /\S/; > > > > That's true, but for clarity I would stick with the first.
If you think that's clearer then that's fine. > I also wouldn't be surprised if the \S construction is slower to match, given > that it has a larger set of things to look at. I haven't looked at the code, but I'd be very surprised if Perl doesn't just build a bitmap for character classes and access it by character code. That would make all character classes equally as fast. > (On the other hand, perl might just turn "unless /\S/" into "if /\s*/". That > seems like an obvious optimization. I wonder if there is an RE algebra?) Again a guess, but I doubt if there is any optimisation of regexes since it's a declarative syntax rather than a procedural one. Also, the mirror of "unless /\S/" is "if /^\s*$/" as you originally wrote. ( /\s*/ matches any string!). Cheers, Rob -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]