Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

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

by jeffa (Chancellor)
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 exploiting the Monastery: (14)
As of 2014-12-19 09:42 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (75 votes), past polls