file content in an array PERL

Hello everybody, I'm new in this forum.

I searched a long time for a solution for my problem but I didn't find the right thing.

I have to read from a file (content is "abngjm" without any other signs) and have to write this content in an array. But every sign has to be called by its own index. If I use "open file" and "print @array = FILE" I can write the signs only in correlation to one index ("$array[0]").

Has anyone an idea?

greetings

You should really do your own school work, but since you seem to have tried something I'll help you.

open(FILE,'path/to/your/file') or die "$!";
my $line = <FILE>;#because it is one line you read it into a scalar
close FILE;
my @array = split(//, $line);
foreach my $i (0..$#array) {
   print "$array[$i]\n";
}

Hi,

One more way to do this is to set the input record separator $/ to "";

$/ = "";
@array = <FILE>;

The variable "array" would contain your file characters.

~thanks
Sudhir

No it won't. It will do the same thing that his script already does, read in the one line of data into the array and store it in $array[0].

I have to say thank you for the answers!

KevinADC I think it works. I'll try it later because there is not enough time at the moment.

The solution mentioned by sudhir_onweb I tried for myself and the effect was the same I said before.

thanks

I know my solution works. I read your question, I understood your question, I tested my code, then I posted a reply. The other guy simply did not understand the question, we are all guilty of that at times.