Hacker News new | ask | show | jobs
by pyre 5019 days ago
This is basically the author finding out something in Ruby that was copied from Perl. E.g. it allows one to do:

  $fh = open() or die("File did not open")
Instead of:

  $fh = open()
  die("File did not open") unless $fh
1 comments

What's wrong with

    $fh = open() || die("File did not open")
? The only difference is that the results of `die` are assigned to `$fh`, but I don't think `die` even returns. It still short-circuits.
Nothing is wrong with that. However the actual Perl open() would be like this...

  open my $fh, '<', 'file.txt'  or die "file.txt not found";

  open(my $fh, '<', 'file.txt') || die 'file.txt not found';
Above two lines are equivalent.
Maybe not in this specific instance, but both operators have different behaviour and different uses.