Thread: need perl help
View Single Post
Old March 4th, 2003, 05:58 PM     #3 (permalink)
SpookyEddy
may contain mild peril
 
SpookyEddy's Avatar
 
Join Date: Oct 2001
Location: UK
Posts: 3,329
Ok first quick attempt that seems to basically work, but I could be horribly wrong (so please test on a non important file).
Code:
#!/usr/bin/perl -w
 
#### DISCLAIMER ###############
#
# Standard warnings, blah blah
# This code was written by a man with the IQ of a punch drunk monkey.
# I accept no responsibility for loss of data, life or sanity.
# 
###############################

use strict;

my $usage = <<EOT;
Usage: $0 [filename]
EOT

#do some rather shody checking on no. of args
if (@ARGV != 1) { die $usage }
my $file = shift;

#open an input file
open(FILE, $file) or die "Can't open input: $!";

#step over each line in the file
while(<FILE>){ 
        #split line up into an array
	my @line= split(/:/, $_);
        #print first element of array if it matches regexp
	if($line[0] =~ /^c(.*)1$/){ print "$line[0]\n" }
}

#Tidy up after reading
close(FILE);

#### The madness ends here ####
I will spend a few minutes later cleaning it up a bit and hunting down any major bugs, but you get the general idea.

Regards

eddy

Last edited by SpookyEddy : March 4th, 2003 at 06:03 PM.
SpookyEddy is offline   Reply With Quote