in reply to Re^9: How do I display only matches
in thread (SOLVED) How do I display only matches
Some Windows test code:
My explanation of why "\r\n" doesn't work is functionally correct, but incorrect in the dirty details of Why?. On Windows this will print <CR><CR><LF>. When read back via text mode, only one <CR> will be deleted. The regex fails because there is still another <CR> there and "$" is looking for a 0x0A. Correct?use warnings; use strict; open (my $file, '>', "testendings") or die "unable to open testendings for write! $!"; print $file "test\n"; close $file; print "Binary file created: 74 65 73 74 0D 0A\n"; open (my $infile, '<', "testendings") or die "unable to open testendings for read! $!"; my $in =<$infile>; close $infile; print "input as read by normal string IO: $in"; print "Length in bytes of input var as read is: ".length($in)," bytes\ +n"; $in =~ s/(.)/sprintf("%02X ",ord($1))/seg; print "$in\n"; print "note: when using Perl text read, the 0x0D was deleted!\n"; __END__ Binary file created: 74 65 73 74 0D 0A # 0D=>CR 0A=>LF input as read by normal string IO: test Length in bytes of input var as read is: 5 bytes 74 65 73 74 0A note: when using text read, the 0x0D was deleted!
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^11: How do I display only matches (updated)
by haukex (Archbishop) on Sep 26, 2019 at 06:04 UTC | |
by Marshall (Canon) on Sep 27, 2019 at 23:17 UTC | |
by haukex (Archbishop) on Sep 28, 2019 at 07:54 UTC | |
by Marshall (Canon) on Sep 28, 2019 at 08:37 UTC |