News for hackers. Stuff that matters.
Re:Why Perl? by Mithaldu on Wednesday November 16, 2011 @06:25AM (#3242687)

  > I'd like to reply to your Unicode link with another link:
  >
  > http://stackoverflow.com/questions/6162484/why-does-modern-perl-avoid-utf-8-by-default/6163129#6163129
To which i have to say that both the Great Unicode Shootout as well as that answer are written by the same person. The point being: Yes, Perl's Unicode support is not perfect. But honestly? It's still the best you can get out there.

  > >Exceptions are built in:
  > 
  > Exceptions are built in?
The both of you are conflating two things here:

- Exception flow control - Exception objects

The former is in fact implemented in Perl core via eval { literal code block }. In earlier versions of Perl there were issues where DESTROY blocks, called on object destruction, were able to clobber $@, i.e. the error message. Thus Try::Tiny has become the preferred method of doing exception flow control:

  my $x;
  try {
      die 'foo';
  }
  catch {
      warn "Got a die: $_";
  } 
  finally {
      $x = 'bar';
  };
Mind, that issue has been fixed in 5.14 ( http://perldoc.perl.org/perl5140delta.html#Exception-Handlin... ), so if you're above that, you can safely use eval for your exception flow control.

  > does it support "bubbling up" the exceptions over different modules?
Yes, evals can be nested.

  > What if a module redefines signal handlers?
If it does it via local it won't even concern you. If it does it plainly you're in a bit of a bind, but in practice this kind of thing happens exceedingly rarely on CPAN outside of self-contained applications or testing/installing code.

  > I'm also not sure how the error message can be handed
  > over multiple exceptions
You die with an array reference containing the interesting exceptions.

  > or how to catch different types of exeptions.
If you know what kind of exception you expect, you write code that interrogates the scalar for that. For example, if you're expecting an object of a certain type:

handle_exception( $_ ) if blessed( $_ ) and $_->isa('Exception::Parse');

  > Finally, why are there myriads of Exception modules and
  > Error handling modules and die/croak/carp modules
Because we're collectively still trying to decide how to best handle exceptions.

  > I never came across the need of looking for a 
  > replacement for those in another language...
In other languages you get a solution plopped in front of you and have to accept it because you cannot even implement your own exception handling. If they got it right, great. If they didn't ... welp.

Anyhow, that was only the first part. The second part is Exception Objects, which is where a lot of the various CPAN modules come in. Since Perl does not provide a native exception object, you can return literally anything you wish and many people experimented to see which kind of exception object they wanted. The concensus for this has landed on Exception::Class.

  > Another point is: Very often i came across the 
  > recommendation to convert the array to a hash and then 
  > check for the key. What recommendation is that? When i
  > have a data structure that is best represented as
  > array, convert it for a simple operation? ugh...
Those recommendations are bullshit and that's where you're right. However the fact that you think Perl does not have tools to search through arrays shows a glaring gap in your knowledge. As i mentioned in another comment, Perl has excellent facilities for searching through arrays:

  > `my @hits = grep { $_ eq 'dogfood' } @array;`
  > 
  > Alternatively:
  > 
  > `use List::Util 'first'; my $has_dogfood = first { $_ eq 'dogfood' } @array;`
  > 
  > And this is in core.
Re:Why Perl? by buster on Wednesday November 16, 2011 @07:02AM (#3242781)
Thanks for your answer.

I'm very aware how to search an array in Perl. I really concentrated to much on searching in my text, whereas the critic should have been for array handling in general which i find far more inferior to other languages. From my other comment:

Example: Looking for an element and deleting it? (Taken from perlmonks.org)

  my @array = qw( your array here );
  my $search_for = "here";
  my( $index )= grep { $array[$_] eq $search_for } 0..$#array;
  splice @array, $index, 1
I'm sorry, but this is hideous, really. Just to show you an example of what "modern" languages can do:

  array = ["a", "b", "c", "d"]
  search = "b"
  array.remove(search)
  print array
     ['a', 'c', 'd']
They may have nearly the same amount of loc but imo the second one is by far more readable and not as error prone to typos or simple bugs as the Perl one.
Re:Why Perl? by Mithaldu on Wednesday November 16, 2011 @07:10AM (#3242803)
I guess i'll have to repost this here. :)

The correct answer should've been:

   @list = grep { $_ ne 'dogfood' } @list;