Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling

Re: Determining the dayname for the last day of any given month

by leocharre (Priest)
on Jun 19, 2006 at 14:38 UTC ( #556264=note: print w/replies, xml ) Need Help??

in reply to Determining the dayname for the last day of any given month

($day = `date +\%A`)=~s/\s//g;

Uses perl core util "date", that's what -I- would do. It would drive home the idea that a diff tech might be a solution to the current problem. But you may not subscribe to the ideology. Also, backticks are nonos in webstuffs.

Edited: davorg - deleted content restored

This is wrong. That's for today's date. Yes, date is an external unix core util. Using multiple programs is the unix way.

Replies are listed 'Best First'.
Re^2: Determining the dayname for the last day of any given month
by davorg (Chancellor) on Jun 19, 2006 at 14:43 UTC
    Uses perl core util "date"

    date isn't a "perl core util", it's an external operating system command. It's a bad idea to use external commands if they aren't necessary because a) you can never be sure what external commands will be available if you have to move your program to another platform and b) opening a new shell unnecessarily is inefficient. Perl contains everything you need to handle dates. There is no need to use external programs.


    "The first rule of Perl club is you do not talk about Perl club."
    -- Chip Salzenberg

      There are times when I do shell out because I am certain your points a) and b) aren't going to bite me or are outweighed by ease/speed of implementation (I am a unix admin and not a developer after all:) but there is another issue with calling external programs which can hurt as much- the output of any external command you call is not in your control and can change. Usually this will be to the detriment of your program which is relying on the output format to parse out the required data. Click, Boom! Ouch!

      Do not seek to follow in the footsteps of the wise. Seek what they sought. -Basho

      As I had said, it all depends on what you are trying to achieve. If you're on deadline for a temporary hack, and there is such a thing- then you should be aware of your enviroment. Perl was originally a collection of unix hacks and tools, wasn't it?

      You don't code a distribution app that depends on unix tools. But on day to day problems in the office, maintaining a hosting server, whatever- It's shooting yourself in the foot if you imagine perl is the only tool in your box.

      The original post was what would *i* do. I got tangled up and wrote a solution that does not address the question.

        That all makes perfect sense. Just two points to add:

        1. People come to this site a look for examples of code to copy or adapt. If you're writing code here that is just a quick hack (and there's no reason why you shouldn't do that) then please clearly mark it as such so that it doesn't get misused in the future.
        2. There are, of course, times when running external programs is a good idea (as long as you're aware of my caveats above). Date and time handling is never one of those times :-)

        "The first rule of Perl club is you do not talk about Perl club."
        -- Chip Salzenberg

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://556264]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (4)
As of 2017-12-16 20:53 GMT
Find Nodes?
    Voting Booth?
    What programming language do you hate the most?

    Results (459 votes). Check out past polls.