>-----Original Message----- >From: Chris Stinemetz [mailto:cstinem...@cricketcommunications.com] >Sent: Thursday, March 17, 2011 14:16 >To: beginners >Subject: if else elsif > >I am trying to return new values based on if else. I understand the idea of >using if else, but I am not sure I have placed in the right place. >I was assuming I would want to insert it before the array is sorted. >Thank you in advance. This mailing list is helping me understand perl >greatly! > >I am getting the following error: >Use of uninitialized value within @data in pattern match (m//) at >./DOband.pl line 19, <$fh> line 485. > > >#!/usr/bin/perl > >use warnings; >use strict; > >my $filepath = 'C:/temp/PCMD'; >my $outfile = 'output.txt'; > >open my $fh, '<', $filepath or die "ERROR opening $filepath: $!"; >open my $out, '>', $outfile or die "ERROR opening $outfile: $!"; > >my @array; > >while (<$fh>) { > next unless /;/; > chomp; > my @data = ( split /;/ )[31,32,38,39,261]; > > if (@data[39] =~ /15/) > { > 2 > } > else > { > 1 > } You are only pulling 5 elements into @data, yet as part of your test, you are looking at the 39th element, but you really element 3.
If you have any questions and/or problems, please let me know. Thanks. Wags ;) David R. Wagner Senior Programmer Analyst FedEx Services 1.719.484.2097 Tel 1.719.484.2419 Fax 1.408.623.5963 Cell http://Fedex.com/us > > push @array, join "\t", @data; >} > >@array = sort { > my @aa = split /\t/, $a; > my @bb = split /\t/, $b; > $aa[0] <=> $bb[0] or > $aa[1] <=> $bb[1] or > $aa[2] <=> $bb[2]; >} @array; > >print $out "$_\n" foreach @array; >close $out; > > > > >#RTD 1 unit = 4 chips RUM Field 16 0 - 2^16 - 1 milliseconds > > > > > > > > >Chris Stinemetz -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/