Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re: Parsing arguments with surrounding garbage.

by kilinrax (Deacon)
on Apr 04, 2001 at 18:53 UTC ( [id://69685]=note: print w/replies, xml ) Need Help??


in reply to Parsing arguments with surrounding garbage.

Since you want "1234 221", not "1234", which is what that regex will capture, and you really want to be using match, not substitute, I'd suggest this:
#!/usr/bin/perl -w use strict; my @args; my $string="garbage validcommand 1234 221 garbage 999 213"; while ($string =~ m!validcommand\s+(\d+(?:\s+\d+)*)!g) { push(@args, $1); } print @args;

Replies are listed 'Best First'.
Re: Re: Parsing arguments with surrounding garbage.
by kschwab (Vicar) on Apr 04, 2001 at 19:14 UTC
    Thanks, I was looking for a match instead of a substitute, so this and the other replies were helpful.

    A note on your comment:

    Since you want "1234 221", not "1234", which is what that regex will capture

    The code I posted does work (because it takes n trips through the while() loop), and pulls in both 1234 and 221 into @args. It's just uglier than I wanted.

    Thanks all !

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others musing on the Monastery: (3)
As of 2024-04-26 07:12 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found