GitHub PullRequestReviewCommentEvent at 2014-07-25 08:22:23
Repository: Perl-Training
Actor: ardavey
Payload: {"action":"created","comment":{"url":"https://api.github.com/repos/SandyThomson/Perl-Training/pulls/comments/15390554","id":15390554,"diff_hunk":"@@ -0,0 +1,96 @@\n+#!/usr/bin/perl\n+\n+use strict;\n+use warnings;\n+\n+main();\n+\n+sub main {\n+  my $longest_word = 0;\n+  my $highest_count = 0;\n+  my %words_seen = ();\n+\n+  print( \"Enter input (use CTRL-D when finished):\", \"\\n\" );\n+\n+  # read input\n+  while ( <> ) {\n+    chomp;\n+    $words_seen{$_}++;\n+\n+    # keep track of the longest input for the column width\n+    $longest_word = length( $_ ) if length( $_ ) > $longest_word;\n+    # keep track of the largest count the column width\n+    $highest_count = $words_seen{$_} if $words_seen{$_} > $highest_count;\n+  }\n+\n+  my $table_properties = get_table_properties( $longest_word, length( $highest_count ) );\n+  print_header( $table_properties );\n+  print_content( $table_properties, \\%words_seen );\n+}\n+\n+# Simply prints the table header\n+sub print_header {\n+  my ( $table ) = @_;\n+\n+  _print_divider( $table );\n+  printf( $table->{column_format}, $table->{word_column_length}, $table->{word_column_header}, $table->{count_column_length}, $table->{count_column_header} );\n+  _print_divider( $table );\n+}\n+\n+# Prints the words seen and divides that row from the next\n+sub print_content {\n+  my ( $table, $word_counts ) = @_;\n+\n+  my $format = $table->{column_format};\n+  my $word_length = $table->{word_column_length};\n+  my $count_length = $table->{count_column_length};\n+\n+  foreach my $word ( sort( keys( $word_counts ) ) ) {\n+    printf( $format, $word_length, $word, $count_length, $word_counts->{$word} );\n+    _print_divider( $table );\n+  }\n+}\n+\n+sub _print_divider {\n+  my ( $table ) = @_;\n+\n+  print( '-' x $table->{table_length}, \"\\n\" );\n+}\n+\n+# Builds a hash with the properties of the table\n+sub get_table_properties {\n+  my ( $longest_word, $highest_count ) = @_;\n+\n+  my $table = {\n+    word_column_header => 'Word',\n+    count_column_header => 'Count',\n+    table_length => 1,\n+    column_format => \"|%*s|%*s|\\n\",\n+\n+    # will be set below\n+    word_column_length => undef,\n+    count_column_length => undef\n+    };\n+\n+  # set word column length and add to table length\n+  if ( $longest_word > length( $table->{word_column_header} ) ) {\n+    $table->{word_column_length} = $longest_word;\n+  }\n+  else {\n+    $table->{word_column_length} = length( $table->{word_column_header} );\n+  }\n+  $table->{table_length} += $table->{word_column_length} + 1;\n+\n+  # set count column length and add to table length\n+  if ( $highest_count > length( $table->{count_column_header} ) ) {\n+    $table->{count_column_length} = $highest_count;\n+  }\n+  else {\n+    $table->{count_column_length} = length( $table->{count_column_header} );\n+  }\n+  $table->{table_length} += $table->{count_column_length} + 1;\n+\n+  return $table\n+} ## end sub get_table_properties\n+","path":"chapter6/abs/exercise_2.pl","position":95,"original_position":95,"commit_id":"a31e446195504b1a9df6496d9c66331be8d11507","original_commit_id":"a31e446195504b1a9df6496d9c66331be8d11507","user":{"login":"ardavey","id":2790047,"avatar_url":"https://avatars.githubusercontent.com/u/2790047?","gravatar_id":"b4c4f6ce5e8b42c6ece06190d1fbf3c0","url":"https://api.github.com/users/ardavey","html_url":"https://github.com/ardavey","followers_url":"https://api.github.com/users/ardavey/followers","following_url":"https://api.github.com/users/ardavey/following{/other_user}","gists_url":"https://api.github.com/users/ardavey/gists{/gist_id}","starred_url":"https://api.github.com/users/ardavey/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ardavey/subscriptions","organizations_url":"https://api.github.com/users/ardavey/orgs","repos_url":"https://api.github.com/users/ardavey/repos","events_url":"https://api.github.com/users/ardavey/events{/privacy}","received_events_url":"https://api.github.com/users/ardavey/received_events","type":"User","site_admin":false},"body":"You might like to look at something like http://search.cpan.org/~lunatic/Text-ASCIITable-0.20/lib/Text/ASCIITable.pm for future table formatting.","created_at":"2014-07-25T08:22:23Z","updated_at":"2014-07-25T08:22:23Z","html_url":"https://github.com/SandyThomson/Perl-Training/pull/33#discussion_r15390554","pull_request_url":"https://api.github.com/repos/SandyThomson/Perl-Training/pulls/33","_links":{"self":{"href":"https://api.github.com/repos/SandyThomson/Perl-Training/pulls/comments/15390554"},"html":{"href":"https://github.com/SandyThomson/Perl-Training/pull/33#discussion_r15390554"},"pull_request":{"href":"https://api.github.com/repos/SandyThomson/Perl-Training/pulls/33"}}},"pull_request":{"url":"https://api.github.com/repos/SandyThomson/Perl-Training/pulls/33","id":18850363,"html_url":"https://github.com/SandyThomson/Perl-Training/pull/33","diff_url":"https://github.com/SandyThomson/Perl-Training/pull/33.diff","patch_url":"https://github.com/SandyThomson/Perl-Training/pull/33.patch","issue_url":"https://api.github.com/repos/SandyThomson/Perl-Training/issues/33","number":33,"state":"open","title":"For review","user":{"login":"arranstobbs","id":2933781,"avatar_url":"https://avatars.githubusercontent.com/u/2933781?","gravatar_id":"2e0a54f7b32766f81bf64c80082fba89","url":"https://api.github.com/users/arranstobbs","html_url":"https://github.com/arranstobbs","followers_url":"https://api.github.com/users/arranstobbs/followers","following_url":"https://api.github.com/users/arranstobbs/following{/other_user}","gists_url":"https://api.github.com/users/arranstobbs/gists{/gist_id}","starred_url":"https://api.github.com/users/arranstobbs/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/arranstobbs/subscriptions","organizations_url":"https://api.github.com/users/arranstobbs/orgs","repos_url":"https://api.github.com/users/arranstobbs/repos","events_url":"https://api.github.com/users/arranstobbs/events{/privacy}","received_events_url":"https://api.github.com/users/arranstobbs/received_events","type":"User","site_admin":false},"body":"","created_at":"2014-07-24T17:08:40Z","updated_at":"2014-07-25T08:22:23Z","closed_at":null,"merged_at":null,"merge_commit_sha":"bbd79bd5ea78f7f780f5769c9ffa2bae3b590c8c","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/SandyThomson/Perl-Training/pulls/33/commits","review_comments_url":"https://api.github.com/repos/SandyThomson/Perl-Training/pulls/33/comments","review_comment_url":"https://api.github.com/repos/SandyThomson/Perl-Training/pulls/comments/{number}","comments_url":"https://api.github.com/repos/SandyThomson/Perl-Training/issues/33/comments","statuses_url":"https://api.github.com/repos/SandyThomson/Perl-Training/statuses/a31e446195504b1a9df6496d9c66331be8d11507","head":{"label":"SandyThomson:abs_chapter_6","ref":"abs_chapter_6","sha":"a31e446195504b1a9df6496d9c66331be8d11507","user":{"login":"SandyThomson","id":7848639,"avatar_url":"https://avatars.githubusercontent.com/u/7848639?","gravatar_id":"84cd01049ccc9c34b12919e305494a66","url":"https://api.github.com/users/SandyThomson","html_url":"https://github.com/SandyThomson","followers_url":"https://api.github.com/users/SandyThomson/followers","following_url":"https://api.github.com/users/SandyThomson/following{/other_user}","gists_url":"https://api.github.com/users/SandyThomson/gists{/gist_id}","starred_url":"https://api.github.com/users/SandyThomson/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/SandyThomson/subscriptions","organizations_url":"https://api.github.com/users/SandyThomson/orgs","repos_url":"https://api.github.com/users/SandyThomson/repos","events_url":"https://api.github.com/users/SandyThomson/events{/privacy}","received_events_url":"https://api.github.com/users/SandyThomson/received_events","type":"User","site_admin":false},"repo":{"id":20683185,"name":"Perl-Training","full_name":"SandyThomson/Perl-Training","owner":{"login":"SandyThomson","id":7848639,"avatar_url":"https://avatars.githubusercontent.com/u/7848639?","gravatar_id":"84cd01049ccc9c34b12919e305494a66","url":"https://api.github.com/users/SandyThomson","html_url":"https://github.com/SandyThomson","followers_url":"https://api.github.com/users/SandyThomson/followers","following_url":"https://api.github.com/users/SandyThomson/following{/other_user}","gists_url":"https://api.github.com/users/SandyThomson/gists{/gist_id}","starred_url":"https://api.github.com/users/SandyThomson/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/SandyThomson/subscriptions","organizations_url":"https://api.github.com/users/SandyThomson/orgs","repos_url":"https://api.github.com/users/SandyThomson/repos","events_url":"https://api.github.com/users/SandyThomson/events{/privacy}","received_events_url":"https://api.github.com/users/SandyThomson/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/SandyThomson/Perl-Training","description":"Corresponds with the Learning Perl O'Reilly book","fork":false,"url":"https://api.github.com/repos/SandyThomson/Perl-Training","forks_url":"https://api.github.com/repos/SandyThomson/Perl-Training/forks","keys_url":"https://api.github.com/repos/SandyThomson/Perl-Training/keys{/key_id}","collaborators_url":"https://api.github.com/repos/SandyThomson/Perl-Training/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/SandyThomson/Perl-Training/teams","hooks_url":"https://api.github.com/repos/SandyThomson/Perl-Training/hooks","issue_events_url":"https://api.github.com/repos/SandyThomson/Perl-Training/issues/events{/number}","events_url":"https://api.github.com/repos/SandyThomson/Perl-Training/events","assignees_url":"https://api.github.com/repos/SandyThomson/Perl-Training/assignees{/user}","branches_url":"https://api.github.com/repos/SandyThomson/Perl-Training/branches{/branch}","tags_url":"https://api.github.com/repos/SandyThomson/Perl-Training/tags","blobs_url":"https://api.github.com/repos/SandyThomson/Perl-Training/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/SandyThomson/Perl-Training/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/SandyThomson/Perl-Training/git/refs{/sha}","trees_url":"https://api.github.com/repos/SandyThomson/Perl-Training/git/trees{/sha}","statuses_url":"https://api.github.com/repos/SandyThomson/Perl-Training/statuses/{sha}","languages_url":"https://api.github.com/repos/SandyThomson/Perl-Training/languages","stargazers_url":"https://api.github.com/repos/SandyThomson/Perl-Training/stargazers","contributors_url":"https://api.github.com/repos/SandyThomson/Perl-Training/contributors","subscribers_url":"https://api.github.com/repos/SandyThomson/Perl-Training/subscribers","subscription_url":"https://api.github.com/repos/SandyThomson/Perl-Training/subscription","commits_url":"https://api.github.com/repos/SandyThomson/Perl-Training/commits{/sha}","git_commits_url":"https://api.github.com/repos/SandyThomson/Perl-Training/git/commits{/sha}","comments_url":"https://api.github.com/repos/SandyThomson/Perl-Training/comments{/number}","issue_comment_url":"https://api.github.com/repos/SandyThomson/Perl-Training/issues/comments/{number}","contents_url":"https://api.github.com/repos/SandyThomson/Perl-Training/contents/{+path}","compare_url":"https://api.github.com/repos/SandyThomson/Perl-Training/compare/{base}...{head}","merges_url":"https://api.github.com/repos/SandyThomson/Perl-Training/merges","archive_url":"https://api.github.com/repos/SandyThomson/Perl-Training/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/SandyThomson/Perl-Training/downloads","issues_url":"https://api.github.com/repos/SandyThomson/Perl-Training/issues{/number}","pulls_url":"https://api.github.com/repos/SandyThomson/Perl-Training/pulls{/number}","milestones_url":"https://api.github.com/repos/SandyThomson/Perl-Training/milestones{/number}","notifications_url":"https://api.github.com/repos/SandyThomson/Perl-Training/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/SandyThomson/Perl-Training/labels{/name}","releases_url":"https://api.github.com/repos/SandyThomson/Perl-Training/releases{/id}","created_at":"2014-06-10T11:45:33Z","updated_at":"2014-07-03T11:06:01Z","pushed_at":"2014-07-24T17:06:16Z","git_url":"git://github.com/SandyThomson/Perl-Training.git","ssh_url":"git@github.com:SandyThomson/Perl-Training.git","clone_url":"https://github.com/SandyThomson/Perl-Training.git","svn_url":"https://github.com/SandyThomson/Perl-Training","homepage":null,"size":1396,"stargazers_count":0,"watchers_count":0,"language":"Perl","has_issues":true,"has_downloads":true,"has_wiki":true,"forks_count":0,"mirror_url":null,"open_issues_count":8,"forks":0,"open_issues":8,"watchers":0,"default_branch":"master"}},"base":{"label":"SandyThomson:master","ref":"master","sha":"2b7058bcb969f7f24cd894f79542b6d0ddae4c69","user":{"login":"SandyThomson","id":7848639,"avatar_url":"https://avatars.githubusercontent.com/u/7848639?","gravatar_id":"84cd01049ccc9c34b12919e305494a66","url":"https://api.github.com/users/SandyThomson","html_url":"https://github.com/SandyThomson","followers_url":"https://api.github.com/users/SandyThomson/followers","following_url":"https://api.github.com/users/SandyThomson/following{/other_user}","gists_url":"https://api.github.com/users/SandyThomson/gists{/gist_id}","starred_url":"https://api.github.com/users/SandyThomson/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/SandyThomson/subscriptions","organizations_url":"https://api.github.com/users/SandyThomson/orgs","repos_url":"https://api.github.com/users/SandyThomson/repos","events_url":"https://api.github.com/users/SandyThomson/events{/privacy}","received_events_url":"https://api.github.com/users/SandyThomson/received_events","type":"User","site_admin":false},"repo":{"id":20683185,"name":"Perl-Training","full_name":"SandyThomson/Perl-Training","owner":{"login":"SandyThomson","id":7848639,"avatar_url":"https://avatars.githubusercontent.com/u/7848639?","gravatar_id":"84cd01049ccc9c34b12919e305494a66","url":"https://api.github.com/users/SandyThomson","html_url":"https://github.com/SandyThomson","followers_url":"https://api.github.com/users/SandyThomson/followers","following_url":"https://api.github.com/users/SandyThomson/following{/other_user}","gists_url":"https://api.github.com/users/SandyThomson/gists{/gist_id}","starred_url":"https://api.github.com/users/SandyThomson/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/SandyThomson/subscriptions","organizations_url":"https://api.github.com/users/SandyThomson/orgs","repos_url":"https://api.github.com/users/SandyThomson/repos","events_url":"https://api.github.com/users/SandyThomson/events{/privacy}","received_events_url":"https://api.github.com/users/SandyThomson/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/SandyThomson/Perl-Training","description":"Corresponds with the Learning Perl O'Reilly book","fork":false,"url":"https://api.github.com/repos/SandyThomson/Perl-Training","forks_url":"https://api.github.com/repos/SandyThomson/Perl-Training/forks","keys_url":"https://api.github.com/repos/SandyThomson/Perl-Training/keys{/key_id}","collaborators_url":"https://api.github.com/repos/SandyThomson/Perl-Training/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/SandyThomson/Perl-Training/teams","hooks_url":"https://api.github.com/repos/SandyThomson/Perl-Training/hooks","issue_events_url":"https://api.github.com/repos/SandyThomson/Perl-Training/issues/events{/number}","events_url":"https://api.github.com/repos/SandyThomson/Perl-Training/events","assignees_url":"https://api.github.com/repos/SandyThomson/Perl-Training/assignees{/user}","branches_url":"https://api.github.com/repos/SandyThomson/Perl-Training/branches{/branch}","tags_url":"https://api.github.com/repos/SandyThomson/Perl-Training/tags","blobs_url":"https://api.github.com/repos/SandyThomson/Perl-Training/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/SandyThomson/Perl-Training/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/SandyThomson/Perl-Training/git/refs{/sha}","trees_url":"https://api.github.com/repos/SandyThomson/Perl-Training/git/trees{/sha}","statuses_url":"https://api.github.com/repos/SandyThomson/Perl-Training/statuses/{sha}","languages_url":"https://api.github.com/repos/SandyThomson/Perl-Training/languages","stargazers_url":"https://api.github.com/repos/SandyThomson/Perl-Training/stargazers","contributors_url":"https://api.github.com/repos/SandyThomson/Perl-Training/contributors","subscribers_url":"https://api.github.com/repos/SandyThomson/Perl-Training/subscribers","subscription_url":"https://api.github.com/repos/SandyThomson/Perl-Training/subscription","commits_url":"https://api.github.com/repos/SandyThomson/Perl-Training/commits{/sha}","git_commits_url":"https://api.github.com/repos/SandyThomson/Perl-Training/git/commits{/sha}","comments_url":"https://api.github.com/repos/SandyThomson/Perl-Training/comments{/number}","issue_comment_url":"https://api.github.com/repos/SandyThomson/Perl-Training/issues/comments/{number}","contents_url":"https://api.github.com/repos/SandyThomson/Perl-Training/contents/{+path}","compare_url":"https://api.github.com/repos/SandyThomson/Perl-Training/compare/{base}...{head}","merges_url":"https://api.github.com/repos/SandyThomson/Perl-Training/merges","archive_url":"https://api.github.com/repos/SandyThomson/Perl-Training/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/SandyThomson/Perl-Training/downloads","issues_url":"https://api.github.com/repos/SandyThomson/Perl-Training/issues{/number}","pulls_url":"https://api.github.com/repos/SandyThomson/Perl-Training/pulls{/number}","milestones_url":"https://api.github.com/repos/SandyThomson/Perl-Training/milestones{/number}","notifications_url":"https://api.github.com/repos/SandyThomson/Perl-Training/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/SandyThomson/Perl-Training/labels{/name}","releases_url":"https://api.github.com/repos/SandyThomson/Perl-Training/releases{/id}","created_at":"2014-06-10T11:45:33Z","updated_at":"2014-07-03T11:06:01Z","pushed_at":"2014-07-24T17:06:16Z","git_url":"git://github.com/SandyThomson/Perl-Training.git","ssh_url":"git@github.com:SandyThomson/Perl-Training.git","clone_url":"https://github.com/SandyThomson/Perl-Training.git","svn_url":"https://github.com/SandyThomson/Perl-Training","homepage":null,"size":1396,"stargazers_count":0,"watchers_count":0,"language":"Perl","has_issues":true,"has_downloads":true,"has_wiki":true,"forks_count":0,"mirror_url":null,"open_issues_count":8,"forks":0,"open_issues":8,"watchers":0,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/SandyThomson/Perl-Training/pulls/33"},"html":{"href":"https://github.com/SandyThomson/Perl-Training/pull/33"},"issue":{"href":"https://api.github.com/repos/SandyThomson/Perl-Training/issues/33"},"comments":{"href":"https://api.github.com/repos/SandyThomson/Perl-Training/issues/33/comments"},"review_comments":{"href":"https://api.github.com/repos/SandyThomson/Perl-Training/pulls/33/comments"},"review_comment":{"href":"https://api.github.com/repos/SandyThomson/Perl-Training/pulls/comments/{number}"},"commits":{"href":"https://api.github.com/repos/SandyThomson/Perl-Training/pulls/33/commits"},"statuses":{"href":"https://api.github.com/repos/SandyThomson/Perl-Training/statuses/a31e446195504b1a9df6496d9c66331be8d11507"}}}}