Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re: Unbelievably Obvious Debugging Tip

by Abigail-II (Bishop)
on Apr 27, 2004 at 14:29 UTC ( #348503=note: print w/ replies, xml ) Need Help??


in reply to Unbelievably Obvious Debugging Tip

Before everyone starts modifying their programs, modifying all their print statements, I'd like to point old and trusty cat. Everyone knows cat. Not everyone knows its options. -E is very useful in this regard: it makes cat print a $ at the end of each line. Other useful cat options for debugging output: -T which displays tabs as ^I, and -v which will show non-printable and non-ASCII characters using ^ and M- notation. With some versions of cat, cat -vET can also be written as cat -A.

cat is your friend. Never debug without it!

Abigail


Comment on Re: Unbelievably Obvious Debugging Tip
Re: Re: Unbelievably Obvious Debugging Tip
by Anonymous Monk on Apr 27, 2004 at 15:03 UTC
    Wow! You learn something new every day. Thanks for the tip!
Re: Re: Unbelievably Obvious Debugging Tip
by ambrus (Abbot) on Apr 27, 2004 at 18:45 UTC

    I use cat -A for ages. Yes, it is a good thing.

    Also, I often use cat -v to make nonprintable characters printable, so that if there's a C-N it wouldn't mess up my terminal, but if it's only text, it would not change. It's also a great way to see C-M's.

Re: Re: Unbelievably Obvious Debugging Tip
by benrwebb (Scribe) on Apr 27, 2004 at 20:54 UTC
    My only concern with that is people who work from a non-UNIX terminal. As I recall, the closest windows alternative (without loading Cygwin) is type, which of course has none of those options. Personally, I tend to agree with the original poster, I delimit my variables when writing logging or debugging output.
      Man, those Windows users are such lazy bastards. Too damn lazy to install a decent Unix toolkit, and too damn lazy to write a trivial Perl program. All they can do is whine that a solution is too Unix specific (never mind the fact that an open source solution for any Unix toolkit is available, not something we can say about Windows tools, can we?) Djees, you give them Perl - the portable Unix - and they still aren't satisfied.
      #!/usr/bin/perl use strict; use warnings; no warnings qw /syntax/; use Getopt::Long; my ($show_ends, $show_tabs, $show_nonprinting); GetOptions ("A|show-all" => sub {$show_ends = 1; $show_tabs = 1; $show_nonprinting = 1}, "e" => sub {$show_ends = 1; $show_nonprinting = 1}, "E|show-ends" => sub {$show_ends = 1}, "t" => sub {$show_tabs = 1; $show_nonprinting = 1}, "T|show-tabs" => sub {$show_tabs = 1}, "v|show-nonprinting" => sub {$show_nonprinting = 1}, ); while (<>) { chomp; s/([\x80-\xFF])/"M-" . chr (ord ($1) - 0x80)/eg if $show_nonprinti +ng; s/([\x00-\x08])/"^" . chr (ord ($1) + 0x40)/eg if $show_nonprinti +ng; s/([\x0A-\x1F])/"^" . chr (ord ($1) + 0x40)/eg if $show_nonprinti +ng; s/\x7F/^?/g if $show_nonprinti +ng; s/\x09/^I/g if $show_tabs; s/$/\$/ if $show_ends; print "$_\n"; } __END__
      Took less than 15 minutes to write and test.

      Abigail

      Those who work without a decent set of tools get no sympathy from me. Either they are fools, or they work for fools. In both cases, the fool is the one who suffers from reduced productivity, which is as it should be.
        Who is the more foolish? The fool or the fool that follows him?

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (4)
As of 2014-12-27 09:54 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (176 votes), past polls