Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re: spliting text!!

by imp (Priest)
on Mar 08, 2007 at 19:10 UTC ( #603883=note: print w/ replies, xml ) Need Help??


in reply to spliting text!!

use strict; use warnings; my $line = <DATA>; # Quick and dirty # Greedily match anything from 1-70 characters my @lines = $line =~ /.{1,70}/g; print $_,"\n" for @lines; # Less memory use for large blocks of text while ($line =~ /(.{1,70})/g) { print $1,"\n"; } __DATA__ 1234567890123456789012345678901234567890123456789012345678901234567890 +123456789012345678901234567890123456789012345678901234567890123456789 +012345678901234567890123456789012345678901234567890123456789012345678 +901234567890123456789012345678901234567890123456789012345678901234567 +890123456789012345678901


Comment on Re: spliting text!!
Download Code
Re^2: spliting text!!
by duff (Vicar) on Mar 08, 2007 at 19:29 UTC

    Just because I'm mildly annoyed at the width of your code, how about, instead of reading from the DATA file handle you do something like this:

    my $line = '1234567890' x 20;
    BTW, you may want to use /s on your pattern so that . matches any character since we don't know the exact contents of the OP's strings.

    cheers,

      If the code isn't wrapping you can goto "Display Settings" and uncheck 'Code Wrapping Off' so that perlmonks will wrap the code up for you. Just an FYI in case you (or someone else reading) didn't know.


      ___________
      Eric Hodges
        Well, I've tried that setting both ways, but right now the front page of SOPW is till too wide, although being here (replies section), width is fine....
        Any tips?

        Cheers
        Chris

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://603883]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (5)
As of 2014-08-22 03:11 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (145 votes), past polls