http://www.perlmonks.org?node_id=500430


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>

Replies are listed 'Best First'.
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.