Re: regex question

2001-06-16 Thread Hasanuddin Tamir

On Fri, 15 Jun 2001, Robert Watterson [EMAIL PROTECTED] wrote,

 Hi all,

  I have a line that has each field separated by commas. However, some of
 individual fields are double quoted strings and also have embedded commas in
 them. for example:

 Value1,Value2, blah,blah,blah,Value3,Value4,blah,Value5

 When I use the split function using the split pattern of /,/ it obviously
 doesn't work.

 I believe what I want is to split on all commas when they are not followed by
 anything, then a double quote , then another comma.

 This seems like it should be a simple string to split into array values, but I
 just can't seem to get it to work.
 Anybody have any suggestions?

use Text::ParseWords;

{
from perlfaq4:
How can I split a [character] delimited string except
when inside [character]? (Comma-separated files)
}

__END__
-- 
s::a::n-http(www.trabas.com)




Re: How to access $ENV{UNIQUE_ID} ????????

2001-06-13 Thread Hasanuddin Tamir

On Wed, 13 Jun 2001, Karthik Krishnamurthy [EMAIL PROTECTED] wrote,

 in that case shouldnt both scripts unable to access that environment variable ?

You're right.  I misread Kevin's last question.  We need to know
how both script access the variable and how they get called.


__END__
-- 
s::a::n-http(www.trabas.com)




Re: Perplexing header problem

2001-06-12 Thread Hasanuddin Tamir

On Tue, 12 Jun 2001, Peter Cline [EMAIL PROTECTED] wrote,

 Last week I opted to use the CGI.pm module to print headers for me since I
 was having trouble using print Content-type: text/html \n\n

That's good, but CGI.pm is actually not for printing header only.


 Now, I am being told that the following file is not producing a valid
 header.  Anyone see why this might be the case?

Did you try it?

snip large code


__END__
-- 
s::a::n-http(www.trabas.com)




Re: testing null strings for form field values

2001-06-04 Thread Hasanuddin Tamir

On Mon, 4 Jun 2001, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote,

 if ( $formdata{view_name} ne  ) {
   $view = $formdata{view_name};
   $viewtag = 1;
 }

 is there a special method for testing against a null string for a form
 field's value? i am using the above data, but it seems to always return
 with a value of 1 making me think that something is incorrect in my if
 test. the form itself does not have anything default value specified for
 view_name.

Take a look at these one-liner examples.  The string (nothing) indicates
that no output is printed.

1% perl -le '$x; print 1 if $x ne '
(nothing)

2% perl -le '$x = undef; print 1 if $x ne '
(nothing)

3% perl -wle '$x = undef; print 1 if $x ne '
Use of uninitialized value at -e line 1.

4% perl -wle '$x = i am here; print 1 if $x ne '
1

5% perl -we '$x = undef; print ($x)\n;
Use of uninitialized value at -e line 1.
()

6% perl -we '$x = ; print ($x)\n;
()


Number 2 is basically same with number 1 in that $x is undefined,
except that $x variable in the number 2 is explicitly assigned.
(Number 1 will also give you extra warning if you use -w).
The line under number 3 is not an output of the code, it's a
warning that will guide you what's wrong with the code.

Undefined value is not the same as empty string (), but both are
evaluated to false.  If you use undefined variable anyway, it will be
evaluated to empty (see no.5 and 6).  Empty field is sent as undefined
value and when you test it against  with 'ne' operator, it evaluates to
true because they're not equal.

You need the defined() function to test whether the variable contains
some defined value, and it will cover both  and 0 if the test returns
true.

if (defined $var) {

}

If you need the value of the variable and you don't want  then you
need to test that too,

if (defined $var and $var ne ) {

}

or

if (defined $var and length $var) {

}

But if you rather want to test $var against true value, you can simply
use,

if ($var) {

}


Btw, did you use -w switch and use strict in your script?
You really should.  All those example codes above will bail out when
you use strict.


hth
s.a.n
-- 
Hasanuddin Tamir: [EMAIL PROTECTED] - Trabas: www.trabas.com