in reply to Hashes and Associative Arrays

It would help us if you show us what the content of the file looks like. For test purposes it's really handy to have the test data "built in" (see I know what I mean. Why don't you? for hints on doing that).

A couple of, not quite related, tips will help with finding and fixing problems generally:

It helps a lot while developing code to ignore unimportant stuff like managing input and output files. The "built in data" trick isn't just for us, it helps you too. Perl helps by letting you tack an input file to the end of the script with __DATA__ and you can use print without a file handle to see the output immediately in the console without having to dig into an output file.

Without worrying about how to write the code, how did you imagine a user of the script would give the edit information? From the user's perspective what do you imagine the sequence of events to be?

Premature optimization is the root of all job security

Replies are listed 'Best First'.
Re^2: Hashes and Associative Arrays
by phizymonk (Novice) on Jan 27, 2016 at 03:12 UTC

    I am updating it now and I will post here aswell with the new code. The text file says this exactly Hamburger - 1.79 Cheeseburger - 2.00 Fries - 1.50

    I took a different approach and had perl read the file print what it said then take that and put it into a hash now I need to take user input and change the hash. My guess would be to use a foreach loop to run through each line of the uploaded hash and change it.

    use strict; use warnings; my $file = 'gp1data.txt'; open my $info, $file || die "Could not open $file: $!"; while( my $line = <$info>) { chomp($line); print $line; (my $word1, my $word2) = split /-/, $line; $hash{word1} = $word2; } while ( my ($k, $v) = each $hash){ print "key $k => $v\n"; } <>;

      You haven't yet taken your programmer hat off and put a user hat on. Until you do that and specify how the user will interact with your script, you can't write the script!

      Is your input really all on one line? Maybe you need to put your sample data in code tags (you can edit your node to do that).

      Premature optimization is the root of all job security

        I am sort of confused, the user will open the program and items and their prices will be printed then the user will be asked to change the prices of the items that were printed. These items should come from a text file.