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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.