SPUG: Fw: Reading a whole file into a scalar.

Rick Croote rick.croote at philips.com
Wed Jul 20 18:46:47 PDT 2005


Nothing super sneaky, I just prefer the OO interfaces.  This just uses 
join.

use strict;
use IO::File;

{
    my $fh = new IO::File 'Colours.xml';
    my $file = join '', $fh->getlines;

    print $file;
}

---
Rick Croote
Software Engineer
Environment and Tools Team
Philips Medical Systems
Bothell, WA
Rick.Croote at Philips.com
Phone: 425-487-7834

----- Forwarded by Rick Croote/ATL-BTL/MS/PHILIPS on 2005-07-20 06:44 PM 
-----

spug-list-bounces at pm.org wrote on 2005-07-20 06:24:49 PM:

> I just found this, is this the best practice?
> 
> while ( <COLOURS> )
> {
>   $myfile = $myfile . $_;
> }
> 
> Duane
> 
> On 7/20/05, Duane Blanchard <dblanchard at gmail.com> wrote:
> > Hi gang,
> > 
> > I'm too tired to think straight and too tired to keep looking on the
> > 'Net. I want to match things like 'line\s+that' in the example file
> > below.
> > 
> > <file>
> > this is a line
> > that is a line
> > </file>
> > 
> > What has worn me out today is not realizing that I'll never match
> > across lines of a file if I only read one line at a time. So, I either
> > need a clever way to match across elements of an array or hash table,
> > or (more likely) to read the whole file into a scalar. As I recall,
> > I'll use the 'm' flag to hand the RE more than one line, and '\s'
> > should handle '\n'.
> > 
> > Someone, please give a little pointer. Thanks,
> > 
> > D
> > --
> > Duane Blanchard
> > 206.934.5873
> > 
> > There are 10 kinds of people in the world;
> > those who know binary and those who don't.
> > _____________________________________________________________
> > Seattle Perl Users Group Mailing List
> >     POST TO: spug-list at pm.org
> > SUBSCRIPTION: http://mail.pm.org/mailman/listinfo/spug-list
> >    MEETINGS: 3rd Tuesdays, Location: Amazon.com Pac-Med
> >    WEB PAGE: http://seattleperl.org/
> > 
> 
> 
> -- 
> Duane Blanchard
> 206.934.5873
> 
> There are 10 kinds of people in the world;
> those who know binary and those who don't.
> _____________________________________________________________
> Seattle Perl Users Group Mailing List 
>      POST TO: spug-list at pm.org
> SUBSCRIPTION: http://mail.pm.org/mailman/listinfo/spug-list
>     MEETINGS: 3rd Tuesdays, Location: Amazon.com Pac-Med
>     WEB PAGE: http://seattleperl.org/
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.pm.org/pipermail/spug-list/attachments/20050721/e90c0f2c/attachment-0001.html


More information about the spug-list mailing list