This is a repost. The entire script is posted below, unlike before when everyone had the wrong idea (to my fault) at what the problem was.

Can someone help me figure out why it prints the last record X number of times rather than all the records of the hash as I want? For example, if I have two names in the hash "Me", "You" and I do this using [ab] (saying $ab is the name), it would print out "You" "You" when you run the script. It always prints the last record X number of times (it'll print 3 times if there are three keys, 10 times if there are 10). Can someone help me make it work so I can do all the substitutions for each key?

(Please don't comment on my variable names, I'll change those when I get this part working).

#!/usr/bin/perl use strict; use warnings; use POSIX; use CGI qw/:standard/; use CGI::Carp qw(fatalsToBrowser); require SDBM_File; my %data; my $data = "mylist.dbm"; my $specifics= param('specifics'); my $lookup = url_param('lookup'); tie %data, 'SDBM_File', $data, O_CREAT | O_RDWR, 0644; if ( !tied %data ) { print "error $!.\n"; } print header(); print start_html(); print <<"ALL"; <table width="470" border="0"> <form name="extract" method="post" action="extract.pl"> <tr><td colspan="2"><textarea name="specifics" cols="40" rows="5" id=" +specifics">$specifics</textarea></td></tr> <tr><td><input type="submit" name="submit1" value="submit"></td></tr> </form> </table> ALL if (param('submit1')) { foreach (sort keys %data) { my ($ab, $bb, $cb, $db, $eb, $fb) = split(/::/, $data{$_}); $specifics =~ s/\[a\]/$ab/; $specifics =~ s/\[b\]/$bb/; $specifics =~ s/\[more\]/$data{$_}/; $specifics =~ s/\[c\]/$cb/; $specifics =~ s/\[d\]/$db/; $specifics =~ s/\[e\]/$eb/; $specifics =~ s/\[f\]/$fb/; print "$specifics<br>"; } }

In reply to Only printing last hash (repost) by Anonymous Monk

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.