The construct while (<>) {do_something} reads either from STDIN or automatically opens the files in @ARGV one by one and reads from them. So this is not what you want in your code. You need the while (<INPUT>) {...} construct.

Instead you might use something like this:

#/usr/bin/perl # call this with perl prog.pl output_file input.db my $output = shift; # remove output_file from @ARGV open(OUTPUT, ">", $output) or die "Can't open $output: $!"; $/="//\n"; # now read from the remaing files in @ARGV (or STDIN) # and let perl handle the opening ... while (<>) { # do something }

To process your record linewise, you can split it on newline:

# to be inserted into the while loop above my @lines = split /\n/, $_;
Setting back the input line separator $/ is not an option, because you are no longer reading the record from a file. You just read it and now want to do something linewise with it.

In addition to that note that you might not have to do the breaking up in lines. The substitution e.g. is happy to work on multiline strings as well (but see the /s and /m modifiers).

-- Hofmator


In reply to Re: about separator by Hofmator
in thread about separator by agustina_s

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.