RE: excluding comments in a line
That's the ticket! thanxs.. not up to par on regex yet.. I had to modify a module I got from cpan to remove the comments.. the darn thing just check for spaces and comments at beginning of line :( -Ron > -Original Message- > From: Frank [mailto:[EMAIL PROTECTED]] > Sent: Monday, January 14, 2002 12:53 > To: Beginners (E-mail) > Subject: Re: excluding comments in a line > > > On Mon, Jan 14, 2002 at 12:44:34PM -0500, Yacketta, wrote: > > Folks, > > > > I am reading in a .cfg file and exclude comments (#) and > spaces at the > > beginning of the line > > how would I lop off any comments in a line? > > > > IE: > > > > Key "value" # comment here > ---end quoted text--- > > while(){ > next if /^\s*(#.*)?$/; # Skip it if just comment or blank > s/#.*$//; # remove comments > ($key,$value)=split/\s+/,$_,2; # Get exactly two values out > $config{$key}=$value; # Load into a hash for use. > } > > -- > Frank Booth - Consultant > Parasol Solutions Limited. > (www.parasolsolutions.com) > > -- > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: excluding comments in a line
On Mon, Jan 14, 2002 at 12:44:34PM -0500, Yacketta, wrote: > Folks, > > I am reading in a .cfg file and exclude comments (#) and spaces at the > beginning of the line > how would I lop off any comments in a line? > > IE: > > Key "value" # comment here ---end quoted text--- while(){ next if /^\s*(#.*)?$/; # Skip it if just comment or blank s/#.*$//; # remove comments ($key,$value)=split/\s+/,$_,2; # Get exactly two values out $config{$key}=$value; # Load into a hash for use. } -- Frank Booth - Consultant Parasol Solutions Limited. (www.parasolsolutions.com) -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: excluding comments in a line
How about splitting the line. @lines = ("foo=bar # stuff", "bar=foo # more stuff"); foreach (@lines) { my ($line) = split(/\s*#/); print "$line\n"; } John -Original Message- From: Yacketta, Ronald [mailto:[EMAIL PROTECTED]] Sent: 14 January 2002 17:45 To: Beginners (E-mail) Subject: excluding comments in a line Folks, I am reading in a .cfg file and exclude comments (#) and spaces at the beginning of the line how would I lop off any comments in a line? IE: Key "value" # comment here Regards, Ron -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] --Confidentiality--. This E-mail is confidential. It should not be read, copied, disclosed or used by any person other than the intended recipient. Unauthorised use, disclosure or copying by whatever medium is strictly prohibited and may be unlawful. If you have received this E-mail in error please contact the sender immediately and delete the E-mail from your system. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]