Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Re^2: FilerProbe: Tidy Up Your NetApp

by bpoag (Monk)
on Jun 24, 2009 at 22:51 UTC ( [id://774538]=note: print w/replies, xml ) Need Help??


in reply to Re: FilerProbe: Tidy Up Your NetApp
in thread FilerProbe: Tidy Up Your NetApp

Hey jw! ....I would disagree with your statement that I am using subroutines "incorrectly". I often use subroutines as a way of keeping different blocks of code separated logically. Which is why I'm not passing data to subroutines. Which is why I'm not returning any data from subroutines. Which is why I don't have any data local to the subroutines. Which is why I have everything of any consequence they might operate on declared globally up front. :)

I usually begin every program I write with a bunch of plain english statements that describe what I want the code to do. These statements end up being boiled down into subroutine names, just like what you see here. I've found it keeps code complexity to a minimum, makes debugging easier, and even prevents bloat/function creep in a way. It's a single-purpose, flat procedural script broken down into blocks for my own and others' readability, and just fleshed out as I go.. You'll notice that not only are most of the subroutines only called once, and a couple of the subroutines do next to nothing at all.

As for the $temp[1]=~s/\/$//g; statement you pointed out, you are correct -- applying the regex globally is superfluous. s/\/$//g is functionally identical to s/\/$//. I probably had it match for something else earlier, changed it, and forgot to remove the g. :)

Replies are listed 'Best First'.
Re^3: FilerProbe: Tidy Up Your NetApp
by jdporter (Paladin) on Jun 25, 2009 at 19:13 UTC

    Congratulations - You're 10% of the way toward structured programming. Hold on to your hat - In the next decade, a new paradigm called "object-oriented programming" will sweep the world.

    jwkrahn is absolutely spot on in all of his criticisms.

    For a program such as this, which is a simple stand-alone script which has one thing to do and does it just once, it doesn't matter too much. It may get your job done, but it's not the kind of code I'd be waving in front of my boss.

      All criticisms?
      And you only really need subroutines for code that will be called more than once but all your sbroutines are only called one time.
      Last time I checked breaking code out into subroutines to make the code easier to maintain was still encouraged even if the subroutine is only called once. So are you really advocating one big chunk of code?

      Elda Taluta; Sarks Sark; Ark Arks

        So are you really advocating one big chunk of code?

        No, I am advocating the proper use of subroutines.   :-)

      Again, the reason for my breaking code out into subroutines is simply for readability. I usually begin any kind of script I write in plain English statements, which form the skeleton of what I write. I break them out into subroutines versus blocks of comments because in the process of writing it, program flow may (and often does) change.

      Lacking any psychic ability, I have no idea in advance of whether there will be a need or a benefit to calling a certain block of code repeatedly. If so, then great, I already have it pegged out as a subroutine. Now, i've heard rumors of people being psychic. Russians, usually. But for me, not so much. So, if you have a crystal ball, by all means, please share it with the class. Most people don't whip out stencils and flowchart their ideas on graph paper in a boardroom like it's 1958 before they sit down at the keyboard. We can afford to work on the fly.

      And for the record, my boss loves it. :) It saves us a crapload of time and effort, and provides a heads-up for half a dozen people in the department. I even wrote a version that pumps out results in preformatted HTML, readable in Outlook. :)

      Regardless, you have inspired me. I think I may write a flat script that repeatedly calls a subroutine that tries to determine what object is currently lodged in your butt, and remove it, so you'll feel better. Call it a hunch, but I have a sneaking suspicion it's a rhinoceros beetle. Only the sharp horn-like protrusion on the head of a rhinoceros beetle could account for your seemingly patronizing, antagonistic, and downright irritable response. The evidence is overwhelming that you may have a bug up your butt...Certainly, enough so to warrant the creation of a script for its detection and removal.

      May I ask if you have visited a tropical region or rainforest lately?

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others contemplating the Monastery: (3)
As of 2025-11-08 12:30 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    What's your view on AI coding assistants?





    Results (65 votes). Check out past polls.

    Notices?
    hippoepoptai's answer Re: how do I set a cookie and redirect was blessed by hippo!
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.