Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re: About $/

by kcott (Chancellor)
on May 25, 2013 at 07:12 UTC ( #1035234=note: print w/replies, xml ) Need Help??


in reply to About $/

G'day lddzjwwy,

Perhaps something along these lines:

$ perl -Mstrict -Mwarnings -E ' # Create test data use autodie qw{:all}; use File::Temp; my $fh = File::Temp->new(UNLINK => 1); print $fh "qwe\rasd\003zxc\r123"; seek $fh, 0, 0; # Read data splitting on "\r" or "\003" say for split /(?>\r|\003)/ => do { local $/; <$fh> }; ' qwe asd zxc 123

I assume you've picked "\003" purely as an example; I've used the same in the code above. However, using constructs like \o{...}, \x{...}, etc. may save you some interpolation issues down the track (see escape sequences in perlop - Quote and Quote-like Operators).

-- Ken

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1035234]
help
Chatterbox?
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (7)
As of 2018-06-23 08:34 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Should cpanminus be part of the standard Perl release?



    Results (125 votes). Check out past polls.

    Notices?