Home
TeamSite
iterating over dcr elements with perl
craigm
I'm using the example callout.ipl to populate a dcr dropdown from a flat file. I can iterate over the dcr elements with javascript but can't figure out how to pass these values to the perl.
Better, I'd like to iterate over the dcr elements with perl. Maybe something like (I'm not a perl programmer):
-------------------
my $form_name = $cgi->{'form'}{'iw_form_name'};
foreach $value ($form_name.element) {
print "Element value = $value\n";
}
-------------------
Can anybody post an example of how I might do this?
Thanks in advance.
Find more posts tagged with
Comments
prasadanand
my $dir = "/iwmnt/default/main/test/WORKAREA/test/templatedata/testsri/categories/data/";
chdir( $dir ) ;
# Put files into an array
foreach(<*>) {
push
@dcr_list
, $dir . $_;
}
for (my $i = 0; $i <
@dcr_list
; $i++) {
# Load dcr and extract information
open (DCR, $dcr_list[$i]);
my $xml_string = join ('', (<DCR>));
close DCR;
my $rootnode = TeamSite:
CRnode->new($xml_string);
if (defined $rootnode) {
foreach( $rootnode -> list( "Categories.*" ) ) {
push
@head_list
, $_->value() ;
}
}
}
this might help
craigm
Thanks for posting the code. Again, I'm not a perl pro but it looks like your getting every dcr in the my $dir directory. I really want just the elements in the dcr that's doing the callout. From the example file, I have access to these values:
my $form_name = $cgi->{'form'}{'iw_form_name'};
my $element_name = $cgi->{'form'}{'iw_callback_var'};
So I'm hoping I can just iterate over the elements in $form_name?
In your code, would I then print the values out with a foreach?
foreach $value (
@head_list)
{
print "category = $value\n";
}
Thanks again. craig