I'm a little confused by item "(2)", because the two lines that look like code (for the two elements of an array called "@arrayelement" are syntax errors. Did you intend to treat SHAPES GREEN;SIZE 240 ... 300 as a single quoted string (and likewise for the second element)?

Also, you didn't mention it specifically, but are the two elements from item "(2)" derived only from the second input line? Would the first input line produce two output array elements like this?

$elem[0] = "SHAPES GREEN1;SIZE 240 500 340 930;SIZE 350 500 240 590;SI +ZE 295 390 015 490;SIZE 350 210 760 300;"; $elem[1] = "SHAPES GREEN2;SIZE 450 310 680 690;SIZE 450 110 680 490;SI +ZE 215 800 560 900;";
If I have that right, then it's true that using "split()" would be a bit clunky, and a regex match would make more sense. For the patterns given, I'd do it like this:
my @matches = ( $inp_line =~ /(SHAPES \w+;(?:SIZE[ \d+])+;)/g );
Or if you want a bunch of matches from various input lines all pushed onto the same array:
my @matches; for ( @inp_lines ) { push @matches, ( /(SHAPES \w+;(?:SIZE[ \d+])+;)/g ); }
Yet another way to look at the problem: if the input lines are being read from some list file (or stdin), such that each line originally has a line-feed at the end, then what you are doing is, in a way, the same as inserting a line-feed in the middle of each line:
s/(?<=\d;)(?=SHAPES )/\n/; # using "look-behind" and "look-ahead # now just split on "\n"...

In reply to Re: splitting line without split by graff
in thread splitting line without split by garbage777

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.