Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

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

by jeffa (Bishop)
on Aug 29, 2003 at 13:41 UTC ( [id://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
Domain Nodelet?
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?Last hourOther CB clients
Other Users?
Others wandering the Monastery: (5)
As of 2024-04-19 02:36 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found