Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

They look fine to me and it also look good written in Perl :)

  use List::Util qw(sum max min);

  # 1
  map { $_ * 2 } 1..10;

  # 2
  sum 1..1000;

  # 3
  my @wordlist = ("scala", "akka", "play framework", "sbt", "typesafe");
  my $tweet = "This is an example tweet talking about scala and sbt.";
  grep { $tweet =~ m/\b$_\b/ } @wordlist;

  # 4
  my $file_text = do { local $/ = undef; open my $fh, '<', 'data.txt'; <$fh> };
  chomp( my @file_lines = do { open my $fh, '<', 'data.txt'; <$fh> } );

  # 5
  say "Happy Birthday " . ($_ == 3 ? "dear Barry" : "to You") for 1..4;

  # 6
  my ($passed, $failed) = do { 
    my @p; \@p, [map { $_ > 60 ? push(@p, $_) && () : $_ } (49,58,76,82,88,90)]
  };

  # 8
  min(14, 35, -7, 46, 98);
  max(14, 35, -7, 46, 98);


  my $file_text = do { local $/ = undef; open my $fh, '<', 'data.txt'; <$fh> };
I have absolutely no idea what this line does. local? undef? '<'?, <$fh>? This is how you read a file in Perl?


> This is how you read a file in Perl?

Nope. I use Path::Class from CPAN...

  use Path::Class 'file';
  my $file_text = file('data.txt')->slurp;


I have absolutely no idea what this line does.

If you don't know Perl, why should you expect to? I didn't know that #(...) represented a lambda in Scala until a moment ago.


'Knowing Perl' is a rather hard thing to do when the list of completely ad-hoc implicit variables and hidden context-sensitive surprises is seemingly endless.


Your grasp of English seems to include subject-verb number agreement, and I suspect you can handle pronouns. You'd do just fine with Perl.

Yes, lots of tutorials explain it badly, and yes, lots of people say "Why should a programming language take cues from natural language?", but implicit variables and context are concepts that primary school children have mastered. They're not that difficult.


Yeah, that was not my point. These aren't but idiosyncrasies of Perl's design, and to model itself on constructs which evolved without direction and which take years to master, just to save a keystroke or two once in a blue moon, is a rather questionable road to take.

Seriously, in what other language don't you ever finish discovering what's on the default namespace, what side-effects any given statement, or hell, expression has, or which syntactic forms are supported, and on and on?

Well, PHP, but we know what the connotations of that are.

And by the way, I'm doing rather 'fine' in Perl, if not for the ever-present worrying about type mismatches (particularly arrays), the frustration of how dirty many operations are (unless you are using a recent version, regex substitution must mutate a variable), the laboriousness of the stock error handling mechanisms (make your own stack trace!) and so on.


It represents a lambda in Clojure.


You're right. I typed Clojure the first time, then for some reason uncorrected it.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: