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
In reply to Re: Input to String OR Array
by GrandFather
in thread Input to String OR Array
by jriggs420
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |