[ale] OFFTOPIC: Perl -w oddities?
Mike Fletcher
fletch at phydeaux.org
Sun Jan 31 01:25:07 EST 1999
A few style suggestions first . . . :)
> open(TOC, "$CDA toc |");
Always check the return from open:
open( TOC, "$CDA toc |" )
or die "Can't open pipe to `$CDA': $!";
> #Get headers
> $Catagory=<TOC>;
> chop($Catagory);
chomp just removes line ends (honouring $/). chop blindly removes
the last character:
chomp( $Category );
> $TitleArtist=<TOC>;
> chop($TitleArtist);
>
> $Trash=<TOC>;
> chop($Trash);
Same on chomp/chop goes for these two as well.
> while(<TOC>) {
> chop;
chomp;
> ($Spacer, $Track, $Len, $Name)=split(' ',$_);
> $Trash=$Spacer;
> $Trash=$Len;
Since you're apparently throwing away $Spacer and $Len, you probably
want to use either:
( undef, $Track, undef, $Name ) = split( ' ', $_, 4 );
or:
( $Track, $Name ) = (split( ' ', $_, 4 ))[1,3];
> $Songs{"$Track"}="$Name";
> }
> close(TOC);
At any rate, judging from the debug output:
[...]
main::(./encodeit:44): $Songs{"$Track"}="$Name";
DB<1> s
[...]
Use of uninitialized value at ./encodeit line 44, <IN> chunk 51.
main::(./encodeit:39): while(<TOC>) {
DB<1>
What it looks like is that either $Track or $Name isn't being
initialized. You might check those variables in the debugger, or go
with the old standby:
print "\$Track `$Track'\t\$Name: `$Name'\n"
if defined( $ENV{DEBUG} );
And run your script:
DEBUG=1 perl myscript
--
Fletch | __`'/|
fletch at phydeaux.org | "I drank what?" -- Socrates \ o.O'
678 443-6239(w) | =(___)=
| U
More information about the Ale
mailing list