something like this ....

# 
# Nothing special .. just opening the file handles
# 
        open(ONE,"one.dat") or die $!,"\n";
        open(TWO,"two.dat") or die $!,"\n";
        open(THREE,"three.dat") or die $!,"\n";

#
# sending the file handle into a reference as a glob
# you could also do this $fh = *ONE .. etc
#
        my @one = read_file(*ONE);
        my @two = read_file(*TWO);
        my @three = read_file(*THREE);

        sub read_file {
                my ($fh) = @_;
                my @lines = <$fh>;
                return @lines;
        }

Alternatively u could use the FileHandle CPAN module ..
On Fri, Nov 02, 2001 at 11:54:21AM -0500, Mike Gargiullo shaped the electrons to read:
> OK I know Perl is the language that lets you do things several different
> ways. So with that having been said, how can I convert the while
> statement into a subroutine and pas the filehandles to it ?
> 
> #!/usr/bin/perl -w
> $tiernum = shift or die "usage: tier2 [3,6,8] [1,2] directory-name id
> $!\n";
> $stylenum = shift or die "usage: tier2 [3,6,8] [1,2] directory-name id
> $!\n";
> $outdir = shift or die "usage: tier2 [3,6,8] [1,2] directory-name id
> $!\n";
> $outid = shift or die "usage: tier2 [3,6,8] [1,2] directory-name id
> $!\n";
> if ($tiernum == 3){
>       if($stylenum == 1){
>               open(OUT1, "/templates/tier2/3/11.cfm") or die "Can't
> open 11.cfm for $outdir: $!\n";
>               open(OUTINDEX, ">/outsites/$outdir/index.cfm") or die
> "Can't create index:$!\n";
>               open(OUT2, "/templates/tier2/3/12.cfm") or die "Can't
> open 12.cfm for $outdir: $!\n";
>               open(OUTINFO, ">/outsites/$outdir/info.cfm") or die
> "Can't create index:$!\n";
>               open(OUT3, "/templates/tier2/3/13.cfm") or die "Can't
> open 13.cfm for $outdir: $!\n";
>               open(OUTCONTACT, ">/outsites/$outdir/contact.cfm") or
> die "Can't create index:$!\n";
>       }else{
>               open(OUT1, "/templates/tier2/3/21.cfm") or die "Can't
> open 21.cfm for $outdir: $!\n";
>               open(OUTINDEX, ">/outsites/$outdir/index.cfm") or die
> "Can't create index:$!\n";
>               open(OUT2, "/templates/tier2/3/22.cfm") or die "Can't
> open 22.cfm for $outdir: $!\n";
>               open(OUTINFO, ">/outsites/$outdir/info.cfm") or die
> "Can't create index:$!\n";
>               open(OUT3, "/templates/tier2/3/23.cfm") or die "Can't
> open 23.cfm for $outdir: $!\n";
>               open(OUTCONTACT, ">/outsites/$outdir/contact.cfm") or
> die "Can't create index:$!\n";
>       }
>       while (<OUT1>){
>               s/abcdefghijklm/$outid/;
>               print OUTINDEX $_;
>       }
>       close(OUT1) or die "Couldn't close file: $1";
>       close(OUTINDEX) or die "Couldn't close file: $1";
>       while (<OUT2>){
>               s/abcdefghijklm/$outid/;
>               print OUTINFO $_;
>       }
>       close(OUT2) or die "Couldn't close file: $1";
>       close(OUTINFO) or die "Couldn't close file: $1";
>       while (<OUT3>){
>               s/abcdefghijklm/$outid/;
>               print OUTCONTACT $_;
>       }
>       close(OUT3) or die "Couldn't close file: $1";
>       close(OUTCONTACT) or die "Couldn't close file: $1";
> }
>       
> 
> -- 
> 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]

Reply via email to