Hi Christ In sub Dist() , you need define scope of each variable as my or our or local , which is line no.20 .
Regards Sunita -----Original Message----- From: Chris Stinemetz [mailto:cstinem...@cricketcommunications.com] Sent: Friday, March 18, 2011 9:18 PM To: Uri Guttman Cc: beginners Subject: RE: sub routine Thanks Uri. I've been reading perldoc perlsub and have a better understanding about subroutines, but I am still stuck. Any help is greatly appreciated. The error I am getting is: Global symbol "%record" requires explicit package name at ./DOband1.pl line 20. Global symbol "$line" requires explicit package name at ./DOband1.pl line 20. Global symbol "%record" requires explicit package name at ./DOband1.pl line 21. syntax error at ./DOband1.pl line 21, near "$record{dist" Global symbol "%record" requires explicit package name at ./DOband1.pl line 22. syntax error at ./DOband1.pl line 22, near "data[" Global symbol "%record" requires explicit package name at ./DOband1.pl line 24. syntax error at ./DOband1.pl line 25, near "}" Execution of ./DOband1.pl aborted due to compilation errors. #!/usr/bin/perl use warnings; use strict; use File::Slurp; my $filepath = 'C:/temp/PCMD'; my $output = 'output.txt'; my %cols = ( cell => 31, sect => 32, chan => 38, dist => 261, précis => 262, ); sub Dist{ @record{ keys %cols } = (split /;/, $line)[ values %cols ] ; foreach $record{dist} { $record{dist} = ((data[261]+13)/6.6/8/2*10)/10 ; } return $record{dist}; } my @records; my @lines = read_file( $filepath ); chomp @lines; foreach my $line ( @lines ) { next unless $line =~ /;/; my %record; # this gets just what you want into a hash using a hash slice and an # array slice. # the order of keys and values will be the same for any # given hash @record{ keys %cols } = (split /;/, $line)[ values %cols ] ; $record{carr} = ( $record{chan} == 15 ) ? 2 : 1 ; $record{dist} = ( length( $record{dist}) > 1 ) ? getDist() : '' ; push( @records, my $record ) ; } my @sorted = sort { $a->{cell} <=> $b->{cell} || $a->{sect} <=> $b->{sect} || $a->{carr} <=> $b->{carr} } @records ; my @report = map "@{$_{ keys %cols }}\n", @records ; print @report ; write_file($output, @report) ; -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/