niXforums Forum Index
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   PreferencesPreferences   Log in to check your private messagesLog in to check your private messages   Log inLog in 
·  nixdoc.net ·  man pages ·  Linux HOWTOs ·  FreeBSD Tips ·  Forums
navigation Forum index » Programming » Perl
how match/expose the value in an empty variable having length of 1
Post new topic   Reply to topic Page 1 of 1 [4 Posts] View previous topic :: View next topic
Author Message
Jack
*nix forums Guru Wannabe


Joined: 27 Feb 2005
Posts: 161

PostPosted: Sat Jul 15, 2006 6:49 am    Post subject: how match/expose the value in an empty variable having length of 1 Reply with 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
Back to top
Jack
*nix forums Guru Wannabe


Joined: 27 Feb 2005
Posts: 161

PostPosted: Sat Jul 15, 2006 7:43 am    Post subject: Re: how match/expose the value in an empty variable having length of 1 Reply with quote

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

PostPosted: Sat Jul 15, 2006 12:44 pm    Post subject: Re: how match/expose the value in an empty variable having length of 1 Reply with quote

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

PostPosted: Mon Jul 17, 2006 10:21 pm    Post subject: Re: how match/expose the value in an empty variable having length of 1 Reply with quote

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
Display posts from previous:   
Post new topic   Reply to topic Page 1 of 1 [4 Posts] View previous topic :: View next topic
The time now is Mon Dec 01, 2008 9:51 pm | All times are GMT
navigation Forum index » Programming » Perl
Jump to:  

Similar Topics
Topic Author Forum Replies Last Post
No new posts Postfix + MySQL error: very strange variable %s iWarior Postfix 0 Mon Aug 25, 2008 2:01 pm
No new posts Secondary db empty susu Berkeley DB 0 Thu Sep 21, 2006 10:37 am
No new posts User Environment - export PATH variable paalepu AIX 0 Tue Sep 12, 2006 8:12 pm
No new posts Match lines, group and sum FriesAOLE shell 2 Thu Jul 20, 2006 7:40 am
No new posts Match pattern in ksh script lnrntx@gmail.com shell 6 Thu Jul 20, 2006 1:48 am

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
[ Time: 1.7112s ][ Queries: 16 (1.6149s) ][ GZIP on - Debug on ]