in reply to Re: Building ARRAY with grep expression NOT working
in thread Building ARRAY with grep expression NOT working

• I've used postfix versions of unless and for to reduce the number of indented blocks.

Which makes it harder for some (me) to read the code.

The reason I answer is not because of that, but because of the wrong reason you state with it. It is easy to not have indentation and stil not use postfix unless and if as you already showed on line 7. I would prefer

#!/usr/bin/env perl use strict; use warnings; my %ujs; my $file = "access_log.txt"; open my $fh, "<", $file or die "File $file not opened: $!\n"; while (<$fh>) { m/([^\/]*\.js)$/ and $ujs{$1}++; } close $fh; print "$_\n" for sort keys %ujs;

Enjoy, Have FUN! H.Merijn

Replies are listed 'Best First'.
Re^3: Building ARRAY with grep expression NOT working
by GrandFather (Saint) on Apr 01, 2020 at 07:29 UTC
    open ... or ...

    is Perl idiom and completely acceptable.

    ... and ...;

    in place of

    ... if ...;

    is a sneaky use of a logical operator and short circuit evaluation that is more appropriate to golf than production code.

    I realise that eyes adapt over time, but explaining to a neophyte how and provides conditional code needs a lot more prose than explaining as postfix if.

    Optimising for fewest key strokes only makes sense transmitting to Pluto or beyond
    A reply falls below the community's threshold of quality. You may see it by logging in.