Hello rahulruns,
Also let me know if you have any other tips and comment for my code
This line:
my %hash_for_db_connect = ("companyname " => "contactnames", "contactn +ame" => "contactnames", "title" => "contactnames");
looks like a potential bug to me: do you really want “companyname” followed by a space as a hash key? I’m assuming not, in which case you can avoid the problem by taking advantage of the fact that Perl’s “fat comma” operator => quotes its left operand (see perlop#Comma-Operator), allowing you to write:
my %hash_for_db_connect = (companyname => "contactnames", contactname +=> "contactnames", title => "contactnames");
It’s also a good idea to delay the declaration of variables until they are actually needed, to avoid unnecessary variables altogether, and to use statement modifiers where possible. So this:
... foreach (@module_file_lines){ print $test_build_file_handle $_; } my @forms_required = ("createnewcid", "customerform"); my @child_node_values_fill; my $locatory_fields_id; my $locator_type; my $event_type; my $data_fill; my %hash_for_db_connect = ("companyname " => "contactnames", "contactn +ame" => "contactnames", "title" => "contactnames"); foreach my $config_forms (@forms_required) { @child_node_values_fill = get_child_node_value($config_forms); foreach (@child_node_values_fill) { ($locatory_fields_id, $locator_type, $event_type, $dat +a_fill) = split (/,/, $_); ...
would be better written as the shorter and simpler:
... print $test_build_file_handle $_ for @module_file_lines; my %hash_for_db_connect = (companyname => 'contactnames', contactname +=> 'contactnames', title => 'contactnames'); for my $config_forms (qw( createnewcid customerform )) { for (get_child_node_value($config_forms)) { my ($locatory_fields_id, $locator_type, $event_type, $data_fil +l) = split /,/; ...
Hope that helps,
| Athanasius <°(((>< contra mundum | Iustus alius egestas vitae, eros Piratica, |
In reply to Re: Writing a file from foreach loop
by Athanasius
in thread Writing a file from foreach loop
by rahulruns
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |