Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
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>"; } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Only printing last hash (repost)
by tilly (Archbishop) on Jan 04, 2004 at 03:53 UTC | |
|
Re: Only printing last hash (repost)
by neuroball (Pilgrim) on Jan 04, 2004 at 04:03 UTC | |
|
Re: Only printing last hash (repost)
by pg (Canon) on Jan 04, 2004 at 05:44 UTC | |
|
Re: Only printing last hash (repost)
by ysth (Canon) on Jan 04, 2004 at 06:58 UTC |