in reply to Re^2: Splitting multiple patterns
in thread Splitting multiple patterns
It's really not much different. However, slurping in the whole file can run you out of memory if your file is very large.
#!/usr/bin/perl use warnings; use strict; open my $fh, "<", "infos.txt" or die "cannot open infos.txt: $!"; my @array = <$fh>; close $fh; for my $line ( @array ){ chomp $line; my ( $name, $rest ) = split /\s+/, $line; my ( $age, $gender, $address ) = split /,/, $rest; print "Name: $name\n"; print "Age: $age\n"; print "Gender: $gender\n"; print "Address: $address\n"; print "\n"; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: Splitting multiple patterns
by astronogun (Sexton) on Apr 09, 2012 at 10:30 UTC | |
by Marshall (Canon) on Apr 09, 2012 at 19:07 UTC | |
by astronogun (Sexton) on Apr 10, 2012 at 09:35 UTC |