in reply to advice for reading data from a file
I left most of your code intact as you probably have it that way for a reason.#!/usr/bin/perl -w use strict; use Text::CSV_XS; my @files = qw(foo bar blah asdf); for my $file ( @files ) { if ( File_Type( $file ) ) { print "Do something with $file\n"; } } sub File_Type { my $file = shift; open (INPUT , '<' , $file) or die "Unable to open $file for readin +g : $!"; my $csv = Text::CSV_XS->new( {'sep_char' => ';'} ); while ( <INPUT> ) { next if $. != 2; chomp; if ( $csv->parse($_) ) { my @field = $csv->fields; die 'Incorrect number of fields' if @field != 4; return $field[2] =~ /^\d+$/ ? 1 : 0; } else { print "Unable to parse: ", $csv->error_input, "\n"; return 0; } } }
Cheers - L~R
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: advice for reading data from a file
by Anonymous Monk on Jan 18, 2004 at 19:05 UTC |