Gregory Machin wrote:
> Hi
> I'm writing a script to pass a config file and put the values in a hash,
> with the key being the directive and the value bing the options,
> but some directives don't have options, so in that case i want to store the
> directive as the value so that for completeness..
> 
> i'm using the follwing regex /(.+)[\s+\n](.+)/    where $1 is the directive
> and $2 is the option for the directive
> 
> user nobody
> group nobody
> persist-key
> persist-tun
> 
> this is the logic that is suposed to do the work.
> if ($_ =~ /^persist-key/){ /(.+)[\s+\n](.+)/ ; if ( $2 == '' ) { $_ = $1} ;

The contents of $2 is undef if the match fails. Try:
  { /(.+)\s+(.+)/; $_ = $1 unless $2; }


> $directive{persist_key} = $_; }
> 
> but I still end up with an empty field ...
> 
> Any ideas..
> 
> 


-- 
__END__

Just my 0.00000002 million dollars worth,
   --- Shawn

"For the things we have to learn before we can do them, we learn by
doing them."
  Aristotle

* Perl tutorials at http://perlmonks.org/?node=Tutorials
* A searchable perldoc is at http://perldoc.perl.org/

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to