Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re: Modifying data in a hash before sending to template

by sacked (Hermit)
on May 17, 2004 at 04:39 UTC ( [id://353868]=note: print w/replies, xml ) Need Help??


in reply to Modifying data in a hash before sending to template

Data::Dumper will show you the structure of the data returned by selectall_arrayref as used above:
use Data::Dumper; die Dumper $rows; __DATA__ $VAR1 = [ { 'locked' => 'no', 'stick' => 'quux', 'last_update' => '2004-05-17 00:24:28', 'name' => 'qux', 'post' => 'foo', 'author' => 'baz', 'last_updated_by' => 'joe', 'view' => 'bar', 'id' => '1' } ];
This data is suitable for use as a <TMPL_LOOP> in a template prepared for HTML::Template. It is a reference to an array of hashes. Each hash holds the data from one record in your dataset. The keys of the hash are the table columns specified in your SELECT statement.

To remove profanity from each record's "post" field, you can use something like the following:
use Regexp::Common 'RE_profanity'; + foreach my $row ( @$rows ) { # $row is a hash reference containing the # data from a single record $row->{post} =~ s/$RE{profanity}/[censored]/g; } + use Data::Dumper; die Dumper $rows; __DATA__ $VAR1 = [ { 'locked' => 'no', 'stick' => 'foobar', 'last_update' => '2004-05-17 00:33:55', 'name' => 'post with curses', 'post' => 'some [censored] [censored] words', 'author' => 'values', 'last_updated_by' => 'jack', 'view' => 'other', 'id' => '2' } ];
See the pod for Regexp::Common for an explanation of $RE{profanity} and other regular expressions it provides.

--sacked

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://353868]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (8)
As of 2024-04-19 09:41 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found