in reply to arrays of arrays
The input file has a couple of lines, each with a few word-number pairs. The output was formatted with all numbers on one line and all words on the next line.> cat input.txt book 1 pencil 2 desk 3 foo 5 bar 6 baz 7 > > cat 637646.pl #!/usr/bin/env perl use warnings; use strict; my (@n, @w); open INFILE, '<', 'input.txt' or die "can not open file $!\n"; while (<INFILE>) { my (@numbers) = /(\d+)/g; my (@words) = /([a-z]+)/g; push @n, @numbers; push @w, @words; } close INFILE; open MYFILE, '>', 'output.txt' or die "can not write to file $!\n"; print MYFILE "$_ " for @n; print MYFILE "\n"; print MYFILE "$_ " for @w; print MYFILE "\n"; close MYFILE; > > 637646.pl > > cat output.txt 1 2 3 5 6 7 book pencil desk foo bar baz >
The does not employ arrays of arrays because I do not think that is necessary. Hope this helps.
|
|---|