Hi Tom,

Thanks so much for putting the time and effort into fixing up
all these qDebugs. I had thought about using a mechanical replace
but feared that it wouldn't work because of the need to also 
drop or alter some of the conversions, ie
qDebug("%s", foo.latin1());
should, if I remember correctly, become simply
qDebug() << foo;
So it's good to hear that it's worked ok anyway!

One good turn deserves another, so I thought I'd pass on
a few tips to make your Perl programming a bit more efficient.
This is not criticism of your style at all, as a programmer
myself I always appreciate this sort of mentoring so I hope
you will too ;)

First things first, kudos for using -w (or 'use warnings;') 
but it's also good practice to put

        use strict;

in any script of more than a few lines (I habitually do it for
anything other than a one-liner). It will make your life easier 
in the long run by pointing out more errors and helping you to 
adhere to good habits and avoid bad ones.

> use vars qw/$opt_n $opt_v/;

Instead of using global variables like this, you can use
file-scoped lexicals, ie

        my ($opt_n, $opt_v);

at the top-level scope. Even better however, in terms of scalability,
is to simply have one variable for your arguments, a hash:

        my %opt;

and then use

        getopts('nv', \%opt);

and refer to your args using $opt{n} etc.
This avoids having to have 20 global variables if you have 20 options :)

>       open (I, "<$fn") or die ("Can't read $fn?!");
>       open (O, ">$ofn") or die ("Can't create temp file $ofn!");

It's useful to use the special variable $! in these error messages,
which will tell you *why* they failed if they do.
You can omit the parentheses from the dies too without losing clarity.
Eg:
        open (I, "<$fn") or die "Can't read $fn: $!";

>               my (@F)= split (/\%[-\.\d]*[A-Za-z]/, $fmt);            # %s 
> %-2d %-4.2e
>               my (@A)= split (/\s*,\s*/, $argstring);                 # list 
> of args

No need for parens here. I would definitely start these lines:
                my @F = ...
                my @A = ...
Whether you also drop them from the splits is a matter of personal taste.

Also, this regex isn't quite adequate to catch all format strings
>               my (@F)= split (/\%[-\.\d]*[A-Za-z]/, $fmt);            # %s 
> %-2d %-4.2e

because format strings can look like %02hhd or %#lx ( see printf(3) )

>                       if (scalar @A) 

can simply be

                        if (@A) 

>       close O;

When closing an output file, always check for success:

        close O or die "$ofn: Write failed: $!";

It may fail if, for example, the disk is full. If you don't check
for it, oh dear, you've lost your original file.

>               `mv $fn $fn.orig`;
>               `mv $ofn $fn`;
>       } else {
>               `rm $ofn`;
>       }

Never resort to system calls unless absolutely necessary. 
It's very hard to make them safe and reliable (these will cause
problems with any filename containing special characters). 
In this case, try:

perldoc -f rename
perldoc -f unlink

I hope you find the above useful :)

Ben


-------------------------------------------------------------------------
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://ad.doubleclick.net/clk;164216239;13503038;w?http://sf.net/marketplace
_______________________________________________
Mixxx-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/mixxx-devel

Reply via email to