So the problem is that i need to add leading zeros back to the numbers after i put them into an array. But the split function joins all the data into 1 long stream so i cant do that. It also means that typing more than 1 word can break the code. Sorry if the answer is simple i am self learning. For the file, you can make an array of 10 fruits, then for numbers an array using 1..10
use strict; use warnings; use JSON qw( decode_json); use File::Find; #Change This Root Depending On File Location open (MYFILE, "F:/Program Files (x86)/Spreadsheets/Words.txt") or die "Could not open required file $!"; my $firstText = do { local $/; <MYFILE> }; my @firstText = split(' ', $firstText); open (FILE, "F:/Program Files (x86)/Spreadsheets/Numbers.txt") or die "Could not open required file $!"; my $firstNumbers = do { local $/; <FILE> }; my @firstNumbers = split(' ', $firstNumbers); print "Text Enter\n"; my $sentance = <>; my @sentance = split(' ', $sentance); print @sentance; print $sentance; use List::MoreUtils qw(first_index); my @indexes; foreach my $place (sentance) { push (@indexes, first_index { $_ eq $place } @firstText); }; print @indexes;
In reply to Seperating values with spaces in array by RuZombieSlayer
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |