Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re: Split string after 14 Line Feeds?

by LanX (Chancellor)
on Dec 04, 2012 at 00:35 UTC ( #1006970=note: print w/replies, xml ) Need Help??


in reply to Split string after 14 Line Feeds?

A more general approach with "nested" iterators:

sub read_chunk { my ($fh,$mod) = @_; my $chunk; while ( <$fh> ) { $chunk .= $_; return $chunk unless $. % $mod; } return $chunk; } open my $fh, "<", \$string; while ( my $chunk = read_chunk( $fh, 14 ) ) { print $chunk; print "-"x5,"\n"; }

works with anything you can open via filehandle even strings.

Cheers Rolf

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1006970]
help
Chatterbox?
[Tanktalus]: SwaJime: wouldn't status & status < 13 be true if status was 0?
[SwaJime]: I thought 0 was false, and false AND anything would be false ...
[SwaJime]: unless & is higher precedence than <
[SwaJime]: couldn't find bitwise in precedence list for sybase

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (9)
As of 2017-08-22 18:07 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Who is your favorite scientist and why?



























    Results (338 votes). Check out past polls.

    Notices?