Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re: split a line by control ^D character

by rjt (Curate)
on Dec 02, 2012 at 11:38 UTC ( [id://1006708]=note: print w/replies, xml ) Need Help??


in reply to split a line by control ^D character

Yes, you definitely want to split on /\x04/ . In addition to that, there are a few places where your code could be cleaned up a little.

You are declaring @LineDetails outside of your loop. Is there any reason for that? At least in your example, you only use it inside the loop, as a temp variable. You don't actually need the variable at all, to do what you need to do in this example.

You are sucking the entire file into an array. This can be very memory intensive, depending on the size of the file. It can also cause your program to appear to hang when it is started. Plus, you can eliminate another variable if you read the file line by line.

I would clean up everything after the open() line as follows:

use 5.010; # Allow say(). You can use print "$_\n" if you like. ... while (<$FILE>) { chomp; say for split /\x04/; }

One last thing, as a general security tip, you would be well advised to get used to using the 3 argument open, (i.e., open my $FILE, '<', $FileLocation in your case).

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others imbibing at the Monastery: (3)
As of 2024-04-24 20:22 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found