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.# 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; }
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 '::').perl -e 'use Equipment;@a=(5,1,6,4);foreach (@a) { Equipment::read_eq( +$_); }'
# 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
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.
In reply to Regex: same code works and fails, why? by Hena
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |