open three files for output, loop through your input file, then
print to your output files:
use strict;
use warnings;
open my $fh1, '>', 'item1.dat' or die "can not open file item1.dat: $!
+";
open my $fh2, '>', 'item2.dat' or die "can not open file item2.dat: $!
+";
open my $fh3, '>', 'item3.dat' or die "can not open file item3.dat: $!
+";
while (<DATA>) {
next if (/^item/); # ignore header
my @items = split;
print $fh1 "@items[0..1]\n";
print $fh2 "@items[2..3]\n";
print $fh3 "@items[4..5]\n";
}
__DATA__
item1 item2 item3
0 0 1 S 0 0
0 0 2 K 0 0
0 0 23 T 1 M
12 T 24 N 2 L
45 0 36 V 14 I
46 0 38 W 16 R
51 S 39 A 17 L
52 A 42 N 20 E
53 0 43 L 21 G
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.