Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re: Get only 1KB from text File

by gopalr (Priest)
on Oct 15, 2005 at 06:13 UTC ( #500430=note: print w/ replies, xml ) Need Help??


in reply to Get only 1KB from text File

Hi

User Input Record Separator ($/)

local $/=\"1024"; open FILE, 'c:\space\sp.txt' or die $!; $_=<FILE>; #<IT WILL READ ONLY 1KB>


Comment on Re: Get only 1KB from text File
Select or Download Code
Re^2: Get only 1KB from text File
by graff (Chancellor) on Oct 15, 2005 at 13:54 UTC
    Bear in mind that "local $/..." will only be "local" if it's inside a curly-brace block:
    { local $/=\"1024"; open FILE, 'c:\space\sp.txt' or die $!; $_=<FILE>; #<IT WILL READ ONLY 1KB> } # now $/ is back to its original value # another way (note that quotes are not needed): open FILE, $name or die $!; $_ = do { local $/ = \1024; <FILE> };
    If you miss that little detail, "local" is equivalent to "main".

    But really, just using "read()" seems easier.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (10)
As of 2015-07-06 23:11 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (85 votes), past polls