in reply to Splitting each line into an array from file
#!/usr/bin/perl -w use strict; print "Program Running\n"; # Below, I use the standard already opened DATA handle # instead of your open() # open FILE, "<", "Readme.txt" or die $! ; # the "=" stuff is a trick using a markup language # called perldoc to add text within the code so here # that the comment text doesn't get confused with the DATA. use constant CHOMP => 0; #change to 1 to see what happens while (<DATA>) { chomp if CHOMP; #deletes "new line" if enabled my @characters = split(//,$_); my $i=0; foreach my $char (@characters) { print $i++, " $char\n"; } } =Program Outputs the following: Program Running 0 S 1 o 2 m 3 e 4 5 S 6 t 7 u 8 f 9 f 10 Note: this is the \n in the input string followed by the \n in the print 0 a 1 s 2 d 3 f 4 =cut __DATA__ Some Stuff asdf
|
|---|