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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |