On Wed, 21 Nov 2012 17:48:00 -0500
shawn wilson <ag4ve...@gmail.com> wrote:

> how do i return something when i've got a long regex and one of the
> captures is empty?
> 
> $_ = '"435" "" "634";
> my ($one, $two, $three)= /^
>    "(\d+)"\
>    "(\d+)"\
>    "(\d+)"
> /x;
> 

First, this contains a syntax error. Please test your code before you
post.

Try:

$_ = '"435" "" "634"';

my $capture_inside_dq = qr/ \" ( [^"]* )\" /x;
my ( $one, $two, $three ) = / \A $capture_inside_dq \s
$capture_inside_dq \s $capture_inside_dq \z /x;

print "one   = '$one'\n";
print "two   = '$two'\n";
print "three = '$three'\n";


-- 
Just my 0.00000002 million dollars worth,
        Shawn

Programming is as much about organization and communication
as it is about coding.

Why fit in when you can stand out?
        Dr. Seuss

The only way that problems get solved in real life is with a lot of
hard work on getting the details right.
        Linus Torvalds

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to