Hello Monks,
I'm trying to make a Fighting Fantasy Game (books published in '80) base system with perl. However something seems to be stuck completely on loading (Data::dumber+eval). Load it self works nicely, however when i'm trying to read info on all equipment that player has, my regex fails. But when i'm using the same sub with 'perl -e' it works (used to use it in player creating and it worked there as well).

Now i'm not going to put all code here. Reasons being that it's currently about 1000 lines long (4 modules) and texts are in finnish (i own the book in finnish...). And it's still work in progress (and i've learned nicely while doing this so far). But here is the relevant parts of it.
# in Equipment.pm ############### # Read an equipment from file to memory sub read_eq ($) { my $eq=shift @_; return if (exists($eq_list{$eq})); local $_; # use re "debug"; open (EQF,"$eq_file") or die "$!"; while (<EQF>) { (m/^#/o) && next; chomp; if (m/^$eq/) { my @array=split (/::/,$_); $eq_list{$eq}=[@array[1 .. $#array]]; $eq=0; last; } } close EQF; if ($eq) { warn "Unable to find equipment \'$eq\'\n"; } return; } # Reads all equipments from player into memory sub read_player () { local $_; foreach (Player::list_all ()) { read_eq ($_); } return; }
Now the Player::list_all () return a list of numbers which match to an eq in 'eq.list' file. Which has that number as first thing (or '#' meaning comment line). When i do this i get proper (no notifications) answer.
perl -e 'use Equipment;@a=(5,1,6,4);foreach (@a) { Equipment::read_eq( +$_); }'
But if i use the Equipment::read_player (), it prints "Unable to find equipment 'X'" for each equipment. Heres the format for 'eq.list' file. Numbers are in the first column in each row (separator is '::').
# list of equipment, that game uses
# comments can be added with '#' in the beginning
1::voimajuoma::potion::orig_const|const::0::0::0
2::taitojuoma::potion::orig_skill|skill::0::0::0
3::onnijuoma::potion::orig_luck+1|luck::0::1::0
4::ruoka::food::+4|const::0::0::0
5::miekka::weapon::::0::0::2
6::nahkahaarniska::armour::::0::0::2

I took some debug from regex (using 'use re "debug";') and this is relevant part.
Guessing start of match, REx `^#' against `# list of equipment, that game uses
# comments can be added ...'...
Guessed: match at offset 0
Matching REx `^#' against `# list of equipment, that game uses
# comments can be added ...'
  Setting an EVAL scope, savestack=85
   0 <> <# list of eq>    |  1:  BOL
   0 <> <# list of eq>    |  2:  EXACT <#>
   1 <#> < list of eq>    |  4:  END
Match successful!
Unable to find equipment '5'
Guessing start of match, REx `^#' against `# list of equipment, that game uses
# comments can be added ...'...
Guessed: match at offset 0
Matching REx `^#' against `# list of equipment, that game uses
# comments can be added ...'
  Setting an EVAL scope, savestack=85
   0 <> <# list of eq>    |  1:  BOL
   0 <> <# list of eq>    |  2:  EXACT <#>
   1 <#> < list of eq>    |  4:  END
Match successful!
Unable to find equipment '1'
And so on for each equipment.
TIA

In reply to Regex: same code works and fails, why? by Hena

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.