Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re: using regular expression to extract subset from a line

by DamnDirtyApe (Curate)
on Dec 30, 2004 at 19:54 UTC ( [id://418369]=note: print w/replies, xml ) Need Help??


in reply to using regular expression to extract subset from a line

I'll leave the analysis of what you've got to someone who's better at regexps than I, but if you're simply looking to extract the argument from a space-delimited string that ends in "makefile", try something simpler like this:

#! /usr/bin/perl -w use strict; my $old_str = 'make -r -f ..\../tools/cell/makefile cell.lib'; my $new_str = ( $old_str =~ /\s+(\S*makefile)/ )[0]; print "New string: $new_str$/"; __END__

HTH

Update: You could do this with split and grep also:

my $new_str = ( grep { /makefile$/ } split /\s+/, $old_str )[0];

_______________
DamnDirtyApe
Those who know that they are profound strive for clarity. Those who
would like to seem profound to the crowd strive for obscurity.
            --Friedrich Nietzsche

Log In?
Username:
Password:

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

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

    No recent polls found