"John W. Krahn" wrote:
> Bob Williams wrote:
>> Hi,
>
> Hello,
>
>> I am trying to split the lines in a file into two halves (at the first
>> space) each half going into an array. The code I have written is below.
>> The print command is there to test that things worked correctly, but it
>> only gives an error for each instance of the print command...
>>
>> Use of uninitialized value within @uktrackname in print at
>> /home/bob/Documents/scripts/perl/music_md5_compare.pl line 22
>> (#1)
>>
>> ---Code---
>> #!/usr/bin/perl
>> use warnings;
>> #use strict;
>
> You shouldn't comment out that line. Strictures can help you find
> mistakes in your code.
>
OK. I'll remove the #
>> #use diagnostics;
>>
>> # perl script to compare two files of md5 checksums
>> #+and extract the lines which differ
>>
>> open (BHF_FILE, "</home/bob/tmp/md5music")
>> or die "Could not open md5music: $!";
>> @bhffile = <BHF_FILE>;
>
> Why are you reading the entire file into memory? You only need to
> process one line at a time.
>
Because I'm a beginner ;) ...
>> close (BHF_FILE);
>>
>> for (my $i = 0; $i <= $#bhffile; $i++){
>
> That is usually written as:
>
> for my $i ( 0 .. $#bhffile ) {
>
... who is learning all the time.
>> $bhffile[$i] =~ m/(\s.+) ( .+)/;
>
> What exactly does your data look like? Your regular expression says:
> match a single WHITESPACE character followed by one or more of ANY
> character followed by a single SPACE character followed by another
> single SPACE character followed by one or more of ANY character.
>
This is one line from the file, the rest are similar:
60196093f7a180d1f2d5fb47ded646be artists/Abdullah Ibrahim/Various/abdullah
ibrahim - Black Lightning.mp3
I have two copies of my music collection, one of which is corrupted. I have
created two files containing the md5 checksum followed by the filename, and
I want to extract a list of files whose checksum differs between the two
colections.
>> push @ukchecksum, $1[$i];
>> push @uktrackname, $2[$i];
>
> You do not define the arrays @1 or @2 anywhere so why are you trying to
> use them here? If you want the contents of the capturing parentheses
> from the regular expression then they are in the variables $1 and $2 but
> you should only use them if you verify that the regular expression
> matched successfully. You would probably be better off using an array
> of arrays or a hash instead of two separate arrays.
>
By now, I realise I'm getting out of my depth
>> }
>>
>>
>> print @ukchecksum[0]; # Won't print - uninitialized value ???
>> print @uktrackname[0]; # Won't print - uninitialized value !!!
>
> Why are you using an array slice to access a scalar value? Perl should
> have warned you about that.
>
No idea! See above.
Many thanks for help :)
Bob
--
openSUSE 11.2, Kernel 2.6.31.5-0.1-desktop, KDE 4.3.3
Intel Core2 Quad Q9400 2.66GHz, 4GB DDR RAM, nVidia GeForce 9200GS
--
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
http://learn.perl.org/