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

Re: Last Letters

by kilinrax (Deacon)
on Nov 30, 2000 at 00:22 UTC ( [id://43994]=note: print w/replies, xml ) Need Help??


in reply to Last Letters

Try using a regular expression:
#!/usr/bin/perl -w use strict; my @data = qw|pa0002Yeadon.2(5091) pa0003Presidential.1(2664) pa0014Haverford.1(2589)|; my @numbers = map { /\((\d+)\)/ } @data; print "@numbers\n";

Replies are listed 'Best First'.
Re: Re: Last Letters
by arturo (Vicar) on Nov 30, 2000 at 00:28 UTC

    Dang, beat me to it =) I note, for the record, that killinrax's solution which is elegant, assumes you know that the first thing in your lines of data that are going to be wrapped in parentheses are the numbers you seek, AND that every line will contain a number (which may or may not be a problem; but if you want to do 1:1 matching of numbers onto lines, you'd like to know which line is missing a number if the sizes of @numbers and @data don't match up.)

    In other words: it's a great basic technique, but be careful how you implement it!

    Philosophy can be made out of anything. Or less -- Jerry A. Fodor

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others sharing their wisdom with the Monastery: (4)
As of 2024-04-26 00:15 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found