Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re: Basic debugging checklist

by LanX (Saint)
on Dec 03, 2017 at 13:54 UTC ( [id://1204800]=note: print w/replies, xml ) Need Help??


in reply to Basic debugging checklist

Hi toolic

Nice work, but may I suggest that

> Display the contents of variables using print or warn

> warn "$var\n";

is changed to

warn "<$var>";

?

Two reasons:

  • I don't see the point of disabling line and file information from warn by default by appending "\n".

    A beginner might get lost where the error originates.

  • A missing chomp is very common, surrounding brackets <...> helps finding them.

    A beginner should be made aware if his variable ends on a newline.

see

C:\>perl $var = "abc\n"; # trailing newline warn "$var\n"; warn "<$var>"; warn "$var"; __END__ abc <abc > at - line 4. abc

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

update

I just realized that your point 3 covers chomp and detecting whitespace, but I'm still not sure why you're disabling the line info in warn.

Replies are listed 'Best First'.
Re^2: Basic debugging checklist
by Athanasius (Archbishop) on Dec 03, 2017 at 15:08 UTC
Re^2: Basic debugging checklist
by davies (Prior) on Mar 01, 2020 at 22:14 UTC

    I recently got bitten by doing this. The debugging messages were going to the web page. The code was misbehaving, but no debugging messages appeared. View Source explained why - because I had used < and >, they were being interpreted as HTML tags that made no sense & were ignored. Since then, I've been using square brackets.

    Regards,

    John Davies

      yeah that's why CGI::Carp translates -> to and so on, which makes some dumps hard to read.

      My preference to <...> over [...] stems from the fact that square brackets are easily confused as array syntax by the eye.

      I'd suggest to either double or invert the angle brackets, I doubt that <<...>> or >...< are easily confused as HTML tags.

      update

      I was wrong with the simple doubling, this <<br>> would be a a break surrounded by angles.

      Though this might help ->...<-

      I'm open for other ASCII suggestions, i.e. avoiding unicode.

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

        Mostly I use the apostrophe (ASCII 39 or x27). This helps as I'm used to seeing it delimiting strings so a "missing" terminator at a line end or one with preceding space appears obvious. In those rare occurrences where this is less effective because of the prevalence of apostrophes in the data corpus I sometimes use the tilde instead (ASCII 126 or x7E). HTH.

Re^2: Basic debugging checklist
by soonix (Canon) on Dec 03, 2017 at 14:44 UTC
    I think the "\n" stems from (originally) just replacing print with warn.
      It has always been well documented that warn or die, with a terminating newline, doesn't emit the line and file info. But warn with a newline is essentially the same as print STDERR, if a little more self-documenting.

      -QM
      --
      Quantum Mechanics: The dreams stuff is made of

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others cooling their heels in the Monastery: (2)
As of 2024-04-24 17:47 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found