Yes and no.

Yes, if you read in many different files, perform the same types of operations on them, but don't create a function to handle those manipulations. Or at least a loop. People who do this tend not to be diligent about error handling and tie themselves up in global variable failure knots.

# don't do this my @lines; open(DATA, ">file1"); while (<DATA>) { push @lines, $_; } process(@lines); open(DATA, ">file2"); @lines = <DATA> while (<DATA>) { push @lines, $_; } process(@lines);
This isn't a problem for filehandles, but what if the second open fails? What if process() doesn't remove everything from @lines? How long will you spend tracking down an error set by file #2 in a global variable that only shows up when you process file #10?

No, if you have a couple of functions that do different things but use lexical variables within the functions.

sub read_file { my $filename = shift; open (DATA, ">$filename") or return; # could die on error my @lines = <DATA>; return process(@lines); }
Besides that, if you keep using the same spot in memory over and over, you might cause that particular byte to fail prematurely. Better to spread things over the whole RAM stick.

In reply to Re: Using a Variable Mutipule times(with different data) by chromatic
in thread Using a Variable Mutipule times(with different data) by Keef

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.