|
|
|
|
|
|
| Author |
Message |
Jack *nix forums Guru Wannabe
Joined: 27 Feb 2005
Posts: 161
|
Posted: Sat Jul 15, 2006 6:49 am Post subject:
how match/expose the value in an empty variable having length of 1
|
|
|
Hi folks,
Ok I am stumped... I am reading a fileline in as follows:
12535957@140@2006-07-08 09:34:45.000@@@2005-11-24@
and splitting on the "@"...
open(SOURCE1,$filename1)
@columnarray = split(/\@/, $_);
Whats really wierd is $columnarray[4] has a length of 1, when clearly
above its NULL !!
I want to be able to recognize this as null, but you cant even match
regex it... I tried
if ($columnarray[4] =~ m/.*?[[:print:]]/) { print " NON PRINTABLE
"."\n"; }
$columnarray[4] =~ s/^\s+//;
$columnarray[4] =~ s/\s+$//;
$length = length @columnarray[4]."\n";
and a number of other things that dont work.. how do I identify "WHAT"
is making up the length =1 ?
Also, what is the detection match test for NULL ?
Thank you all much,
Jack |
|
| Back to top |
|
 |
Jack *nix forums Guru Wannabe
Joined: 27 Feb 2005
Posts: 161
|
Posted: Sat Jul 15, 2006 7:43 am Post subject:
Re: how match/expose the value in an empty variable having length of 1
|
|
|
Jack wrote:
| Quote: | Hi folks,
Ok I am stumped... I am reading a fileline in as follows:
12535957@140@2006-07-08 09:34:45.000@@@2005-11-24@
and splitting on the "@"...
open(SOURCE1,$filename1)
@columnarray = split(/\@/, $_);
Whats really wierd is $columnarray[4] has a length of 1, when clearly
above its NULL !!
I want to be able to recognize this as null, but you cant even match
regex it... I tried
if ($columnarray[4] =~ m/.*?[[:print:]]/) { print " NON PRINTABLE
"."\n"; }
$columnarray[4] =~ s/^\s+//;
$columnarray[4] =~ s/\s+$//;
$length = length @columnarray[4]."\n";
and a number of other things that dont work.. how do I identify "WHAT"
is making up the length =1 ?
Also, what is the detection match test for NULL ?
Thank you all much,
Jack
|
NEVERMIND.. sorry.. I figured it out.. no need to post. |
|
| Back to top |
|
 |
Tad McClellan *nix forums Guru
Joined: 09 Mar 2005
Posts: 1647
|
Posted: Sat Jul 15, 2006 12:44 pm Post subject:
Re: how match/expose the value in an empty variable having length of 1
|
|
|
Jack <jack_posemsky@yahoo.com> wrote:
| Quote: | $length = length @columnarray[4]."\n";
^^ |
^^ this is one character long
And you should always enable warnings when developing Perl code.
| Quote: | how do I identify "WHAT"
is making up the length =1 ?
|
By looking closely at the string above that is the argument for length().
| Quote: | Also, what is the detection match test for NULL ?
|
Perl does not have anything known as NULL. I expect you mean
an "empty string".
print "empty string\n" unless length $columnarray[4];
or
print "empty string\n" if $columnarray[4] =~ /^\z/;
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas |
|
| Back to top |
|
 |
J. Gleixner *nix forums Guru Wannabe
Joined: 10 Mar 2005
Posts: 195
|
Posted: Mon Jul 17, 2006 10:21 pm Post subject:
Re: how match/expose the value in an empty variable having length of 1
|
|
|
Jack wrote:
| Quote: | Hi folks,
Ok I am stumped... I am reading a fileline in as follows:
12535957@140@2006-07-08 09:34:45.000@@@2005-11-24@
and splitting on the "@"...
open(SOURCE1,$filename1)
@columnarray = split(/\@/, $_);
|
Post real code as an example. If your code is actually the above, then
it has a lot of problems.
| Quote: |
Whats really wierd is $columnarray[4] has a length of 1, when clearly
above its NULL !!
|
How do you know its length is 1?
| Quote: | I want to be able to recognize this as null, but you cant even match
regex it... I tried
if ($columnarray[4] =~ m/.*?[[:print:]]/) { print " NON PRINTABLE
"."\n"; }
$columnarray[4] =~ s/^\s+//;
$columnarray[4] =~ s/\s+$//;
$length = length @columnarray[4]."\n";
|
Adding these to your code would have caught the error..
use strict;
use warnings;
my $length = length $columnarray[4]
| Quote: | and a number of other things that dont work.. how do I identify "WHAT"
is making up the length =1 ?
Also, what is the detection match test for NULL ?
|
Maybe this will help you:
perldoc -f defined
A short script as an example:
#!/usr/bin/perl
use strict;
use warnings;
my $str='12535957@140@2006-07-08 09:34:45.000@@@2005-11-24@';
my @columnarray = split(/\@/, $str);
print "length=", length( $columnarray[4] ), "\n";
print "columnarray[4] is an undefined value" unless defined $columnarray[4]; |
|
| Back to top |
|
 |
Google
|
|
| Back to top |
|
 |
|
|
The time now is Mon Dec 01, 2008 9:51 pm | All times are GMT
|
|
Facebook Proxy | Mortgage Calculator | Mortgage Calculator | Payday Loan | Ken follet
|
|
Copyright © 2004-2005 DeniX Solutions SRL
|
|
|
|
Other DeniX Solutions sites:
Unix/Linux blog |
electronics forum |
medicine forum |
science forum |
|
|
Privacy Policy
|
Powered by phpBB © 2001, 2005 phpBB Group
|
|