tommyboy has asked for the wisdom of the Perl Monks concerning the following question:
I am trying to parse a single file in a series of directories that is frequently updated and and renamed
with a postfix according to the date.
I do this by iterating through the directories and matching the files I want to parse with forced shell expansion inside calls to open open(FH,<*fpc>).
It works the first time through and then fails.
The <> returns undef but the files I am trying to parse do in fact exist.
Does <> shell expansion only get compiled once -- is there a way to force it to evaluate every time.
There are other ways to solve this problem but <> is the simplest/most elegant, if it only worked.
below is one of an excerpt of one of the fpc files that needs parsing.#!/usr/bin/perl -w use strict; #directory containing fpc map dirs my $fpcdir = '/home3/ftp/pub/gsc1/fpc_files'; #organism/fpc map dir names my @projects = ("mouse","human","cb","arab"); my %stats; #foreach of the fpc maps get total clones and contigs foreach(@projects) { &get_clones_and_contigs($fpcdir,$_); } sub get_clones_and_contigs($$) { my ($fpcdir,$project) = @_; # this is what I can not figure out - #this works on the first iteration # but fails to expand correctly the second time #&get_lones_and_contigs is called. open(FH,<$fpcdir/$project/*fpc>) || die "$! \n"; while(<FH>) { if ($_ =~ /\sContigs\s.(\d+)\s.Clones\s.(\d+)\s/) { print "$project: contigs[$1] clones[$2] \n"; my @stats = ($1,$2); $stats{'project'} = \@stats; return; } } close FH; }
// fpc project master_Humanmap // 4.6.9 Date: 14:04 Wed 05 Dec 2001 User: scanner // Contigs 726 Clones 407155 Markers 69507 Bands 12849811 // Framework Chr_Z Genome 0 AvgBand 4000 AvgInsert 174000 // Configure 173 Tol 7 Cut 3e-09 Apx 0.100 Min 3 End 15 Kill -1 Bad 15 + Best 10 Log 0 Std 1 // CpM Off 50 1 0 TBL 1 1e-05 2 1e-04 3 1e-03 // Build 1/1/70 0:0 Cut 3e-12 Off 50 1 0 TBL 1 1e-08 21e-07 3 1e-06 // Clip(0 4600) MinMax(0 32767) AutoRemark
Edit Masem 2002-01-24 - Fixed title, code tage on file format
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Shell expansion with is funky
by Masem (Monsignor) on Jan 25, 2002 at 01:10 UTC | |
Re: Shell expansion with is funky
by japhy (Canon) on Jan 25, 2002 at 02:39 UTC | |
by tommyboy (Initiate) on Jan 25, 2002 at 03:42 UTC | |
by japhy (Canon) on Jan 25, 2002 at 04:27 UTC | |
Re: Shell expansion with is funky
by chipmunk (Parson) on Jan 25, 2002 at 07:44 UTC |
Back to
Seekers of Perl Wisdom