ispman/lib/ISPMan Utils.pm,1.19,1.20

[email protected]
Newsgroups gmane.comp.isp.ispman.cvs
Message-ID <[email protected]>
Update of /cvsroot/ispman/ispman/lib/ISPMan
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv18246/lib/ISPMan

Modified Files:
	Utils.pm 
Log Message:
added new helper function for token substitution

Index: Utils.pm
===================================================================
RCS file: /cvsroot/ispman/ispman/lib/ISPMan/Utils.pm,v
retrieving revision 1.19
retrieving revision 1.20
diff -u -d -r1.19 -r1.20
--- Utils.pm	4 Jan 2004 18:56:15 -0000	1.19
+++ Utils.pm	13 Feb 2004 22:02:25 -0000	1.20
@@ -61,6 +61,7 @@
 isEmpty
 hasValue
 unique
+substitute
 );
 
 
@@ -563,6 +564,37 @@
    return keys %hr;
 }
 
+sub substitute {
+    # substitute tokens from substmap in scalar
+
+    my $self=shift;
+    my $data=shift;
+    my $map=shift;
+
+    for (keys %$map) {
+	my $val=$map->{$_};
+	$data =~ s/%$_%/$val/g;
+    }
+    return $data;
+
+=item B<substitute>
+
+substitute tokens with values in supplied data.
+
+I<Example>
+my $substmap = {
+    item => $var1,
+    what => $var2 };
+
+my $var=$ispman->substitute("my %item% is %what%", $substmap);
+
+will result in
+
+$var="my $var1 is $var2";
+
+=cut
+
+}
 
 1;
 __END__



-------------------------------------------------------
SF.Net is sponsored by: Speed Start Your Linux Apps Now.
Build and deploy apps & Web services for Linux with
a free DVD software kit from IBM. Click Now!
http://ads.osdn.com/?ad_id=1356&alloc_id=3438&op=click
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.