Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re: skip newline charater when reading

by svenXY (Deacon)
on Jan 13, 2009 at 10:41 UTC ( [id://735917]=note: print w/replies, xml ) Need Help??


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.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://735917]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others examining the Monastery: (8)
As of 2024-04-25 11:34 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found