Re: split delimiters query
On Wed, 02 Feb 2005 20:37:54 +, mike [EMAIL PROTECTED] wrote: No the problem was that this ( with the quote in the right place) was giving me what I didnt want. this is the code @value=param(); shift (@value); shift (@value); pop (@value); print @value; foreach $value (@value){ $value1=substr($value,0,9); if ($value1 eq work_emai){ push (@value2,param($value)); push (@value2,\t); #print $value2; } else { push (@value2,param($value)); push (@value2,'##'); #print param($value) } } $value4=join('',@value2); print br,value4,$value4,br; @array3=split(/\t/,$value4); @[EMAIL PROTECTED]; with \t the \t was being inserted into a db field, without it everything was hunky dory You asked, though, if adding quotes changed the behavior of split. It does not. What you did was change the regex. Adding the quotes didn't mean that split suddenly kept the final delimeter, it meant that you were no longer splitting on what you thought you were splitting on /\t/ looks for a \t and then a . Splitting on /\t/ looks of a \t. Since join only inserts delimeters between items and not after the final item, your final value ended with \t instead of \t; split didn't know it was a delimeter. You'll notice the way you're doing things now, all the values joined by join, except the first, still have a at the beginning. Split behaves exactly as predicted in both cases: it removes exactly and only what you ask it to. What you're really looking for is probably: $value4 =~ s/\t$//; @array3 = split(/\t/, $value4); HTH, --jay -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
split delimiters query
Am I right in thinking that if you double quote the seperator in split the seperator is added to the array ie: @array3=split(/\t/,$value4); would add \t to the end of @array3 while @array3=split(/\t/,$value4); would not -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: split delimiters query
mike wrote: Am I right in thinking that if you double quote the seperator in split the seperator is added to the array ie: @array3=split(/\t/,$value4); would add \t to the end of @array3 while As you have written it above I get a syntax error: String found where operator expected at ./test.pl line 12, at end of line (Missing semicolon on previous line?) Can't find string terminator '' anywhere before EOF at ./test.pl line 12. If you meant, C/\t/ then I still don't think you will get what you want. Csplit just isn't that smart. @array3=split(/\t/,$value4); would not What are you really trying to do? http://danconia.org -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: split delimiters query
On Wed, 02 Feb 2005 12:39:17 +, mike [EMAIL PROTECTED] wrote: Am I right in thinking that if you double quote the seperator in split the seperator is added to the array ie: @array3=split(/\t/,$value4); would add \t to the end of @array3 while @array3=split(/\t/,$value4); would not I think we need a little more information here, maybe a sample value for $value4. Split, though, doesn't add anything; it removes the delimiter. If you have: $value4 = one\ttwo\tthree\tfour\tfive ; @array3=split(/\t/, $value4) ; returns @array3 = [one, two, three, four, five] The delimiter is never included in the returned data. If you questions is really what happens when there is a trailing delimiter, or an empty field in the data?, the answer is, trailing delimiters are ignored, otherwise empty strings are returned. So if $value4 = \tone\t\ttwo\tthree\t\tfour\tfive\t ; then @array3 = [, one, , two, three, , four, five] If you need some other behavior, you need to constuct a more complex regex for split, but simple adding quotes doesn't change the behavior. HTH, --jay -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: split delimiters query
On Wed, 2005-02-02 at 12:54 -0500, Jay wrote: On Wed, 02 Feb 2005 12:39:17 +, mike [EMAIL PROTECTED] wrote: Am I right in thinking that if you double quote the seperator in split the seperator is added to the array ie: @array3=split(/\t/,$value4); would add \t to the end of @array3 while @array3=split(/\t/,$value4); would not I think we need a little more information here, maybe a sample value for $value4. Split, though, doesn't add anything; it removes the delimiter. If you have: $value4 = one\ttwo\tthree\tfour\tfive ; @array3=split(/\t/, $value4) ; returns @array3 = [one, two, three, four, five] The delimiter is never included in the returned data. If you questions is really what happens when there is a trailing delimiter, or an empty field in the data?, the answer is, trailing delimiters are ignored, otherwise empty strings are returned. So if $value4 = \tone\t\ttwo\tthree\t\tfour\tfive\t ; then @array3 = [, one, , two, three, , four, five] If you need some other behavior, you need to constuct a more complex regex for split, but simple adding quotes doesn't change the behavior. HTH, afraid it did in my case (screwed up a dba query, which is how I noticed) the code without quoting the delimiter works with no further changes, this is on a fc3 box --jay -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: split delimiters query
On Wed, 2005-02-02 at 09:23 -0500, Wiggins d'Anconia wrote: mike wrote: Am I right in thinking that if you double quote the seperator in split the seperator is added to the array ie: @array3=split(/\t/,$value4); would add \t to the end of @array3 while As you have written it above I get a syntax error: String found where operator expected at ./test.pl line 12, at end of line (Missing semicolon on previous line?) Can't find string terminator '' anywhere before EOF at ./test.pl line 12. If you meant, C/\t/ then I still don't think you will get what you want. Csplit just isn't that smart. No the problem was that this ( with the quote in the right place) was giving me what I didnt want. this is the code @value=param(); shift (@value); shift (@value); pop (@value); print @value; foreach $value (@value){ $value1=substr($value,0,9); if ($value1 eq work_emai){ push (@value2,param($value)); push (@value2,\t); #print $value2; } else { push (@value2,param($value)); push (@value2,'##'); #print param($value) } } $value4=join('',@value2); print br,value4,$value4,br; @array3=split(/\t/,$value4); @[EMAIL PROTECTED]; with \t the \t was being inserted into a db field, without it everything was hunky dory @array3=split(/\t/,$value4); would not What are you really trying to do? http://danconia.org -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response