Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Perl Idioms Explained - my $string = do { local $/; <FILEHANDLE> };

by jeffa (Bishop)
on Aug 29, 2003 at 13:41 UTC ( #287647=perlmeditation: print w/ replies, xml ) Need Help??

Help for this page

Select Code to Download


  1. or download this
    open FILEHANDLE, 'somefile.txt' or die $!;
    my $string = do { local $/; <FILEHANDLE> };
    
  2. or download this
    open FILEHANDLE, 'somefile.txt' or die $!;
    my $string = '';
    while (<FILEHANDLE>) {
        $string .= $_;
    }
    
  3. or download this
    my $scalar = <FILEHANDLE>;    # one line
    my @array  = <FILEHANDLE>;    # whole file
    
  4. or download this
    undef $/;
    my $scalar = <FILEHANDLE>;   # whole file
    
  5. or download this
    local $/;
    
  6. or download this
    local $/ = undef;
    
  7. or download this
    $/ = undef;           # Danger Will Robinson! Danger!
    
  8. or download this
    my $string = do {local $/;<DATA>};
    
  9. or download this
    my $data = do {local $/;<DATA>};
    my $template = HTML::Template->new(scalarref => \$data);
    
  10. or download this
    my $template = HTML::Template->new(filehandle => \*DATA);
    

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlmeditation [id://287647]
Approved by Corion
Front-paged by broquaint
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (12)
As of 2015-07-29 18:27 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 (267 votes), past polls