regular expression
hi all, i am working to split the data in my array as follows but ended up clueless, hoope some of u can help. @text # contains values of a phone directory $text[0] contains john=012345678 $phone1 = ? let say i wanted to grab just the values'012345678'. how should i go on truncating the values? kindly advice pls. thanks! _ Get your FREE download of MSN Explorer at http://explorer.msn.com/intl.asp. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
truncating carrier return character(s)
It seems that when i am working with network programming, the input from the client will contain carrier return characters which the server interpreted as 2 carrier-return, how do i truncate the end carrier return characters? kindly advice... ... thanks! _ Chat with friends online, try MSN Messenger: http://messenger.msn.com -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: regular expression
Hey Chaoz, code #!/usr/bin/perl use strict; open(FILE,'file.txt') or die Can't open file.txt: $!\n; my @text=(FILE); close(FILE); for(@text) { /(d+)$/; # Match only the numbers at the end of the string # and store them in '$1' to be printed out on the # next line followed by a new line character print $1,\n; } exit; /code shawn - Original Message - From: ChaoZ InferNo [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Friday, May 17, 2002 4:01 AM Subject: regular expression hi all, i am working to split the data in my array as follows but ended up clueless, hoope some of u can help. @text # contains values of a phone directory $text[0] contains john=012345678 $phone1 = ? let say i wanted to grab just the values'012345678'. how should i go on truncating the values? kindly advice pls. thanks! _ Get your FREE download of MSN Explorer at http://explorer.msn.com/intl.asp. -- 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: regular expression
code for(@text) { /(d+)$/; # Match only the numbers at the end of the string ^^ this should actually be (\d+) I would actually conditionally print also, like so: print $1 if /(\d+)$/; And depending on the size of the file, instead of reading the whole thing into memory with my @text = (FILE); I would do: while(FILE) { print $1 if /(\d+)$/; } # and store them in '$1' to be printed out on the # next line followed by a new line character @text # contains values of a phone directory $text[0] contains john=012345678 $phone1 = ? let say i wanted to grab just the values'012345678'. how should i go on truncating the values? Cheers, -dave -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: regular expression
ChaoZ InferNo wrote: @text # contains values of a phone directory $text[0] contains john=012345678 $phone1 = ? let say i wanted to grab just the values'012345678'. if the format of $text[0] is always name=number you can use split instead of a regex. perldoc -f split -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: regular expression
Regular expressions are overkill for what you're trying to do. It seems like using 'split' should do exactly what you need. #!/usr/bin/perl -W use strict; open(IN,/path/to/file) or die Could not open file; my @list = IN; close(IN); for(@list) { chomp; my($field,$value) = split(/=/,$_); # split each line on '=' print Your $field is $value. \n; } Scot Robnett inSite Internet Solutions [EMAIL PROTECTED] [EMAIL PROTECTED] -Original Message- From: ChaoZ Inferno [mailto:[EMAIL PROTECTED]] Sent: Friday, May 17, 2002 11:38 AM To: [EMAIL PROTECTED] Subject: Re: regular expression Actually, the content of the file looks something like:- name=john id=12345 password=12345 colour=blue I am trying to grab the value field of each line and assigned it to be a variable. I tried the regular expressions, but seems like the syntax is wrong or something, @file = filehandle; #small file anyway $file[0] is equal to 'name=john' but i just wanna extract john to be my scalar variable. like print $name but returns john only and the same extraction method for the rest of the other 3 fields as well. kindly advice!... million thanks! - Original Message - From: David Gray [EMAIL PROTECTED] To: [EMAIL PROTECTED] Cc: 'ChaoZ InferNo' [EMAIL PROTECTED]; 'Shawn' [EMAIL PROTECTED] Sent: Friday, May 17, 2002 10:16 PM Subject: RE: regular expression code ... for(@text) { /(d+)$/; # Match only the numbers at the end of the string ^^ this should actually be (\d+) I would actually conditionally print also, like so: print $1 if /(\d+)$/; And depending on the size of the file, instead of reading the whole thing into memory with my @text = (FILE); I would do: while(FILE) { print $1 if /(\d+)$/; } # and store them in '$1' to be printed out on the # next line followed by a new line character ... @text # contains values of a phone directory $text[0] contains john=012345678 $phone1 = ? let say i wanted to grab just the values'012345678'. how should i go on truncating the values? Cheers, -dave -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] --- Incoming mail is certified Virus Free. Checked by AVG anti-virus system (http://www.grisoft.com). Version: 6.0.351 / Virus Database: 197 - Release Date: 4/19/2002 --- Outgoing mail is certified Virus Free. Checked by AVG anti-virus system (http://www.grisoft.com). Version: 6.0.351 / Virus Database: 197 - Release Date: 4/19/2002 -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: regular expression
Ok, first, thanks for the correction and input David... I agree 100% with what you say. Secondly, am I just crazy, or doesn't split USE regex? Since this is the second mention the regex is overkill, and that split will work, I am a bit confused... When you can say $var=split(/=|:/); it tells me this IS a regex... hence the '//'s. So how exactly is this any less overkill (powerful) than a regex? shawn - Original Message - From: Scot Robnett [EMAIL PROTECTED] To: ChaoZ Inferno [EMAIL PROTECTED]; [EMAIL PROTECTED] Sent: Friday, May 17, 2002 9:52 AM Subject: RE: regular expression Regular expressions are overkill for what you're trying to do. It seems like using 'split' should do exactly what you need. #!/usr/bin/perl -W use strict; open(IN,/path/to/file) or die Could not open file; my @list = IN; close(IN); for(@list) { chomp; my($field,$value) = split(/=/,$_); # split each line on '=' print Your $field is $value. \n; } Scot Robnett inSite Internet Solutions [EMAIL PROTECTED] [EMAIL PROTECTED] -Original Message- From: ChaoZ Inferno [mailto:[EMAIL PROTECTED]] Sent: Friday, May 17, 2002 11:38 AM To: [EMAIL PROTECTED] Subject: Re: regular expression Actually, the content of the file looks something like:- name=john id=12345 password=12345 colour=blue I am trying to grab the value field of each line and assigned it to be a variable. I tried the regular expressions, but seems like the syntax is wrong or something, @file = filehandle; #small file anyway $file[0] is equal to 'name=john' but i just wanna extract john to be my scalar variable. like print $name but returns john only and the same extraction method for the rest of the other 3 fields as well. kindly advice!... million thanks! - Original Message - From: David Gray [EMAIL PROTECTED] To: [EMAIL PROTECTED] Cc: 'ChaoZ InferNo' [EMAIL PROTECTED]; 'Shawn' [EMAIL PROTECTED] Sent: Friday, May 17, 2002 10:16 PM Subject: RE: regular expression code ... for(@text) { /(d+)$/; # Match only the numbers at the end of the string ^^ this should actually be (\d+) I would actually conditionally print also, like so: print $1 if /(\d+)$/; And depending on the size of the file, instead of reading the whole thing into memory with my @text = (FILE); I would do: while(FILE) { print $1 if /(\d+)$/; } # and store them in '$1' to be printed out on the # next line followed by a new line character ... @text # contains values of a phone directory $text[0] contains john=012345678 $phone1 = ? let say i wanted to grab just the values'012345678'. how should i go on truncating the values? Cheers, -dave -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] --- Incoming mail is certified Virus Free. Checked by AVG anti-virus system (http://www.grisoft.com). Version: 6.0.351 / Virus Database: 197 - Release Date: 4/19/2002 --- Outgoing mail is certified Virus Free. Checked by AVG anti-virus system (http://www.grisoft.com). Version: 6.0.351 / Virus Database: 197 - Release Date: 4/19/2002 -- 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: regular expression vs split
Curious, but I've always thought that regex was much quicker then split for situations such as this... I'd always figured that split was basically a (and the regex for this is probably wrong, but you can get the jist of it) /[^($delimiter | end of string)/ with a dumping of the match minus the delimiter... I'm guessing what was meant is that regex is more work then using a split, but it doesn't particularly seem like a huge amount of extra work using regex... any comments/thoughts? ~Brian Regular expressions are overkill for what you're trying to do. It seems like using 'split' should do exactly what you need. #!/usr/bin/perl -W use strict; open(IN,/path/to/file) or die Could not open file; my @list = IN; close(IN); for(@list) { chomp; my($field,$value) = split(/=/,$_); # split each line on '=' print Your $field is $value. \n; } Scot Robnett inSite Internet Solutions [EMAIL PROTECTED] [EMAIL PROTECTED] -Original Message- From: ChaoZ Inferno [mailto:[EMAIL PROTECTED]] Sent: Friday, May 17, 2002 11:38 AM To: [EMAIL PROTECTED] Subject: Re: regular expression Actually, the content of the file looks something like:- name=john id=12345 password=12345 colour=blue I am trying to grab the value field of each line and assigned it to be a variable. I tried the regular expressions, but seems like the syntax is wrong or something, @file = filehandle; #small file anyway $file[0] is equal to 'name=john' but i just wanna extract john to be my scalar variable. like print $name but returns john only and the same extraction method for the rest of the other 3 fields as well. kindly advice!... million thanks! - Original Message - From: David Gray [EMAIL PROTECTED] To: [EMAIL PROTECTED] Cc: 'ChaoZ InferNo' [EMAIL PROTECTED]; 'Shawn' [EMAIL PROTECTED] Sent: Friday, May 17, 2002 10:16 PM Subject: RE: regular expression code ... for(@text) { /(d+)$/; # Match only the numbers at the end of the string ^^ this should actually be (\d+) I would actually conditionally print also, like so: print $1 if /(\d+)$/; And depending on the size of the file, instead of reading the whole thing into memory with my @text = (FILE); I would do: while(FILE) { print $1 if /(\d+)$/; } # and store them in '$1' to be printed out on the # next line followed by a new line character ... @text # contains values of a phone directory $text[0] contains john=012345678 $phone1 = ? let say i wanted to grab just the values'012345678'. how should i go on truncating the values? Cheers, -dave -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] --- Incoming mail is certified Virus Free. Checked by AVG anti-virus system (http://www.grisoft.com). Version: 6.0.351 / Virus Database: 197 - Release Date: 4/19/2002 --- Outgoing mail is certified Virus Free. Checked by AVG anti-virus system (http://www.grisoft.com). Version: 6.0.351 / Virus Database: 197 - Release Date: 4/19/2002 -- 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: regular expression
Actually, the content of the file looks something like:- name=john id=12345 password=12345 colour=blue Ok, how about this then... This is based on the fact that name, id, password, colour appear for every record whether they have a value or not, and that none of the values after the '=' will have an '=' in them. code #!/usr/bin/perl use strict; my(@name,@id,@password,@colour); open(FILE,'file.txt') or die Can't open file.txt: $!\n; my @text=(FILE); close(FILE); for(@text) { s/.*=//; } for(my $x=0; $x $#text; $x+4;) { push @name, $text[$x]; push @id, $text[$x+1]; push @passowrd, $text[$x+2]; push @colour, $text[$x+3]; } for(@name) { print if($_); } exit; /code It is still way too early, so if you catch any errors, let me know David (or anyone else for that matter) :-) shawn -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: regular expression
...it certainly looks like a regex to me -Original Message- From: Shawn [mailto:[EMAIL PROTECTED]] Sent: 17 May 2002 16:03 To: Scot Robnett; ChaoZ Inferno; [EMAIL PROTECTED] Subject: Re: regular expression Ok, first, thanks for the correction and input David... I agree 100% with what you say. Secondly, am I just crazy, or doesn't split USE regex? Since this is the second mention the regex is overkill, and that split will work, I am a bit confused... When you can say $var=split(/=|:/); it tells me this IS a regex... hence the '//'s. So how exactly is this any less overkill (powerful) than a regex? shawn - Original Message - From: Scot Robnett [EMAIL PROTECTED] To: ChaoZ Inferno [EMAIL PROTECTED]; [EMAIL PROTECTED] Sent: Friday, May 17, 2002 9:52 AM Subject: RE: regular expression Regular expressions are overkill for what you're trying to do. It seems like using 'split' should do exactly what you need. #!/usr/bin/perl -W use strict; open(IN,/path/to/file) or die Could not open file; my @list = IN; close(IN); for(@list) { chomp; my($field,$value) = split(/=/,$_); # split each line on '=' print Your $field is $value. \n; } Scot Robnett inSite Internet Solutions [EMAIL PROTECTED] [EMAIL PROTECTED] -Original Message- From: ChaoZ Inferno [mailto:[EMAIL PROTECTED]] Sent: Friday, May 17, 2002 11:38 AM To: [EMAIL PROTECTED] Subject: Re: regular expression Actually, the content of the file looks something like:- name=john id=12345 password=12345 colour=blue I am trying to grab the value field of each line and assigned it to be a variable. I tried the regular expressions, but seems like the syntax is wrong or something, @file = filehandle; #small file anyway $file[0] is equal to 'name=john' but i just wanna extract john to be my scalar variable. like print $name but returns john only and the same extraction method for the rest of the other 3 fields as well. kindly advice!... million thanks! - Original Message - From: David Gray [EMAIL PROTECTED] To: [EMAIL PROTECTED] Cc: 'ChaoZ InferNo' [EMAIL PROTECTED]; 'Shawn' [EMAIL PROTECTED] Sent: Friday, May 17, 2002 10:16 PM Subject: RE: regular expression code ... for(@text) { /(d+)$/; # Match only the numbers at the end of the string ^^ this should actually be (\d+) I would actually conditionally print also, like so: print $1 if /(\d+)$/; And depending on the size of the file, instead of reading the whole thing into memory with my @text = (FILE); I would do: while(FILE) { print $1 if /(\d+)$/; } # and store them in '$1' to be printed out on the # next line followed by a new line character ... @text # contains values of a phone directory $text[0] contains john=012345678 $phone1 = ? let say i wanted to grab just the values'012345678'. how should i go on truncating the values? Cheers, -dave -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] --- Incoming mail is certified Virus Free. Checked by AVG anti-virus system (http://www.grisoft.com). Version: 6.0.351 / Virus Database: 197 - Release Date: 4/19/2002 --- Outgoing mail is certified Virus Free. Checked by AVG anti-virus system (http://www.grisoft.com). Version: 6.0.351 / Virus Database: 197 - Release Date: 4/19/2002 -- 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] -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: regular expression vs split
I don't believe that a regex would be faster in an instance like this, but someone please correct me if I'm wrong. It seems that it would add (albeit a very minimal amount) processing overhead to apply a regular expression to each line rather than using the built-in split function on it, depending on the complexity of the regex. In this case it doesn't seem that complicated, so maybe we're just talking semantics. TMTOWTDI. Regarding split being a regex, well...split is a function, but it basically uses a regex to do its whizbangery, if that's what you mean. Scot Robnett inSite Internet Solutions [EMAIL PROTECTED] [EMAIL PROTECTED] -Original Message- From: Brian [mailto:[EMAIL PROTECTED]] Sent: Friday, May 17, 2002 10:17 AM To: [EMAIL PROTECTED] Subject: RE: regular expression vs split Curious, but I've always thought that regex was much quicker then split for situations such as this... I'd always figured that split was basically a (and the regex for this is probably wrong, but you can get the jist of it) /[^($delimiter | end of string)/ with a dumping of the match minus the delimiter... I'm guessing what was meant is that regex is more work then using a split, but it doesn't particularly seem like a huge amount of extra work using regex... any comments/thoughts? ~Brian Regular expressions are overkill for what you're trying to do. It seems like using 'split' should do exactly what you need. #!/usr/bin/perl -W use strict; open(IN,/path/to/file) or die Could not open file; my @list = IN; close(IN); for(@list) { chomp; my($field,$value) = split(/=/,$_); # split each line on '=' print Your $field is $value. \n; } Scot Robnett inSite Internet Solutions [EMAIL PROTECTED] [EMAIL PROTECTED] -Original Message- From: ChaoZ Inferno [mailto:[EMAIL PROTECTED]] Sent: Friday, May 17, 2002 11:38 AM To: [EMAIL PROTECTED] Subject: Re: regular expression Actually, the content of the file looks something like:- name=john id=12345 password=12345 colour=blue I am trying to grab the value field of each line and assigned it to be a variable. I tried the regular expressions, but seems like the syntax is wrong or something, @file = filehandle; #small file anyway $file[0] is equal to 'name=john' but i just wanna extract john to be my scalar variable. like print $name but returns john only and the same extraction method for the rest of the other 3 fields as well. kindly advice!... million thanks! - Original Message - From: David Gray [EMAIL PROTECTED] To: [EMAIL PROTECTED] Cc: 'ChaoZ InferNo' [EMAIL PROTECTED]; 'Shawn' [EMAIL PROTECTED] Sent: Friday, May 17, 2002 10:16 PM Subject: RE: regular expression code ... for(@text) { /(d+)$/; # Match only the numbers at the end of the string ^^ this should actually be (\d+) I would actually conditionally print also, like so: print $1 if /(\d+)$/; And depending on the size of the file, instead of reading the whole thing into memory with my @text = (FILE); I would do: while(FILE) { print $1 if /(\d+)$/; } # and store them in '$1' to be printed out on the # next line followed by a new line character ... @text # contains values of a phone directory $text[0] contains john=012345678 $phone1 = ? let say i wanted to grab just the values'012345678'. how should i go on truncating the values? Cheers, -dave -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] --- Incoming mail is certified Virus Free. Checked by AVG anti-virus system (http://www.grisoft.com). Version: 6.0.351 / Virus Database: 197 - Release Date: 4/19/2002 --- Outgoing mail is certified Virus Free. Checked by AVG anti-virus system (http://www.grisoft.com). Version: 6.0.351 / Virus Database: 197 - Release Date: 4/19/2002 -- 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] --- Incoming mail is certified Virus Free. Checked by AVG anti-virus system (http://www.grisoft.com). Version: 6.0.351 / Virus Database: 197 - Release Date: 4/19/2002 --- Outgoing mail is certified Virus Free. Checked by AVG anti-virus system (http://www.grisoft.com). Version: 6.0.351 / Virus Database: 197 - Release Date: 4/19/2002 -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: regular expression
I just happened to write exactly this the other day, as a generic configuration file reader. Here's the basics: sub readINI {# argument: filename my %params; open( INIFILE, $_[0] ) || die Could not open $_[0]\n; while(INIFILE) { if(! /^#/ ) { # Allow comments chomp; $params{$`} = $' if( /=/ ); } } return %params; } What you get back is a hash of key/value pairs. In your case, $myhash{name} = 'john', $myhash{id} = '12345', etc. You can even comment a line out by putting a # in the first position (or by not having an = anywhere in the line). The only slightly obscure thing here is the use of $` and $' to mean everything before the match and everything after the match, to save you having to explicitely capture those sections with parens. FYI, more detail on your initial question would have allowed us to cut to the chase faster. - John --- ChaoZ Inferno [EMAIL PROTECTED] wrote: Actually, the content of the file looks something like:- name=john id=12345 password=12345 colour=blue I am trying to grab the value field of each line and assigned it to be a variable. ... = When you're following an angel, does it mean you have to throw your body off a building? - They Might Be Giants, http://www.tmbg.com Word of the week: Serendipity, see http://www.bartleby.com/61/93/S0279300.html __ Do You Yahoo!? LAUNCH - Your Yahoo! Music Experience http://launch.yahoo.com -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
What's up with CPAN?
Anybody else having trouble reaching search.cpan.org or wait.cpan.org today? I can get to the main site, but I can't get to module documentation. Scot R. --- Outgoing mail is certified Virus Free. Checked by AVG anti-virus system (http://www.grisoft.com). Version: 6.0.351 / Virus Database: 197 - Release Date: 4/19/2002 -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Send mail question
On Fri, 10 May 2002, fliptop wrote: Lance Prais wrote: If I am going to sendmail from an Internet using CGI does anyone know all the modules I will need to install? This may answer all my questions. i use mime::lite and it works great and is simple to use. Ditto. -- Eric P. Los Gatos, CA -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]