Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re: split a line by control ^D character

by rcrews (Novice)
on Dec 04, 2012 at 18:29 UTC ( #1007136=note: print w/ replies, xml ) Need Help??


in reply to split a line by control ^D character

One simple way to do what you're doing is to change the value of Perl's input record separator from an end-of-line to a ^D:

my $FileLocation = '/home/RND/Sample.txt'; open my $FILE, '<', $FileLocation or die "$!"; my @LineDetails = do { local $/ = chr(4); <$FILE> }; map { print "$_\n" } @LineDetails;

This eliminates both for loops.

Note that the foreach keyword is actually a synonym for the for keyword, so in your original post, you can have replaced "foreach" with "for" in both places, which also simplifies your code.


Comment on Re: split a line by control ^D character
Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (7)
As of 2016-02-14 23:43 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How many photographs, souvenirs, artworks, trophies or other decorative objects are displayed in your home?





    Results (471 votes), past polls