princepawn has asked for the wisdom of the Perl Monks concerning the following question:
I wrote the following Perl code to get the value part of the string (the part after the equal sign) using regexes even though split is easier so that I could practice my regexes. Here is my code, yet it does not work (in other words, printing $1 yields an empty string). So it is matching, but $1 is not bound. My regex is saying:azxinetgw.EXECFILE_DIR.azxinetgw='/usr/local/instinet/RTS/etc/local/az +xfiles'
sub get_assigned_dir { my $gpa_key = shift; my $gpa_ret = `$gpa $gpa_key`; warn $gpa_ret; if ( $gpa_ret =~ /[^=]+[=][']([^']+)[']/ ) { my $assigned_dir = $1 } else { die "couldn't determine assigned directory for $ +gpa_key" } log_msg "assigned dir for $gpa_key == $assigned_dir"; }
$string = 'aaaaa'; print $1,$/ if $string =~ /(a)+/; print $1,$/ if $string =~ /(a+)/;
|
|---|