Pacific-Design.com

    
Home Index

1. Perl5

2. FILE

+ File Mapper

+ Glob

+ Handlers

+ Multiple Files

+ Position

Perl5 / FILE /

Read File into array several ways.

use IO::All; my @array = io($filename)->slurp;

use File::Slurp; my @array = read_file($filename);

my @array = do { open my $fh, "<", $filename or die "could not open $filename: $!"; <$fh>; };

sub read_file { my $file = shift; open(FILE, $file) or die $!; my @array = <FILE>; return @array; }

sub read_file_content { my $file = shift; open( FILE, $file ) or die $!; my @array = <FILE>; my $content = join(' ', @array); return $content; }