Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot

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

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?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlmeditation [id://287647]
Approved by Corion
Front-paged by broquaint
[ambrus]: I have to tolerate syntax highlighters when other people use them, but I don't use them myself. And sorry for the rant.
[GotToBTru]: I appreciate the ability to highlight matching brackets/ parentheses/ braces, both for my own code and the inconsistently indented code of others
[Corion]: I like editors that automatically highlight the matching parenthesis (like % in vi), but that's roughly the extent to which I like editor support ;)
[GotToBTru]: same here Corion.
[Corion]: I tried for a short time (well, 8 hours now) to get Perl::Tidy set up but then found that it doesn't support (new-style) signatures and then stopped again ;))
[GotToBTru]: changing the font color of the rest of the document just because I typed a single quote character is annoying

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (7)
As of 2017-02-27 12:51 GMT
Find Nodes?
    Voting Booth?
    Before electricity was invented, what was the Electric Eel called?

    Results (385 votes). Check out past polls.