Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Re: Do not understand code

by sundialsvc4 (Abbot)
on Sep 28, 2017 at 19:49 UTC ( #1200310=note: print w/replies, xml ) Need Help??


in reply to Do not understand code

Since I am already headed for another dunking in “downvote city,” I thought it might be good to give you two opportunities to do so, as I make further comment about the OP’s particular piece of source code:

unlink $file if /.BGV/;

This statement is about to perform an irrevocable act: it is going to delete a file.   The identity of the file that it is about to delete is determined by the preceding source-code which establishes the present value of the variable, $file.   But the logic which determines the decision to delete it is not even contained within the statement itself, nor within any statement which obviously surrounds it.   The “very(!) pregnant, although at first glance it does not appear so” statement is dependent upon everything which determines the then-present value of a variable, $_, which the Perl language does not even name.

“Your present task is to modify this subroutine.”   To do this successfully, you must change the source-code to incorporate the specified new behavior, but without affecting any of its present behaviors upon which any other piece of source code in the entire system might possibly depend ... and you do not have the ability to identify all of those pieces.   Nevertheless, you must, along with your change, include tests which demonstrate that your change is correct and that it has no adverse impact.   You have about fifteen changes to finish today, all to the same standard.

It should be immediately obvious what a disservice the original programmer did, both to the OP and to his/her project manager.

We must presume that the original code as originally written “worked, at the time,” but that source code is absolutely fragile and non-maintainable.   So much so that the OP failed to understand it and was (thank god) able to obtain outside assistance.

Yes, this is how I earn my daily bread today.   Hundreds of cases just like this.   An uncountable number of source-code examples.   And sometimes, a very bitter-tasting announcement to very senior executives:   “this software cannot be salvaged.”

Replies are listed 'Best First'.
Re^2: Do not understand code
by Your Mother (Bishop) on Oct 02, 2017 at 12:56 UTC
    the then-present value of a variable, $_, which the Perl language does not even name.

    I was curious if this was true, so checked English. Interestingly, to me at least, it does have a name but I admit its name is barely any better than not having one at all and probably why I didn't already know the answer without needing to look–

    perl -MEnglish -le '$_ = "moo"; print $ARG' moo

      I'm worried that this talk of translating $_ into English is neglecting the all-important needs of the Perl poet, specifically the crucial Perl haiku (5-7-5) syllable count, where traditionally $_ is pronounced as "it" and @_ as "them", as in chipmunk's winning TPC 4 poem (where his subroutine summer is both a "sum-er" and a season):

      sub summer { my $sum; $sum += $_ for @_; $sum } print summer (split);
      and is pronounced (5-7-5) like so:

      sub sum-mer my sum
      sum plus equ-als "it" for "them"
      sum print sum-mer split

        the crucial Perl haiku (5-7-5) syllable count

        Far from crucial, the 5-7-5 syllable count is unnecessary. The idea that it's central to the definition of haiku is bogus. Pure myth.

        I reckon we are the only monastery ever to have a dungeon stuffed with 16,000 zombies.

      Actually I would expect $ARGV for $_ to mostly be a side effect of @ARGV for @_. This also works for other punctuation variables and their english versions

      perl -MEnglish -E "@; = q<Hi>; say @SUBSEP" Hi
      It's not a name that perl parses, but I'd expect pretty much everyone here to understand what "the default variable" refers too.

        > to understand what "the default variable" refers too.

        We could consider adding $DEF or $DEFAULT for $_ to Perl.

        > @; = q<Hi>; say @SUBSEP

        I suppose these are just glob aliases, that's why they work for all types associated to a symbol.

        Cheers Rolf
        (addicted to the Perl Programming Language and ☆☆☆☆ :)
        Je suis Charlie!

      It takes too much energy correcting all inaccuracies in sundial posts in replies. *

      If it was possible to edit foreign posts (like in SO), sundials would be normally full of strikes and red comments.

      Cheers Rolf
      (addicted to the Perl Programming Language and ☆☆☆☆ :)
      Je suis Charlie!

      *) that's the DOS feature which makes him similar to trolls.

Re^2: Do not understand code
by Anonymous Monk on Sep 28, 2017 at 19:57 UTC
    OP is a beginner and just wanted to understand the code. theres nothing wrong with the code and everything wrong with every one of your posts in this thread. thanks for reminding everyone you're just a troll
Re^2: Do not understand code
by Anonymous Monk on Sep 28, 2017 at 20:02 UTC
    This statement is about to perform an irrevocable act: it is going to delete a file.
    There are three posibilities: 1) the file is not terribly important, 2) there is a backup of the file, and c) you are an idiot. But I'm still waiting to hear how you, in your infinite wisdom, think it should have been written. This should be good.
      "c) you are an idiot"

      He is, for sure. Absolutly resistant to advice AKA stubborn. Regards, Karl

      «The Crux of the Biscuit is the Apostrophe»

      perl -MCrypt::CBC -E 'say Crypt::CBC->new(-key=>'kgb',-cipher=>"Blowfish")->decrypt_hex($ENV{KARL});'Help

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1200310]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (8)
As of 2019-07-15 20:04 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?