in reply to Working with text files, thinking my issue is with variables inside if loops

Change to
while (<FILE>) { next unless /\S/; # Skip whitespace lines if (/^ \s* Daniel \s+ Lastname \s* $/x) { $printto = "Daniel"; } elsif (/^ \s* Steffi \s+ Lastname \s* $/x) { $printto = "Steffi"; } elsif ($printto eq "Daniel") { print DANIEL $_; } elsif ($printto eq "Steffi") { print STEFFI $_; } }
  • Comment on Re: Working with text files, thinking my issue is with variables inside if loops
  • Download Code

Replies are listed 'Best First'.
Re^2: Working with text files, thinking my issue is with variables inside if loops
by holli (Abbot) on May 24, 2011 at 07:56 UTC
    Suboptimal.
    while (<FILE>) { next unless /\S/; # Skip whitespace lines if (/^ \s* Daniel \s+ Lastname \s* $/x) { $current_handle = daniels_handle; next; } elsif (/^ \s* Steffi \s+ Lastname \s* $/x) { $current_handle = steffis_handle; next; } print $current_handle $_; }


    holli

    You can lead your users to water, but alas, you cannot drown them.