Posted by pc486 Tue 27th Feb 2007 20:30 - Syntax is Perl - 40 views
Download | New Post | Modify | Hide line numbers
  1. #!/usr/bin/env perl
  2.  
  3. use strict;
  4. use warnings;
  5.  
  6. BlogEntry;
  7.  
  8. sub new {
  9.   ; # first arg is the package name, dump it
  10.   my $self = {};
  11.   ($self->{title}, $self->{author}, $self->{content}, $self->{datetime}) =
  12.     (@_, ());
  13.   $self;
  14.   $self;
  15. }
  16.  
  17. sub title    { $_[0]->{title}    }
  18. sub author   { $_[0]->{author}   }
  19. sub content  { $_[0]->{content}  }
  20. sub datetime { $_[0]->{datetime} }
  21.  
  22. main;
  23.  
  24. my @blog;
  25. @blog, new BlogEntry("Post 1", "ParadoxHeart", "The first post in the Ruby blog.");
  26. @blog, new BlogEntry("Post 2", "ParadoxHeart", "The second post in the Ruby blog.");
  27.  
  28. foreach my $entry (@blog){
  29.   $entry->title() . "\n";
  30.   "By: " . $entry->author() . "\n";
  31.   "=" x 20 . "\n";
  32.   $entry->content() . "\n";
  33. }
  34.  

PermaLink to this entry https://pastebin.co.uk/11087
Posted by pc486 Tue 27th Feb 2007 20:30 - Syntax is Perl - 40 views
Download | New Post | Modify | Hide line numbers

 

Comments: 0