Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re: Putting special elements from a row into an array

by shmem (Canon)
on Mar 22, 2007 at 14:44 UTC ( #606037=note: print w/ replies, xml ) Need Help??


in reply to Putting special elements from a row into an array

best woud be if i can place every NUMBER(numbers) in one array and the rest in one array, the stuff infront of the ; can be ignored will be splited away
Your specs are unclear; your working example does not do that. Instead, the first \d+ ends up in $pre, the stuff in parens in $in and the remainder in $post.

I guess you want something that keeps doing that, but stuffs the \d+ cuddled to an opening paren into $in if there are more numbers up front. Quick shot:

#!/usr/bin/perl use warnings; use strict; while (<DATA>) { chomp; my ($ezb, $numbers) = split(';',$_); my( $pre, $in, $post )= $numbers =~ /^(\d+(?=\()|[\d+, ]+?)(\d*\(. +*\))(.*)/; print "$_:\n \$pre = '$pre\n \$in = '$in'\n \$post = '$post' +\n"; } __DATA__ 201.1;201(27, 28, 3, 4, 83, 84, 890, 897, 898, 9), 2054 201.2;201(1, 20-26, 29, 80-82, 891-896, 899) 201.3;201(52-54, 6, 75, 76, 85-88) 201.4;201(50, 51, 55-59, 70-74, 77-79) 2302.1;2302, 2304(3-8, 92-99), 2305(2, 4-9) 231.1;2301, 2303, 2304(1, 2, 90, 91), 2305(1, 3), 2306, 2307, 2308

outputs

201.1;201(27, 28, 3, 4, 83, 84, 890, 897, 898, 9), 2054: $pre = '201 $in = '(27, 28, 3, 4, 83, 84, 890, 897, 898, 9)' $post = ', 2054' 201.2;201(1, 20-26, 29, 80-82, 891-896, 899): $pre = '201 $in = '(1, 20-26, 29, 80-82, 891-896, 899)' $post = '' 201.3;201(52-54, 6, 75, 76, 85-88): $pre = '201 $in = '(52-54, 6, 75, 76, 85-88)' $post = '' 201.4;201(50, 51, 55-59, 70-74, 77-79): $pre = '201 $in = '(50, 51, 55-59, 70-74, 77-79)' $post = '' 2302.1;2302, 2304(3-8, 92-99), 2305(2, 4-9): $pre = '2302, $in = '2304(3-8, 92-99), 2305(2, 4-9)' $post = '' 231.1;2301, 2303, 2304(1, 2, 90, 91), 2305(1, 3), 2306, 2307, 2308: $pre = '2301, 2303, $in = '2304(1, 2, 90, 91), 2305(1, 3)' $post = ', 2306, 2307, 2308'

Is that what you seek to accomplish?

--shmem

_($_=" "x(1<<5)."?\n".q·/)Oo.  G°\        /
                              /\_¯/(q    /
----------------------------  \__(m.====·.(_("always off the crowd"))."·
");sub _{s./.($e="'Itrs `mnsgdq Gdbj O`qkdq")=~y/"-y/#-z/;$e.e && print}


Comment on Re: Putting special elements from a row into an array
Select or Download Code
Re^2: Putting special elements from a row into an array
by ultibuzz (Monk) on Mar 22, 2007 at 15:17 UTC

    there are 2 data models, ure script will work with both of them
    wich is nice ;), but the other also works great because these 2 datamodels shoud not be mixed up ever
    kd ultibuzz

      there are 2 data models, ure script will work with both of them
      It is either "ur" or "your", but I prefer the latter.

      sry scnr kk cu

      ;-)

      --shmem

      _($_=" "x(1<<5)."?\n".q·/)Oo.  G°\        /
                                    /\_¯/(q    /
      ----------------------------  \__(m.====·.(_("always off the crowd"))."·
      ");sub _{s./.($e="'Itrs `mnsgdq Gdbj O`qkdq")=~y/"-y/#-z/;$e.e && print}

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (14)
As of 2015-07-02 10:27 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (33 votes), past polls