Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re: Idiomatic Perl?

by haukex (Archbishop)
on Mar 21, 2018 at 09:07 UTC ( [id://1211400]=note: print w/replies, xml ) Need Help??


in reply to Idiomatic Perl?

find out what is idiomatic Perl and what is not

Here's my take on how to make that a bit more idiomatic/modern/whatever:

use warnings; use strict; use IO::Prompt; print "RegEx Engine 1.0\n", "________________\n"; my $str = prompt("Gimme a string: "); my $pattern = prompt("Gimme a RegEx: "); print $str=~$pattern ? "Yes!" : "No.", "\n"; print "kthxbye\n";

(As an alternative to IO::Prompt, you could use ExtUtils::MakeMaker 'prompt'; - ExtUtils::MakeMaker is a core module, even though it has a completely different purpose. Or, there is Term::ReadLine.)

I don't want to end up writing Python in Perl.

But why not? ;-)

use Acme::Pythonic; use warnings use strict use IO::Prompt print("RegEx Engine 1.0\n________________\n") while 1: my $str = prompt("Gimme a string: ") unless length($str): last my $pattern = prompt("Gimme a RegEx: ") if $str=~$pattern: print("Yes!\n") else: print("No.\n") print("kthxbye\n")

Replies are listed 'Best First'.
Re^2: Idiomatic Perl?
by thenextfart (Novice) on Mar 21, 2018 at 13:23 UTC
            But why not ;-)        
    Because: most of the benefits learnt while learning a postmodern language such as Perl are lost when we try to implement modern languages like Python. Also, whitespace is starting to appear in my dreams.

      stevieb is right, I wasn't being (entirely) serious. Modules in the Acme:: namespace are generally meant to be tongue-in-cheek, silly, and/or not for production use. I also gave that example to show off some of the power of Perl, in this case its ability to rewrite source code on the fly.

        I get it. Meta programming is cool. (btw that's why I came to perl in the first place)

      I do believe haukex may have been being facetious (although I could be wrong).

      Also, whitespace is starting to appear in my dreams

      haukex pointed out one Acme module, so here's another for your whitespace dreams: Acme::Bleach ;)

      By the way, I completely agree with your reply about coding in one language while trying to retain and use the particulars of another.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others studying the Monastery: (3)
As of 2024-04-25 17:35 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found