>opendir(DIR, 'data') ... This allows me to grab the correct file names from within the 'data' directory, but I guess that my problem happens when the script actually goes to parse those files that it only looks for the filenames locally, rather than in the actual 'data' directory.
>while (<INFILE>)... This give me the correct file called 'logfile1', but I need my INFILE to actually be pointing to 'data/logfile1' Hope that's not too confusing. Here is the original script if it is. ================================== #!/usr/bin/perl -w use strict; use Text::CSV; my $ip=$ARGV[0]; my $csv=Text::CSV->new(); opendir(DIR, "data"); #<=== 'data' directory contains several log files to be parsed. my @files = readdir(DIR); foreach my $file (@files) { my $input="$file"; open(INFILE,"$input") || die "Can't open file $input"; #<=== is opening correct file name, but not 'data/logfile1. while (<INFILE>) { chomp; if($csv->parse($_)) { if (m|$ip|) { my @fields=$csv->fields; print "$fields[0],$fields[4],$fields[5],$fields[6]\n"; } } } } closedir(DIR); close INFILE; ================================== ----- Original Message ----- From: "Wiggins d'Anconia" <[EMAIL PROTECTED]> To: "Jose Malacara" <[EMAIL PROTECTED]> Cc: <[EMAIL PROTECTED]> Sent: Tuesday, February 04, 2003 8:11 PM Subject: Re: move data into separate directory > Sure lots of ways, this is Perl ;-)... > > Jose Malacara wrote: > > Hello. > > > > I have a script that parses csv files for the occurence of an IP address that is passed to the script as an argument when it runs. Currently, I can only run the script from within the same directory as my data files. I would like to be able to move my csv files into a separate data directory, but I seem to be having problems mapping the rest of the script to the new directory. Is there any way to make my input look something like this: > > > > my $input="data/$file" or is there a better way to handle this? > > > > Thanks, > > Jose > > > > > > Any help would be appreciated. Here's what' I've got so far: > > > > > > #!/usr/bin/perl -w > > use strict; > > use Text::CSV; > > > > my $ip=$ARGV[0]; > > my $csv=Text::CSV->new(); > > > > opendir(DIR, "."); > > opendir(DIR, 'data') or die "Can't open directory for reading: $!"; > > Is probably the easiest, cheapest, and ugliest, but thats better than > leaving alone isn't it ;-) ?? > > You could consider passing in the directory that contains your files to > be parsed, so that your opendir is not hardcoded: > > my $dir = $ARGV[1]; > opendir(DIR,$dir) or die "Can't open directory for reading: $!"; > > > command.pl 127.0.0.1 /tmp/data > > You could also consider passing in the files you want to parse, then > doing something like, > > my $ip = shift @ARGV; > foreach my $file (@ARGV) { > # parse your file > } > > > command.pl 127.0.0.1 /tmp/data/*.csv > > You could go down the path of File::Find, or you could use Getopt::Long > or Getopt::Std and have the user specify whether they are passing in a > directory, a list of files, or nothing (in which case you just mangle > the current directory)..... > > http://danconia.org > > > > -- > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > > -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]