I think that what you're trying to do is to read a file line by line, split each line on spaces, and then do something with each resulting array.
I'll assume that you have a smallish file, and want to slurp the entire file...
#!/perl/bin/perl use strict; use warnings; use Data::Dumper; my($ifh, @all_lines); open($ifh, "text.txt") or die "Could not read file.\n"; while (<$ifh>) { # split's default delimiter is whitespace, and if # no expression is supplied, it splits $_ my @lineinfo = split; for (@lineinfo) { # print each element on it's own line print $_, "\n"; } print "\n"; print sprintf qq(Line %d has %d elements.\n\n), $., $#lineinfo + 1; # push a reference to each array into an array push (@all_lines, \@lineinfo); } close $ifh; # Dump it all out... print Dumper(\@all_lines); __DATA__ one two three four five six seven eight nine ten eleven twelve
In reply to Re: String parse
by thezip
in thread String parse
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |