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

Re: mac file problem

by Kenosis (Priest)
on Mar 16, 2013 at 23:37 UTC ( #1023856=note: print w/ replies, xml ) Need Help??


in reply to mac file problem

That's because you're only asking Perl to read one line with my $content = <HANDLE>;. If you preceeded the open with local $/; it would work, i.e., you'd slurp all the file's contents into $content, because you've set a local copy of Perl's record seperator ($/) to undef.

However, try the following idiomatic way, too:

#!/usr/bin/perl use strict; use warnings; use diagnostics; my $content = do { local $/; <> }; print "$content\n";

When you've passed a file to a script on the command line for reading, you don't need to explicitely open it, as using only <> will read it.

Hope this helps!

BTW - For your future reference, always use the three-argument open, e.g., open my $fh, '<', $fileloc or die "Cannot open file: $!";


Comment on Re: mac file problem
Select or Download Code
Reaped: Re^2: mac file problem
by NodeReaper (Curate) on Mar 16, 2013 at 23:55 UTC

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (6)
As of 2014-08-29 08:14 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (277 votes), past polls