Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re: problem in printing the result in the out put file

by RonW (Parson)
on Mar 02, 2017 at 21:43 UTC ( [id://1183476]=note: print w/replies, xml ) Need Help??


in reply to problem in printing the result in the out put file

I use a similar approach to toolic's suggestion, except I specifically target line endings and anchor the pattern:

s/[\n\r]+$// for (@ip);

Most of the time, this is enough, because when I "export" text files to Ms Windows users, I use unix2dos to convert the line endings to MS Windows convention.

When I want or need a tool that robustly works under both MS Windows and Linux/Unix/POSIX, I would combine that with Eily's suggestion and add in ':raw' mode, like:

my @ip; { local $/ = "\n"; open my $dat, "<:raw", $in_file or die "Can't open file $in_file: $! +"; @ip = <$dat>; s/[\n\r]+$// for (@ip); close $dat; }

(There's probably a module on CPAN that does this, and maybe even add support for legacy MacOS line endings.)

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others about the Monastery: (2)
As of 2024-04-16 23:39 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found