in reply to next unless not working

Welcome! Unrelated to the question that has been answered above, consider open, note the three argument form of open, and the use of $! to display why opening failed when calling die. See also Three-arg open().

Replies are listed 'Best First'.
Re^2: next unless not working
by Fletch (Bishop) on Feb 05, 2025 at 17:22 UTC

    Good point. Playing around with qwen2.5-coder it came up with the below version incorporating both this suggestion and some of mine.

    use warnings; use strict; my $file_path = "/Users/anaordonez/Documents/my_languages.txt"; open(my $fh, '<', $file_path) or die "Sorry!! couldn't open '$file_pa +th': $!"; print "Reading file \n"; while (my $line = <$fh>) { chomp $line; print "$line\n" if $line eq "Java"; } close($fh);

    The cake is a lie.
    The cake is a lie.
    The cake is a lie.

      Curious, does the LLM explain why these changes should be made? If so can you please post the output?

        Soitanly, nyuk nyuk. I'm using aider talking to a local ollama running qwen2.5-coder and put it in "architect mode" and asked:

        behave as an experienced perl programmer. Look at the attached perl script and give 2-3 suggestions for improvement.

        Edit: Reading back it also caught (but didn't mention) the line ending problem and added chomp which I actually missed. And it improved (but didn't call out) the error message as I mentioned by moving the path into a variable and adding it to the output with $! on the end.

        Second edit: Added output running with deepseek-r1:14b afterwards with the reasoning included.