The UK Home Automation Archive

Archive Home
Group Home
Search Archive


Advanced Search

The UKHA-ARCHIVE IS CEASING OPERATIONS 31 DEC 2024

Latest message you have seen: RE: Oopsie... Re: BioLogon


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: OT: Perl problem



Hi Tony,

Try this. It could all have been squeezed onto one line I expect but I
thought I'd comment it a bit for a change. It does read all the data in one
go but 15Mb isn't really all that much and doing it in chunks is a bit more
of a pain to do since you have to keep track of where you are and there
would have to be a loop in there too.

Cheers,

Phil,

==============
#!/usr/bin/perl -w

use strict;

$ = 1;

# Read all the data in one go, it's only 15Mb!
local $/;
my $data = <>;

# Remove any newlines (if there are any)
$data =~ s/\n//g;

# Break it into 80 char chunks
my @lines = split( /(.{80})/, $data );

# And join all the non-empty ones together with newlines
print join( "\n", grep { $_ } @lines );

# Add a trailing new line if you want one.
print "\n";
===============


----- Original Message -----
From: "Tony Butler" <lists@xxxxxxx>
To: <ukha_d@xxxxxxx>
Sent: Thursday, July 17, 2003 8:17 AM
Subject: [ukha_d] OT: Perl problem


> I know there's gonna be some perl whizzes here, so perhaps you could
help
me
> out as someone not at all familiar with perl:
>
> I need to read in a text file about 15Mb in size and basically split
it
into 80
> chars per line + a new line char on the end.
> and spit it out again
>
> eg. instead of AGATCAGTACTGACTTGATCAGTTACGTCATGTACGT
> have
> AGATATC
> CATGACT
> TAGCATA
> CATGATA
> [obviously that wasn't 80 chars, per line, but u get the idea.
>
> I'm thinking coz it's such a large file that reading it ann in one go
isn't a
> good idea :/  Am complete n00b to perl, so would appreciate any help.
>
> cheers,
>
> Tony
>
>
>
> ** UKHA2004 BE THERE! ** - start planning now.
>
> http://www.automatedhome.co.uk
> Post message: ukha_d@xxxxxxx
> Subscribe:  ukha_d-subscribe@xxxxxxx
> Unsubscribe:  ukha_d-unsubscribe@xxxxxxx
> List owner:  ukha_d-owner@xxxxxxx
>
> Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/
>
>




Home | Main Index | Thread Index

Comments to the Webmaster are always welcomed, please use this contact form . Note that as this site is a mailing list archive, the Webmaster has no control over the contents of the messages. Comments about message content should be directed to the relevant mailing list.