[ale] OFFTOPIC: Perl -w oddities?

Nomad the Wanderer nomad at orci.com
Sun Jan 31 13:31:37 EST 1999


Some great tips.  Thanks,  I can use em all as I'm perl-self-taught.  Not
bad, but hey, stuff is missed.

I ended up using @Name in the split isntead of $Name, otherwise I loose
values if the name has spaces in it.  If I wanted to do:

     ( $Track, $Name ) = (split( ' ', $_, 4 ))[1,3];

but instead of 3, do 3-eol, what would I do?

The print statements give me this:

$Track `01'     $Name: `The Dam At Otter Creek'
$Track `02'     $Name: `Selling The Drama'
$Track `03'     $Name: `I Alone'
$Track `04'     $Name: `Iris'
$Track `05'     $Name: `Lightning Crashes'
$Track `06'     $Name: `Top'
$Track `07'     $Name: `All Over You'
$Track `08'     $Name: `Shit Towne'
$Track `09'     $Name: `T.B.D.'
$Track `10'     $Name: `Stage'
$Track `11'     $Name: `Waitress'
$Track `12'     $Name: `Pillar Of Davidson'
$Track `13'     $Name: `White, Discussion'
$Track `14'     $Name: `Horse (Unlisted)'

so they are all initialized.  It also complains because
I'm using @Name with $Track, saying it should be associative.  I guess
it's interpiting the 01 as a string.  Know a way to clean this up?  Using
it as a numeric works fine.


Robert



Thus spake Mike Fletcher (fletch at phydeaux.org):

> 
> 	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
> 

---------------------------------------------------------------------------
Robert L. Harris                |    Windows is to Unix 
Senior System Administrator II  |      what 'hooked on phonics'
  at Great West Life.           \_       is to Shakespeare


http://www.orci.com/~nomad

DISCLAIMER:
      These are MY OPINIONS ALONE.  I speak for no-one else.

FYI:
 perl -e 'print $i=pack(c5,(41*2),sqrt(7056),(unpack(c,H)-2),oct(115),10);'






More information about the Ale mailing list