Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re^2: RFC: (DRAFT Tutorial) A Gentle Introduction to Perl 6

by u65 (Chaplain)
on Aug 06, 2015 at 02:23 UTC ( [id://1137604]=note: print w/replies, xml ) Need Help??


in reply to Re: RFC: (DRAFT Tutorial) A Gentle Introduction to Perl 6
in thread RFC: (DRAFT Tutorial) A Gentle Introduction to Perl 6

First, the purpose of this tutorial is to show how to translate a real Perl 5 program with typical, often-used statements and code idioms into the equivalent Perl 6 form, and it is not intended to show the advantages of Perl 6. Second, the greater length of the Perl 6 program is due to the extra subroutine required because of a currently non-existent module in the Perl 6 system. Third, I believe the example program's utility, although simplistic, does provide a useful template for many real-world problems.

Replies are listed 'Best First'.
Re^3: RFC: (DRAFT Tutorial) A Gentle Introduction to Perl 6
by BrowserUk (Patriarch) on Aug 06, 2015 at 03:22 UTC
    Third, I believe the example program's utility, although simplistic, does provide a useful template for many real-world problems.

    I make no claim for being especially conversant with P6.

    But. I think it is clear from my history here that I am reasonably conversant in P5.

    I downloaded your P5 example and ran it. I reformatted it to an acceptable standard. I threw away the superfluous fluff. I trimmed the unnecessary verbosity.

    I arrived at < 50 lines of workaday Perl 5 code and ... could see nothing in it that allowed it to demonstrate a single advantage of P6 over P5. Not one.

    If your purpose is to promote P6; then take council. Choose an example that exercises P6's strengths rather than it weaknesses. Trim it to its bare minimum. Then ...

    Contrast it with the best, most idiomatic, most performent, most clear; most maintainable P5 equivalent you can muster.

    My point is: demonstrating that a P6 solution to a non-problem takes more lines of code than a P5 equivalent; does not serve the purpose of persuading those of us suffering from CP6ES (Chronic Perl 6 Expectation Syndrome), that it is time for us to re-evaluate P6.

    Bad promotion is worse than no promotion. Doubt my words? Ask Gerald Ratner about his £277.5 million per word apercu; then protest my intervention.


    Anyone got any experience of this phone's predecessor?

    With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority". I knew I was on the right track :)
    In the absence of evidence, opinion is indistinguishable from prejudice.
    I'm with torvalds on this Agile (and TDD) debunked I told'em LLVM was the way to go. But did they listen!
      I downloaded your P5 example and ran it. I reformatted it to an acceptable standard. I threw away the superfluous fluff. I trimmed the unnecessary verbosity.

      Please post your version so I can see the error of my ways.

      UPDATE 1:

      I disagree with the formatting comment. My code I believe closely adheres to Prof. Conway's style. Also, I do not believe in brevity for the sake of brevity. I never know who's reading my code--most likely someone with much less Perl knowledge than most monks here.

      However, thanks to your comments, I have used perlcritic for the first time and will update the Perl 5 code soon.

        I threw it away; but here's a rough recreation:

        #! perl -slw use strict; use Data::Dump qw[ pp ]; our $i //= 'tutorial-data.txt'; our $debug //= 0; open my $in, '<', $i or die "failed to open '$i':$!"; my %users; my $userid; while( <$in> ) { chomp; warn "DEBUG: $_\n" if $debug; s[#.*$][] if /#/; next unless /\S/; my( $lead, $key, $val ) = m[^(\s+)?(\S+)\s*:\s*(.+?)\s*$] or die " +Invalid line format at line $."; $key = lc $key; if( defined $lead and length $lead ) { die "Missing userid at $." unless $userid; $val = [ split '\s*,\s*', $val ] if $key eq 'hobbies'; ## modi +fied to trim $users{ $userid }{ $key } = $val; } else { die "Missing userid at line $." unless $val; die "Userid '$val' not a positive integer at line $." unless $ +val =~ /^\d+$/; die "Userid '$val' not unique at line $." if exists $users{ $v +al }; $userid = $val; } } warn "DEBUG: Dumping user hash\n" and pp \%users if $debug;

        And a debug run:

        C:\test>p56tut -debug -i=tutorial-data.txt DEBUG: # file: tutorial-data.txt DEBUG: # a data file of users and their attributes DEBUG: # note all valid lines are in format "key: value..." DEBUG: user: 1234 # unique ID (an integer > zero) DEBUG: last: Brown DEBUG: first: Sam DEBUG: job: gunsmith DEBUG: # hobbies may be a comma-separated list DEBUG: hobbies: hunting, Perl Monging DEBUG: user: 2316 DEBUG: last: Doe DEBUG: first: Jane DEBUG: job: financial analyst DEBUG: hobbies: Python open source, bowling DEBUG: Dumping user hash { 1234 => { first => "Sam", hobbies => ["hunting", "Perl Monging"], job => "gunsmith", "last" => "Brown", }, 2316 => { first => "Jane", hobbies => ["Python open source", "bowling"], job => "financial analyst", "last" => "Doe", }, }

        With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
        Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
        "Science is about questioning the status quo. Questioning authority". I knew I was on the right track :)
        In the absence of evidence, opinion is indistinguishable from prejudice.
        I'm with torvalds on this Agile (and TDD) debunked I told'em LLVM was the way to go. But did they listen!

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others contemplating the Monastery: (5)
As of 2024-03-28 20:53 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found