extracting word from line 
Author Message
 extracting word from line

I'm a Perl neophyte and would like some advice.

I have a string;

$_="process 3657 and `object.o' successful last Friday"

and would like to extract "object.o".

Here's some code I wrote, any suggestions for this Perl student?

print "$array2[0]\n";

--

Core Research and Development           SAS Campus Dr, Cary, NC
(919) 677-8000 x6875                    27513-2414 USA



Mon, 13 Mar 1995 05:13:35 GMT  
 extracting word from line

Quote:

>I'm a Perl neophyte and would like some advice.

>I have a string;

>$_="process 3657 and `object.o' successful last Friday"

>and would like to extract "object.o".

>Here's some code I wrote, any suggestions for this Perl student?



>print "$array2[0]\n";

Hi,
You could use

        $_="process 3657 and `object.o' successful last Friday";
        /(`.*')/  && print "$1\n";
or
        print "$1\n" if /(`.*')/;

Cheers,
Joel
--
     ==================================================================
     ||               T E C H N E   R E S E A R C H                  ||
     ||  ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++  ||
     ||                     Joel Rosi-Schwartz                       ||

     ||   12 Waverley Way            +    (pyrltd!abigale.UUCP!joel) ||
     ||   Finchampstead, Wokingham   +   Phone: +44 (734) 730.260    ||
     ||   Berkshire RG11 4YD (UK)    +   Fax:   +44 (734) 730.272    ||
     ==================================================================



Mon, 13 Mar 1995 16:55:42 GMT  
 extracting word from line

Quote:

>I'm a Perl neophyte and would like some advice.
>I have a string;
>$_="process 3657 and `object.o' successful last Friday"
>and would like to extract "object.o".

The easiest way I can see to do this is to write:

   ($match)=/(`.*')/;

Hope this helps,

Quote:

>Core Research and Development               SAS Campus Dr, Cary, NC
>(919) 677-8000 x6875                        27513-2414 USA

John

--
-------------------------------------------------------------------------------


UUCP     : {...|mcsun}|uknet|rlinf|jjsc          ||   Informatics Department
X.400    : /S=jjsc/OU=informatics/O=rutherford   ||   Rutherford Appleton Lab.
           /PRMD=UK.AC/ADMD= /C=GB/              ||   Chilton, Didcot,
VOICE    : +44 (0)235 44 6555 (Direct line)      ||   Oxon OX11 0QX.
-------------------------------------------------------------------------------



Tue, 14 Mar 1995 17:08:35 GMT  
 extracting word from line

: >I'm a Perl neophyte and would like some advice.
: >I have a string;
: >$_="process 3657 and `object.o' successful last Friday"
: >and would like to extract "object.o".
:
: The easiest way I can see to do this is to write:
:
:    ($match)=/(`.*')/;

That includes the quotes, and could be a wee bit more efficient at
the expense of a bit of readability:

        ($match) = /`([^']*)'/;

Actually, that final ' doesn't have to be there, since [^']* will match
up to it anyway.

Larry



Wed, 15 Mar 1995 05:18:05 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. Extract last word on line

2. Extract the nth word from a line

3. How to: Create Regex which extracts N number of words before target word

4. problem about extract line by line from file

5. Searching a WORD 6 DOC by line line number

6. Extracting a range of words!

7. Extracting Word from Variable

8. extract the first word in a string

9. Extracting information from Word 7.0 documents.

10. Help please extracting data from a word document

11. Extracting an index from a MS Word 97 doc

12. Extracting n-grams and words that contain them

 

 
Powered by phpBB® Forum Software