i accidentally hit the new button a little too early, sorry for the duplicate posts...
i have a subroutine which does some processing on html files and stores values from those files into a hash. now up until recently i had made it a habit not to use -w or use strict in my scripts, but well i just decided i oughta start :) so anyway, i have this hash that looks like this:
sub processhtml {
my ($file) = $_[0];
my ($filename, $i, $value2, $value3);
my (@input, @values);
... substitution and pattern match stuff ...
@values = split(" ", $i);
if ($values[2] !~ /^[a-z]{1,2}$/i) {
$values[2] = "";
} else {
}
if ($values[0] !~ /000/) {
$import_values{"ship"} = $file;
$import_values{"weight"} = $values[0];
$import_values{"dwg"} = $values[1];
$import_values{"rev"} = $values[2];
foreach $value2 (keys %import_values{"ship","weight","dwg","rev
+"}) {
print TEMP ("\"$value2\",");
}
print TEMP ("\n");
} else {
$import_values{"ship"} = $file;
$import_values{"weight"} = "";
$import_values{"dwg"} = $values[1];
$import_values{"rev"} = $values[2];
foreach $value3 (keys %import_values{"ship","weight","dwg","rev
+"}) {
print TEMP ("\"$value3\",");
}
print TEMP ("\n");
}
}
now the problem lies in the foreach loops, i keep getting the error "Can't use subscript on private hash" and i don't know why... as weird as it may sound prior to applying use strict and -w i had array symbols preceding them
foreach $value3 (keys @import_values{"ship","weight","dwg","rev
+"}) {
print TEMP ("\"$value3\",");
}
and it worked, but now this problem is driving me up the wall... can anyone shed any light on this for me?
In reply to hashes
by jrsmith
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.