in reply to skip newline charater when reading

Hi,
open(OUT,">$outfile"); open(F1, "<$infile") or die "Could not open $infile for reading!\n"; $/ = "#"; while (<F1>) { chomp; # <--- remove trailing newline character print OUT "$_\n"; }
should do the trick
Regards,
svenXY

Replies are listed 'Best First'.
Re^2: skip newline charater when reading
by moritz (Cardinal) on Jan 13, 2009 at 10:47 UTC
Re^2: skip newline charater when reading
by davido (Cardinal) on Jan 13, 2009 at 17:04 UTC
    open(OUT,">$outfile"); open(F1, "<$infile") or die "Could not open $infile for reading!\n";

    I realize that this is just an example snippet, but.... verbally fail if $infile won't open, and silently fail if the output file can't be opened? Also, have a look at the first paragraph or two of chomp and how it reacts to changes to $/. You're not removing the trailing newline characters.


    Dave

Re^2: skip newline charater when reading
by repellent (Priest) on Jan 13, 2009 at 17:37 UTC
    chomp will try to remove the input record separator $/.

    $_ may have embedded "\n". The chomp approach does not deal with this issue.
Re^2: skip newline charater when reading
by coldy (Scribe) on Jan 13, 2009 at 10:46 UTC
    Thanks but doesn't that just remove the last character of the line that is read, this just deleted my '#' characters, leaving the newline characters.