Others already gave you good suggestions as to how to do what you want. I feel like adding a few random observations:
sub setManagers() { my $getInputFlag = 1; my $writeFileFlag = 1; my $mCounter = 0;
This may be a spurious comment, but in my experience I found that in Perl you seldom need flag variables like that. Not to say that this is "wrong", but sounds suspect...
my $ans = &promptUser("Do you wish to configure SNMP Managers +on $var? ", "yes");
In modern perls you most often do not want to adopt the & form of sub call unless you really know what you're doing, which doesn't appear to be the case here...
if ($ans =~ /^[n]o?/i) {
[n]?
if ($address =~ /^(([3-9]\d?|[01]\d{0,2}|2\d?|2[0-4]\d|25[0- +5])\.){3}([3-9]\d?|[01]\d{0,2}|2\d?|2[0-4]\d|25[0-5])$/)
Here your regex has the form ^(?:/$regex\.){3}/$regex$, so you could increase its readability porting it explicitly into that form. Also, here you have parens for grouping (an alternation), but they're capturing parens, so you may change them into
(?:[3-9]\d?|[01]\d{0,2}|2\d?|2[0-4]\d|25[0-5])
instead.

All in all I'd use an appearently more complex, but IMHO more readable test possibly putting it into a sub. I'd split on /\./\, then check that the return list has four elements, and do a check on each of them. This seems more {portable,maintainable}, especially if -like it seems reasonable- each of them would require a separate range of validity.

$managers[$mCounter]{address} = $address; $managers[$mCounter]{port} = $port; $managers[$mCounter]{version} = $version; $managers[$mCounter]{community} = $community;
Also:
@{ $managers[$mCounter] }[qw/address port version community]= ($address $port $version $community);
But then I wouldn't probably create the intermediate variables at all, if you ask me...
my $numOfManagers = scalar(@managers); print FILE "manager.total=$numOfManagers\n"; for (my $i=0; $i<$numOfManagers; $i++) {
scalar is pleonastic there, and a rule of thumb is that Perl-style for loops should always be preferred over C-style ones, if they're equivalent, i.e. if the latter doesn't buy you something special, which definitely is not the case here. Thus:
for my $i (0..$#managers) { ... }
But then chances are that doing some modification in the logic above you may just turn it into
for my $item (@managers) { ... }

In reply to Re: updating to a file by blazar
in thread updating to a file by s_gaurav1091

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.