Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re^2: match lines containing state abbreviation

by PerlSufi (Friar)
on Apr 18, 2013 at 17:47 UTC ( #1029395=note: print w/replies, xml ) Need Help??


in reply to Re: match lines containing state abbreviation
in thread match lines containing state abbreviation

Thanks for the response, Ken. That is helpful how you explained it. However, should I make the $content an array of lines to match? I have taken out the foreach operator right now..
  • Comment on Re^2: match lines containing state abbreviation

Replies are listed 'Best First'.
Re^3: match lines containing state abbreviation
by kcott (Chancellor) on Apr 18, 2013 at 18:20 UTC

    Splitting the lines to create an array is probably what I would have done. However, if you want to work directly with a multiline string, here's one way to do it:

    $ perl -Mstrict -Mwarnings -E ' my $lines = "AZ\nSX\nAZ\nDC\nAB\nYZ\n"; say $lines; $lines =~ s/(?>[^A].|.[^Z])\n//gm; say $lines; ' AZ SX AZ DC AB YZ AZ AZ

    In my opinion, the multiline solution is a lot more cryptic than the array solution.

    -- Ken

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1029395]
help
Chatterbox?
[LanX]: moritz, no ... jsut copy one line of my code
[moritz]: I'm still using the CB, because ambrus's #cbstream makes it bearable
[LanX]: ... the rest is loaded from a node
[holli]: the best course of action would be to transfer the data to something well tested. even if it isnt perl based
[moritz]: but even if I had all the time in the world, I wouldn't spend much on perlmonks
[LanX]: holli: LOL
[LanX]: moritz: why ? family?
[LanX]: or other language?
[moritz]: LanX because of usability issues, and the lack of evolvement
[holli]: lol to the robust charme or to the data transfer?

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (12)
As of 2017-11-20 19:24 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    In order to be able to say "I know Perl", you must have:













    Results (291 votes). Check out past polls.

    Notices?