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:
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.# to be inserted into the while loop above my @lines = split /\n/, $_;
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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |