develooper Front page | perl.beginners | Postings from March 2011

RE: sub routine

Thread Previous | Thread Next
From:
Chris Stinemetz
Date:
March 18, 2011 08:48
Subject:
RE: sub routine
Message ID:
D225040F2D0F75448937B83D9527991A0154883132@denex1.cricketcommunications.com
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) ;

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About