[Bio] / FigKernelPackages / SeedUtils.pm Repository:
ViewVC logotype

Diff of /FigKernelPackages/SeedUtils.pm

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.45, Sat Aug 21 15:43:06 2010 UTC revision 1.46, Sun Aug 22 22:37:27 2010 UTC
# Line 718  Line 718 
718  }  }
719    
720    
721    
722    =head3 file_read
723    
724        my $text = $fig->file_read($fileName);
725    
726    or
727    
728        my @lines = $fig->file_read($fileName);
729    
730    or
731    
732        my $text = FIG::file_read($fileName);
733    
734    or
735    
736        my @lines = FIG::file_read($fileName);
737    
738    Read an entire file into memory. In a scalar context, the file is returned
739    as a single text string with line delimiters included. In a list context, the
740    file is returned as a list of lines, each line terminated by a line
741    delimiter. (For a method that automatically strips the line delimiters,
742    use C<Tracer::GetFile>.)
743    
744    =over 4
745    
746    =item fileName
747    
748    Fully-qualified name of the file to read.
749    
750    =item RETURN
751    
752    In a list context, returns a list of the file lines. In a scalar context, returns
753    a string containing all the lines of the file with delimiters included.
754    
755    =back
756    
757    =cut
758    
759    #: Return Type $;
760    #: Return Type @;
761    sub file_read {
762    
763        shift if UNIVERSAL::isa($_[0],__PACKAGE__);
764        my($fileName) = @_;
765        return file_head($fileName, '*');
766    
767    }
768    
769    
770    =head3 file_head
771    
772        my $text = $fig->file_head($fileName, $count);
773    
774    or
775    
776        my @lines = $fig->file_head($fileName, $count);
777    
778    or
779    
780        my $text = FIG::file_head($fileName, $count);
781    
782    or
783    
784        my @lines = FIG::file_head($fileName, $count);
785    
786    Read a portion of a file into memory. In a scalar context, the file portion is
787    returned as a single text string with line delimiters included. In a list
788    context, the file portion is returned as a list of lines, each line terminated
789    by a line delimiter.
790    
791    =over 4
792    
793    =item fileName
794    
795    Fully-qualified name of the file to read.
796    
797    =item count (optional)
798    
799    Number of lines to read from the file. If omitted, C<1> is assumed. If the
800    non-numeric string C<*> is specified, the entire file will be read.
801    
802    =item RETURN
803    
804    In a list context, returns a list of the desired file lines. In a scalar context, returns
805    a string containing the desired lines of the file with delimiters included.
806    
807    =back
808    
809    =cut
810    
811    #: Return Type $;
812    #: Return Type @;
813    sub file_head {
814    
815        shift if UNIVERSAL::isa($_[0],__PACKAGE__);
816        my($file, $count) = @_;
817    
818        my ($n, $allFlag);
819        if ($count eq '*') {
820            Trace("Full file read for \"$file\".") if T(3);
821            $allFlag = 1;
822            $n = 0;
823        } else {
824            $allFlag = 0;
825            $n = (!$count ? 1 : $count);
826            Trace("Reading $n record(s) from \"$file\".") if T(3);
827        }
828    
829        if (open(my $fh, "<$file")) {
830            my(@ret, $i);
831            $i = 0;
832            while (<$fh>) {
833                push(@ret, $_);
834                $i++;
835                last if !$allFlag && $i >= $n;
836            }
837            close($fh);
838            if (wantarray) {
839                return @ret;
840            } else {
841                return join("", @ret);
842            }
843        }
844    }
845    
846    
847    
848  =head3 genome_of  =head3 genome_of
849    
850      my $genomeID = genome_of($fid);      my $genomeID = genome_of($fid);

Legend:
Removed from v.1.45  
changed lines
  Added in v.1.46

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3