in reply to Input to String OR Array
This may be what you are looking for:
use strict; use warnings; my $heading = ''; my @lines; while (my $line = <DATA>) { chomp $line; if ($line =~ /^[1-9]/) {#New heading line ProcessEntry ($heading, @lines) if length $heading; $heading = $line; @lines = (); } else {push @lines, $line;} } ProcessEntry ($heading, @lines) if length $heading; sub ProcessEntry { my $heading = shift; my @lines = @_; print "Heading is: $heading\n"; print "Lines are:\n " . join "\n ", @lines; print "\n\n"; }
__DATA__ 1. This string can be modified using only regexes -These strings -Need to be -put into an -array 2.Here's another string needs only regexes -But here are more -strings which -I want arrayed
Which prints:
Heading is: 1. This string can be modified using only regexes Lines are: -These strings -Need to be -put into an -array Heading is: 2.Here's another string needs only regexes Lines are: -But here are more -strings which -I want arrayed
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Input to String OR Array
by jriggs420 (Sexton) on Oct 18, 2005 at 21:59 UTC | |
by GrandFather (Saint) on Oct 18, 2005 at 22:38 UTC | |
by jriggs420 (Sexton) on Oct 19, 2005 at 00:47 UTC |