Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Re^2: What technical benfits perl offers over python + few more questions.

by Anonymous Monk
on Nov 14, 2021 at 18:49 UTC ( #11138812=note: print w/replies, xml ) Need Help??


in reply to Re: What technical benfits perl offers over python + few more questions.
in thread What technical benfits perl offers over python + few more questions.

Hi Hippo

Here is one of the links that talks about exceptions not being part of Perl. My bad again, I got mixed up with errors and exceptions, and if you berate me for that I would totally understand- https://www.oreilly.com/library/view/mastering-perl/9780596527242/ch12.html

Given below is paragraph from the chapter -

Exceptions Perl doesnít have exceptions. Letís just get that clear right now. Lik +e some other things Perl doesnít really have, people have figured out + how to fake them. If youíre used to languages, such as Java or Pytho +n, set the bar much lower so you arenít too disappointed. In those ot +her languages, exceptions are part of the fundamental design, and tha +tís how Iím supposed to deal with all errors. Exceptions arenít part +of Perlís design, and itís not how Perl programmers tend to deal with + errors.

Unfortunately I could not find other links. I was just going from one article to another and that is how I stumbled across the said articles.

Note:- I am not hear to badmouth about Perl. Just really badly wanting to get some clarity (which the ensuing answers have provided in truckloads).

  • Comment on Re^2: What technical benfits perl offers over python + few more questions.
  • Download Code

Replies are listed 'Best First'.
Re^3: What technical benfits perl offers over python + few more questions.
by eyepopslikeamosquito (Bishop) on Nov 15, 2021 at 03:40 UTC
Re^3: What technical benfits perl offers over python + few more questions.
by hippo (Bishop) on Nov 14, 2021 at 21:39 UTC

    Exceptions are not an explicit part of the Perl language, but fatal errors are and can serve a similar purpose. However, as with many other topics, exceptions are well catered for on CPAN with almost 4000 results for "exception". If you do want to use exceptions with Perl there are many ways to do so.


    🦛

Re^3: What technical benfits perl offers over python + few more questions.
by ikegami (Patriarch) on Nov 15, 2021 at 15:50 UTC

    Perl has exceptions, and that's nothing new. Exceptions are thrown using die, and caught using eval BLOCK.

    Differences:

    • Perl operators don't throw exceptions, while the corresponding IO libraries in other languages might.

    • Perl exceptions don't automatically come with a stack trace, whereas it's common elsewhere. It's definitely possible to get stack trace from exceptions in Perl, through. See Carp::Always.

      > Perl operators don't throw exceptions, while the corresponding IO libraries in other languages might.

      could you please elaborate what you mean?

      DB<37> eval { 1/0 } or print "<$@>" <Illegal division by zero at (eval 46)[c:/Strawberry/perl/lib/perl5db. +pl:738] line 2. > DB<38>

      edit

      Probably you are talking about the kind of non-error "message" exceptions , e.g. thrown by iterators like in Python???

      Cheers Rolf
      (addicted to the Perl Programming Language :)
      Wikisyntax for the Monastery

        I think the distinction being made is maybe that in (say) Java trying to print on a closed filehandle object would throw an IOException which your code would be required to handle, whereas perl  -E 'close(STDOUT);say qq{FOOP}' will run (producing no output but also not printing any sort of error (although you could check the return from say and print $!)).

        The cake is a lie.
        The cake is a lie.
        The cake is a lie.

        ok, so you found an exception. Well, kinda. There's no IO library function that corresponds to division.

        Anyway, the point stands: Where other languages might use exception, Perl primarily returns false on error.

        Update: Clearer wording

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11138812]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (6)
As of 2022-01-27 09:58 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    In 2022, my preferred method to securely store passwords is:












    Results (70 votes). Check out past polls.

    Notices?