A
aleatory
Hi perl gurus,
I've been struggling for maniplating a line of
numbers. I'd greatly appreciate if you could
offer me some help.
A file, for instance, contains a bunch of numbers:
| 1218, 8, 29
| 3211, 9, 15
I would like to first read in a line of numbers
and then would like to uniquely store each number
in an array as:
For 1st loop
| print "$my_array[0]"; <--displays 1218
| print "$my_array[1]"; <--displays 8
| print "$my_array[2]"; <--displays 29
For 2nd loop
| print "$my_array[0]"; <--displays 3211
| print "$my_array[1]"; <--displays 9
| print "$my_array[2]"; <--displays 15
However, I've been having difficulty uniquely
storing each number in an array. The following
is my code:
| #!/usr/bin/perl
| use strict;
| use warnings;
|
| open IN, 'infile' || die$!;
|
| my @line;
| my @my_array;
|
| while ( <IN> )
| {
| @line = $_; <--@line contains 1218, 8, 29
| @my_array = @line How could I store each as:
| } $my_array[0] = 1218
| $my_array[1] = 8
| $my_array[2] = 29
Then after separating each, how could I put
them together as a line of numbers separated
by a comma?
I'm quite desperate and any information is
highly appreciated.
Many thanks in advance,
alea
I've been struggling for maniplating a line of
numbers. I'd greatly appreciate if you could
offer me some help.
A file, for instance, contains a bunch of numbers:
| 1218, 8, 29
| 3211, 9, 15
I would like to first read in a line of numbers
and then would like to uniquely store each number
in an array as:
For 1st loop
| print "$my_array[0]"; <--displays 1218
| print "$my_array[1]"; <--displays 8
| print "$my_array[2]"; <--displays 29
For 2nd loop
| print "$my_array[0]"; <--displays 3211
| print "$my_array[1]"; <--displays 9
| print "$my_array[2]"; <--displays 15
However, I've been having difficulty uniquely
storing each number in an array. The following
is my code:
| #!/usr/bin/perl
| use strict;
| use warnings;
|
| open IN, 'infile' || die$!;
|
| my @line;
| my @my_array;
|
| while ( <IN> )
| {
| @line = $_; <--@line contains 1218, 8, 29
| @my_array = @line How could I store each as:
| } $my_array[0] = 1218
| $my_array[1] = 8
| $my_array[2] = 29
Then after separating each, how could I put
them together as a line of numbers separated
by a comma?
I'm quite desperate and any information is
highly appreciated.
Many thanks in advance,
alea