Ok, ive rewritten the code to do what I wanted it to do but....
It doesn't work. It prints out the starting text and then stops. Help please. strict says
"my" variable %action masks earlier declaration in same scope at test. +pl line 47 . Useless use of private variable in void context at test.pl line 40. Bareword "LOC" not allowed while "strict subs" in use at test.pl line +95. Bareword "LOC" not allowed while "strict subs" in use at test.pl line +97. Bareword "LOC" not allowed while "strict subs" in use at test.pl line +99.
None of which should stop the program with strict off.
I just dunno. Heres the rewriten code.
use strict; use warnings; print "Welcome.\n"; print "This game will lead you through many perils \n" . "and dangers +that could lead to your death.\n"; print "ONLY THE STRONG WILL SURVIVE\n\n"; my $data; my $action; my @items= (); my $location = "hall"; my $health; my @acdata; my %action; while(<1>){ $data = &data($location); print $data; print "\n\n"; print "What do you want to do?? \n"; print "(type h for help.)\n"; print "Do what??\\: "; my $action = <>; my $noun = &action($action, $location); print $noun; } sub actions{ my $data; my @actdata; my $location; my $action; $data, $location = @_; chomp($data); $data =~ tr/A-Z/a-z/; @acdata = split(/ /, $data); exists $action{$acdata[0]} and $action{$acdata[0]}->(); my %action = ( go => \&go($location, $data) , use => \&use($location, $data) , pickup => \&pickup($location, $data) , drop => \&drop($location, $data) , throw => \&throw($location, $data) , push => \&push($location, $data) , pull => \&pull($location, $data) , search => \&search($location, $data) , check => \&check($location, $data) ); return %action; } sub go{ my ($location, $data) = @_; $data = &chomp_data($data); my $locationdata = &locationdata("go", $location, $data); print $locationdata; return "ok"; } sub chomp_data{ my $data = @_; chomp($data); $data =~ tr/A-Z/a-z/; my @data = split(/ /, $data); shift(@data); return @data; } sub locationdata{ my ($action, $location, $data) = @_; open('LOC', $location) or die "Could not open area script $location.\n +" . "Please check if the file was deleted or +moved.\n"; while(<$location>){ my $start = index(LOC, $action); $start = $start++; my $finish = index(LOC, '>', $start); my $total = $finish - $start - 1; my $cmd = substr(LOC, $start, $total); my @cmdl = split(/:/, $cmd); my @all = split(/#/, @cmdl); my @a = ($all[0], $all[2]); my @b = ($all[0], $all[1]); my @c = ($all[2], $all[3]); if ($cmd eq " "){ my $noun = "You can't do that.($action, $data)"; return $noun; } else{ last; } } } sub data{ my $location = @_; open('LOC', $location) or die "Could not open area script $location.\n +" . "Please check if the file was deleted or +moved.\n"; while(<$location>){ my $info = $_; chomp($info); my $length = length($info); $length = $length - 2; my $data = substr $info, 1, $length; return $data; last; } }

All the Best, Eoin...

If everything seems to be going well, you obviously don't know what the hell is going on.


In reply to Re: Re: What?? delete chars. by eoin
in thread What?? delete chars. by eoin

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.