Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
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 having an uproarious good time at the Monastery: (10)
As of 2014-10-30 13:22 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    For retirement, I am banking on:










    Results (208 votes), past polls