Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re^3: Perl regex txt file new line (not recognised?)

by BillKSmith (Monsignor)
on Jan 21, 2020 at 20:41 UTC ( [id://11111706]=note: print w/replies, xml ) Need Help??


in reply to Re^2: Perl regex txt file new line (not recognised?)
in thread Perl regex txt file new line (not recognised?)

Even if your disc file is exactly what you expect, you must fix your regex to match and remove the newlines from the unwanted lines.
use strict; use warnings; my $file = \do{my $disk_file = "Inventorier\n" ."Trade receivables\n" ."Assets\n" ."This item includes impairment losses.\n" ; }; open (IN,'<:encoding(UTF-8)', $file) or die "Could not open '$file'$!" +; *OUT = *stdout; while (my $text = <IN>) { #$text =~ s/^[a-z].*[a-z]$//gmi; $text =~ s/^[a-z].*[a-z]\n$//i; print OUT $text; } close (IN) or die "Could not close input file: '$file' $!";

Note that I have not made any other changes to your posted code (except to remove the looping and the output files.) Even though this should 'work', I prefer LanX's first suggestion.

Bill

Log In?
Username:
Password:

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

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

    No recent polls found