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 ( ) {
>
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
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
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. :-)
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);
>
--- 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
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
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
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 {
> >
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
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
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;
>
>
12 matches
Mail list logo