Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re: breaking up a file by delimiter

by hippo (Bishop)
on Oct 07, 2018 at 09:30 UTC ( #1223635=note: print w/replies, xml ) Need Help??


in reply to breaking up a file by delimiter

This gives the following correct output:

$VAR1 = ['This is a test.','This is a multiline test.']

Not on my perl. Here it gives:

$VAR1 = ['This is a test. ',' This is a multiline test. '];

As it's hard to know from that what you actually want, here's an SSCCE which preserves the multi-line nature of the second string but removes the trailling newlines. You can amend it to suit your actual requirements.

use strict; use warnings; use Test::More tests => 1; my @data; my @want = ('This is a test.', "This is a multiline\ntest."); { local $/ = "\nXXX\n"; chomp (@data = <DATA>); } is_deeply (\@data, \@want); __DATA__ This is a test. XXX This is a multiline test. XXX

Replies are listed 'Best First'.
Re^2: breaking up a file by delimiter
by Anonymous Monk on Oct 07, 2018 at 10:35 UTC

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (4)
As of 2022-05-23 20:02 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Do you prefer to work remotely?



    Results (82 votes). Check out past polls.

    Notices?