Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Re: Character Text Delimiters

by Sue D. Nymme (Monk)
on Oct 25, 2011 at 18:39 UTC ( [id://933674]=note: print w/replies, xml ) Need Help??


in reply to Character Text Delimiters

Have you considered splitting the string on "), XX("? Something like:

@chunks = split /\), ([A-Z][A-Z])\(/, $input;

That'll give you all the values interspersed with the prefixes (with the first and last elements being wacky because you matched on the stuff that goes between each value).

In fact, you could make the split pattern a bit more complex, to separate out the first "AA(" and the last ")":

@chunks = split /(?: (?:^|\),\s) ([A-Z][A-Z])\( | \)$)/x, $input; shift @chunks; # remove extra blank element at front

Then you can use part from List::MoreUtils to partition the list into prefixes and values, or you could just assign it to a hash and use it directly:

use List::MoreUtils qw(part); my @chunks = ...; # as above shift @chunks; # as above my $ix = 0; my ($prefixes,$texts) = part {++$ix % 2} @chunks; # or my %text = @chunks; say "Text value AF is $text{AF}";

Replies are listed 'Best First'.
Re^2: Character Text Delimiters
by Ninthwave (Chaplain) on Oct 25, 2011 at 19:45 UTC

    I did try something similar but on the last pattern the text value in one case was

    AC(Departament d'Astronomia i Astrofísica. Universitat de València. C/Dr. Moliner 50, 46100 Burjassot (València), Spain)

    And was having problems with the (Valencia) portion and if I used the | was getting too much but I will try this or variant to see if it can be consistent. Sorry I don't have the exact pattern from the previous attempt that was similar to this split.

    "No matter where you go, there you are." BB

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others surveying the Monastery: (2)
As of 2024-04-25 20:19 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found