RuZombieSlayer has asked for the wisdom of the Perl Monks concerning the following question:
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;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Seperating values with spaces in array
by Corion (Patriarch) on Jan 17, 2016 at 11:56 UTC | |
by RuZombieSlayer (Novice) on Jan 17, 2016 at 12:01 UTC | |
by AnomalousMonk (Archbishop) on Jan 17, 2016 at 16:09 UTC | |
|
Re: Seperating values with spaces in array
by Corion (Patriarch) on Jan 17, 2016 at 11:46 UTC | |
by RuZombieSlayer (Novice) on Jan 17, 2016 at 11:50 UTC | |
by Corion (Patriarch) on Jan 17, 2016 at 11:53 UTC |