in reply to Loading a Hash directly from a Regex

minor point but you don't need -w as well as use warnings .
/^(\d+)\W\d+\W\d+\W(\d+)\W\w+/;
is operating on the $_ value and is equivalent to
$_=~ /^(\d+)\W\d+\W\d+\W(\d+)\W\w+/;
which is more readable

Replies are listed 'Best First'.
Re: Re: Loading a Hash directly from a Regex
by merlyn (Sage) on Feb 14, 2002 at 16:25 UTC
    $_=~ /^(\d+)\W\d+\W\d+\W(\d+)\W\w+/;
    which is more readable
    That's debateable. If someone puts =~ and $_, I am forced to wonder if something is going on that requires them to not merely accept the default. It's misleading. I don't see how that makes it "more readable".

    Regex matches against $_ are the common form. =~ is an exception. To use an exeception to still perform the common operation is a bit like using the emergency handbrake at every stop light.

    -- Randal L. Schwartz, Perl hacker

      But the complete novice or maintainer may not know the footbrake exists.
      It's fair point around here but for novice or unperlish programmer using a = sign in the statement indicates there is an assignment going on. One of the problems/benefits of Perl is the number of unique programming concepts it has and defaults you need to learn. In my opinion Perl code is not of a high standard unless it's unreadable to a non Perl programmer. Anyway it's an old argument, I think even $_ is unreadable but I realise it has it's benefits. Especially for for the experts:)
        It's fair point around here but for novice or unperlish programmer using a = sign in the statement indicates there is an assignment going on.
        ... which is exactly why you shouldn't use it, because in =~, there is no assignment going on!

        -- Randal L. Schwartz, Perl hacker