Hi Rob, Many thanks. That does what I want :) Now I need to study your code to learn why.
Bob Rob Dixon wrote: > Hi Bob > > I suggest you forget about regular expressions and use the library > function split() instead. Take a look at the code below. > > HTH, > > Rob > > > > use warnings; > use strict; > > my (@ukchecksum, @uktrackname); > > open my $bhf_file, '<', '/home/bob/tmp/md5music' > or die "Could not open md5music: $!"; > > while (<$bhf_file>) { > > my @fields = split ' ', $_, 2; > > if (@fields < 2) { > print "Invalid data format at line $.\n"; > next; > } > > push @ukchecksum, $fields[0]; > push @uktrackname, $fields[1]; > } > > print $ukchecksum[0]; > print $uktrackname[0]; > > > > Bob Williams wrote: >> Hi, >> >> 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; >> #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>; >> close (BHF_FILE); >> >> for (my $i = 0; $i <= $#bhffile; $i++){ >> $bhffile[$i] =~ m/(\s.+) ( .+)/; >> push @ukchecksum, $1[$i]; >> push @uktrackname, $2[$i]; >> } >> >> >> print @ukchecksum[0]; # Won't print - uninitialized value ??? >> print @uktrackname[0]; # Won't print - uninitialized value !!! >> ---Code--- >> >> What am I doing wrong? >> >> Many thanks, >> >> 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: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/