in reply to Trying to make the code more clear and clean

Is there a way to make the code shorter

Sure, just remove all the double-quotes. None of those in the excerpt you've shown are required.

  • Comment on Re: Trying to make the code more clear and clean

Replies are listed 'Best First'.
Re^2: Trying to make the code more clear and clean
by ovedpo15 (Pilgrim) on Jul 29, 2019 at 14:10 UTC
    I'll make them constans, left them as strings so it will be more readable for the readers of the thread.

      Personally I find that

      open(my $fh, '<', "$file_path") or return 0;

      is much less readable than

      open(my $fh, '<', $file_path) or return 0;

      With the former one is forced to ponder why the author has enclosed nothing more than a single scalar in double-quotes. Perhaps $file_path isn't really a scalar but is instead some path object requiring stringification. So then we have to go looking for the declaration of $file_path and assignments to it, etc. ... only to find that it's a just a plain string after all and the double-quotes are superfluous.

      Editing is an art for sure but cutting for clarity is one of the easiest tasks.

      Nothing to do with constants. They are always strings, just quoted or not. You don't need to quote them when in use as hash key names.


      The way forward always starts with a minimal test.