[24359] in Perl-Users-Digest

home help back first fref pref prev next nref lref last post

Perl-Users Digest, Issue: 6548 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon May 10 14:06:13 2004

Date: Mon, 10 May 2004 11:05:13 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Mon, 10 May 2004     Volume: 10 Number: 6548

Today's topics:
    Re: Conditional Statement failure  --- if ($a>0) (Anno Siegel)
    Re: Conditional Statement failure  --- if ($a>0) <raisin@delete-this-trash.mts.net>
    Re: Conditional Statement failure  --- if ($a>0) <tadmc@augustmail.com>
    Re: Conditional Statement failure  --- if ($a>0) <bernard.el-haginDODGE_THIS@lido-tech.net>
    Re: Conditional Statement failure  --- if ($a>0) <ewijaya@singnet.com.sg>
    Re: Conditional Statement failure  --- if ($a>0) <sbryce@scottbryce.com>
    Re: Conditional Statement failure  --- if ($a>0) <xxala_qumsiehxx@xxyahooxx.com>
    Re: Conditional Statement failure  --- if ($a>0) (Anno Siegel)
    Re: Conditional Statement failure  --- if ($a>0) (Anno Siegel)
        Confused Newbie question: Decimal to IP (Monica Roman)
    Re: Confused Newbie question: Decimal to IP <mark.clements@kcl.ac.uk>
    Re: hashes and array's <dave.verhoeven@pandora.be>
    Re: hashes and array's <tore@aursand.no>
        Oops, it gives error only when "@b" is empty, thanks (e <ewijaya@singnet.com.sg>
    Re: Oops, it gives error only when "@b" is empty, thank <1usa@llenroc.ude>
    Re: Please Recommend A Good Perl Book. (Mark Jason Dominus)
    Re: rapid development web interface to a database <david@nowhere.net>
    Re: upload file with perl cgi <sbryce@scottbryce.com>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

----------------------------------------------------------------------

Date: 10 May 2004 13:11:58 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Conditional Statement failure  --- if ($a>0)
Message-Id: <c7nv2u$qh7$1@mamenchi.zrz.TU-Berlin.DE>

Edward Wijaya  <ewijaya@singnet.com.sg> wrote in comp.lang.perl.misc:
> 
> Hi all,
> 
> This are my code snippet.
> The countArray subroutines are suppose to count
> the number of elements withiin an array.

You don't need a subroutine for that.  An array, used in scalar
context, returns the number of its elements, so

    my $a = @b;

is all you need.

> However the compilation gives the following error:
> 
> Use of uninitialized value in concatenation (.) or string at pvalue_v12.pl 
> line 325.
> Use of uninitialized value in numeric gt (>) at pvalue_v12.pl line 327.

Those aren't compilation errors, they are run-time warnings.

> Is there anything wrong with my conditional statement i.e, if ($a>0)
> or is it because of my subroutines?

> #----My code snippet-----
> $a = countArray(@b);

You don't show what @b contains.  Presumably it is empty.

Also, why isn't $a declared?  You aren't running under strict, are you?

> print "$a\n";        #----- line 325
> 
> if ($a> 0)  {        #-----line 327
> bla bla bla;
> }
>   else { die "bla bla bla"}
> 
> 
> #----Subroutines----
> sub countArray {
>      my @params = @_;
>      my $Key;
>      my $count;

That should be

       my $count = 0;

>      foreach $Key (@params) {$count++}
>      return $count;
> }

Apart from being unnecessary, the sub is (almost) correct.  The problem
is that with an empty array the loop body is never executed, and hence
$count never is assigned a value.  Just initialize $count to 0.

Anno


------------------------------

Date: Mon, 10 May 2004 08:27:42 -0500
From: Web Surfer <raisin@delete-this-trash.mts.net>
Subject: Re: Conditional Statement failure  --- if ($a>0)
Message-Id: <MPG.1b093f4b93c431d5989819@news.mts.net>

[This followup was posted to comp.lang.perl.misc]

In article <opr7sx0zokuj0cst@news.singnet.com.sg>, 
ewijaya@singnet.com.sg says...
> 
> Hi all,
> 
> This are my code snippet.
> The countArray subroutines are suppose to count
> the number of elements withiin an array.
> 
> However the compilation gives the following error:
> 
> Use of uninitialized value in concatenation (.) or string at pvalue_v12.pl 
> line 325.
> Use of uninitialized value in numeric gt (>) at pvalue_v12.pl line 327.
> 
> Is there anything wrong with my conditional statement i.e, if ($a>0)
> or is it because of my subroutines?
> 
> Thanks so much for your time.
> 
> Regards
> Edward WIJAYA
> SINGAPORE
> 
> #----My code snippet-----
> $a = countArray(@b);
> print "$a\n";        #----- line 325
> 
> if ($a> 0)  {        #-----line 327
> bla bla bla;
> }
>   else { die "bla bla bla"}
> 
> 
> #----Subroutines----
> sub countArray {
>      my @params = @_;
>      my $Key;
>      my $count;
       my $count = 0;

>      foreach $Key (@params) {$count++}
>      return $count;
> }

To count the number of elements in an array you might want to consider 
doing the following :

$count =  scalar @array;


------------------------------

Date: Mon, 10 May 2004 08:41:24 -0500
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: Conditional Statement failure  --- if ($a>0)
Message-Id: <slrnc9v1k4.1n0.tadmc@magna.augustmail.com>

Anno Siegel <anno4000@lublin.zrz.tu-berlin.de> wrote:
> Edward Wijaya  <ewijaya@singnet.com.sg> wrote in comp.lang.perl.misc:

>> $a = countArray(@b);

> Also, why isn't $a declared?  You aren't running under strict, are you?


Maybe he is and maybe he isn't.

We can't tell since $a (and $b) happens to be exempted 
from "use strict" anyway.  :-)


-- 
    Tad McClellan                          SGML consulting
    tadmc@augustmail.com                   Perl programming
    Fort Worth, Texas


------------------------------

Date: Mon, 10 May 2004 15:48:19 +0200
From: "Bernard El-Hagin" <bernard.el-haginDODGE_THIS@lido-tech.net>
Subject: Re: Conditional Statement failure  --- if ($a>0)
Message-Id: <Xns94E5A0CFF6192elhber1lidotechnet@62.89.127.66>

Web Surfer <raisin@delete-this-trash.mts.net> wrote:

[...]

 
> To count the number of elements in an array you might want to
> consider doing the following :
> 
> $count =  scalar @array;
 

To count the number of elements in an array *you* might want to 
consider doing the following:


$count = @array;


-- 
Cheers,
Bernard


------------------------------

Date: Mon, 10 May 2004 22:12:27 -0000
From: Edward Wijaya <ewijaya@singnet.com.sg>
Subject: Re: Conditional Statement failure  --- if ($a>0)
Message-Id: <opr7s1a1ceuj0cst@news.singnet.com.sg>

Sorry for my "misbehavior" guys.

BTW, I am not using $a under strict,
even if I declare $a=0 beforehand
it still gives the same error.

Why is it harmful to use sub for counting arrays' content?

Thanks
Edward WIJAYA
Singapore

On Mon, 10 May 2004 08:41:24 -0500, Tad McClellan <tadmc@augustmail.com> 
wrote:

> Anno Siegel <anno4000@lublin.zrz.tu-berlin.de> wrote:
>> Edward Wijaya  <ewijaya@singnet.com.sg> wrote in comp.lang.perl.misc:
>
>>> $a = countArray(@b);
>
>> Also, why isn't $a declared?  You aren't running under strict, are you?
>
>
> Maybe he is and maybe he isn't.
>
> We can't tell since $a (and $b) happens to be exempted
> from "use strict" anyway.  :-)
>
>



-- 
Using M2, Opera's revolutionary e-mail client: http://www.opera.com/m2/


------------------------------

Date: Mon, 10 May 2004 08:29:34 -0600
From: Scott Bryce <sbryce@scottbryce.com>
Subject: Re: Conditional Statement failure  --- if ($a>0)
Message-Id: <109v4duffp67o1e@corp.supernews.com>

Edward Wijaya wrote:

> Why is it harmful to use sub for counting arrays' content?

Not harmful. Just unnecessary.

The use of $a and $b may be problematic, since they are reserved 
variables. Their values could get stomped on, or you could be stomping 
on them when they are being used for their intended purpose. It is best 
to get in the habit of not using them except for their intended purpose.



------------------------------

Date: Mon, 10 May 2004 15:00:28 GMT
From: Ala Qumsieh <xxala_qumsiehxx@xxyahooxx.com>
Subject: Re: Conditional Statement failure  --- if ($a>0)
Message-Id: <gOMnc.6914$822.6730@newssvr27.news.prodigy.com>

Bernard El-Hagin wrote:
> Web Surfer <raisin@delete-this-trash.mts.net> wrote:
> 
> [...]
> 
>  
> 
>>To count the number of elements in an array you might want to
>>consider doing the following :
>>
>>$count =  scalar @array;
> 
>  
> 
> To count the number of elements in an array *you* might want to 
> consider doing the following:
> 
> 
> $count = @array;

Nothing wrong with using scalar() explicitly. Personally, I don't, but 
some people find that clearer. I would *encourage* anybody to use it if 
it helps their maintainability.

--Ala



------------------------------

Date: 10 May 2004 16:34:29 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Conditional Statement failure  --- if ($a>0)
Message-Id: <c7oaul$4vu$2@mamenchi.zrz.TU-Berlin.DE>

Edward Wijaya  <ewijaya@singnet.com.sg> wrote in comp.lang.perl.misc:
> Sorry for my "misbehavior" guys.

Please don't top-post.  See the posting guidelines for this group, they
are posted here regularly.

> BTW, I am not using $a under strict,
> even if I declare $a=0 beforehand
> it still gives the same error.

Of course it doesn't help to initialize $a, its value will be set to
whatever the sub returns.

It's the count variable in the sub that needs initialization.

[TOFU snipped]

Anno


------------------------------

Date: 10 May 2004 16:35:58 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Conditional Statement failure  --- if ($a>0)
Message-Id: <c7ob1e$4vu$3@mamenchi.zrz.TU-Berlin.DE>

Tad McClellan  <tadmc@augustmail.com> wrote in comp.lang.perl.misc:
> Anno Siegel <anno4000@lublin.zrz.tu-berlin.de> wrote:
> > Edward Wijaya  <ewijaya@singnet.com.sg> wrote in comp.lang.perl.misc:
> 
> >> $a = countArray(@b);
> 
> > Also, why isn't $a declared?  You aren't running under strict, are you?
> 
> 
> Maybe he is and maybe he isn't.
> 
> We can't tell since $a (and $b) happens to be exempted 
> from "use strict" anyway.  :-)

Oh, right.  I didn't notice what particular variable went undeclared.

Anno



------------------------------

Date: 10 May 2004 09:58:33 -0700
From: monicaroman@yahoo.com (Monica Roman)
Subject: Confused Newbie question: Decimal to IP
Message-Id: <9eb77af5.0405100858.2c119e6d@posting.google.com>

I've read a lot of the threads on this conversion but could not figure
out which one is the correct function.

I have never written PERL before, but I want to give it a try and be
able to convert decimal numbers into IP addresses in the PERL script
used to load the IPs plus other data into an Oracle database. Right
now I use a SQL function within Oracle, but it slows down everything!

Can someone help the translate into PERL the following SQL function?

create or replace function int2ip(ip  int)
return varchar2
is
 ip_address varchar2(15);
  t  number;
  w  int(3);
  x  int(3);
  y  int(3);
  z  int(3);

begin

         t:= ip / 256;
         w:= 256 * (t - FLOOR(t));
         t:= (FLOOR (t))/ 256;
         x:= 256 * (t - FLOOR(t));
         t:= (FLOOR (t)) / 256;
         y:= 256 * (t - FLOOR(t));
         z:= FLOOR (t);

 ip_address := z||'.'||y||'.'||x||'.'||w;

  return ip_address;
end int2ip;


Thank you very much,


Monica Roman


------------------------------

Date: Mon, 10 May 2004 18:05:34 +0100
From: Mark Clements <mark.clements@kcl.ac.uk>
Subject: Re: Confused Newbie question: Decimal to IP
Message-Id: <409fb64b$1@news.kcl.ac.uk>

Monica Roman wrote:
> I've read a lot of the threads on this conversion but could not figure
> out which one is the correct function.
> 
> I have never written PERL before, but I want to give it a try and be
> able to convert decimal numbers into IP addresses in the PERL script
> used to load the IPs plus other data into an Oracle database. Right
> now I use a SQL function within Oracle, but it slows down everything!
<snip horrific pl/sql> (yes, I know that that is its nature)

look at inet_ntoa in the Socket module for starters.

perldoc Socket

btw: it's written "Perl" or "perl".

regards,

Mark


------------------------------

Date: Mon, 10 May 2004 13:31:12 GMT
From: "Dafke8" <dave.verhoeven@pandora.be>
Subject: Re: hashes and array's
Message-Id: <AuLnc.909$B64.126125223@hestia.telenet-ops.be>


"Tore Aursand" <tore@aursand.no> schreef in bericht
news:pan.2004.05.07.09.15.18.267583@aursand.no...
> On Thu, 06 May 2004 23:16:02 +0000, Dafke8 wrote:
> >>> push @namen,$akte =~
m!<span\s+class="naam"\s+id="(n[0-9]+)">(.*?)</span>!g;
>
> >>> if ( $akte =~ m!<span\s+class="naam"\s+id="n[0-9]+">(.*?)</span>!g ) {
> >>>     push( @namen, $1 ,$2);
> >>> }
>
>
> Which one of them?  Have you tried them both?  And - why don't you want to
> see the difference? Let me ask you again:  What do you think gets pushed
> to @namen if you use the first code above, and you regular expression
> doesn't match?
>
I used the expression from above and so far it works fine. I thought that
when the regular expression didn't match, that there was notting pushed into
the array. But probably it isn't so.




------------------------------

Date: Mon, 10 May 2004 17:41:33 +0200
From: Tore Aursand <tore@aursand.no>
Subject: Re: hashes and array's
Message-Id: <pan.2004.05.10.15.35.47.264302@aursand.no>

On Mon, 10 May 2004 13:31:12 +0000, Dafke8 wrote:
> I used the expression from above and so far it works fine.

If you use _your_ regular expression, it _will_ fail whenever there's no
match.

> I thought that when the regular expression didn't match, that there was
> notting pushed into the array. But probably it isn't so.

Yes, it is so; Nothing will ever get pushed to @namen if there is no
match, so there a "self-documenting problem" with your way of doing it.


-- 
Tore Aursand <tore@aursand.no>
"First get your facts; then you can distort them at your leisure."
 (Mark Twain)


------------------------------

Date: Mon, 10 May 2004 21:15:39 -0000
From: Edward Wijaya <ewijaya@singnet.com.sg>
Subject: Oops, it gives error only when "@b" is empty, thanks (eom)
Message-Id: <opr7syodw2uj0cst@news.singnet.com.sg>

On Mon, 10 May 2004 21:01:37 -0000, Edward Wijaya <ewijaya@singnet.com.sg> 
wrote:

>
> Hi all,
>
> This are my code snippet.
> The countArray subroutines are suppose to count
> the number of elements withiin an array.
>
> However the compilation gives the following error:
>
> Use of uninitialized value in concatenation (.) or string at 
> pvalue_v12.pl line 325.
> Use of uninitialized value in numeric gt (>) at pvalue_v12.pl line 327.
>
> Is there anything wrong with my conditional statement i.e, if ($a>0)
> or is it because of my subroutines?
>
> Thanks so much for your time.
>
> Regards
> Edward WIJAYA
> SINGAPORE
>
> #----My code snippet-----
> $a = countArray(@b);
> print "$a\n";        #----- line 325
>
> if ($a> 0)  {        #-----line 327
> bla bla bla;
> }
>   else { die "bla bla bla"}
>
>
> #----Subroutines----
> sub countArray {
>      my @params = @_;
>      my $Key;
>      my $count;
>      foreach $Key (@params) {$count++}
>      return $count;
> }
>
>
>
>



-- 
Using M2, Opera's revolutionary e-mail client: http://www.opera.com/m2/


------------------------------

Date: 10 May 2004 13:46:42 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude>
Subject: Re: Oops, it gives error only when "@b" is empty, thanks (eom)
Message-Id: <Xns94E56377D4B6Basu1cornelledu@132.236.56.8>

Edward Wijaya <ewijaya@singnet.com.sg> wrote in
news:opr7syodw2uj0cst@news.singnet.com.sg: 

(in the subject line)

> Re: Oops, it gives error only when "@b" is empty, thanks (eom)

Don't put your entire message in the subject line. Don't quote an entire 
message if you are not going to say anything about the material you have 
quoted.

Please pay attention to Tad's remark regarding the special variables $a and 
$b (for more info, see perldoc -f sort).

Do stop using a sub to count the number of elements in an array.


-- 
A. Sinan Unur
1usa@llenroc.ude (reverse each component for email address)


------------------------------

Date: Mon, 10 May 2004 15:43:14 +0000 (UTC)
From: mjd@plover.com (Mark Jason Dominus)
Subject: Re: Please Recommend A Good Perl Book.
Message-Id: <c7o7ui$j53$1@plover.com>

In article <u8yg41vbc.fsf@notvalid.se>,  <moller@notvalid.se> wrote:
>$persons {'Mark Jason Dominus'}{ nice } = 1;

I am afraid that is not really the case.  I think you may be confusing
this with

        $persons {'Mark Jason Dominus'}{ good } = 1;

From a long way away, they can sometimes look similar.


------------------------------

Date: Mon, 10 May 2004 13:34:43 GMT
From: David Segall <david@nowhere.net>
Subject: Re: rapid development web interface to a database
Message-Id: <p20v90p5euob3ebbgqt291vqpk4o56i155@4ax.com>

Gregory Toomey <nospam@bigpond.com> wrote:

>carloschoenberg@yahoo.com wrote:
>
>> I am looking for the easiest web interface to a database. By easiest,
>> I mean most rapid development. Because the requirements are so simple
>> and standard, I'm hoping that something can take care of the grunt
>> work. Easy maintenance, possibly by non-programmers (or at least
>> "junior" programmers) would also be nice.
>> 
>> I'm open to Perl, PHP, Java in that order (best solution wins, equal
>> solutions go with the preferred language). I'm also open to anything
>> that doesn't require code to be written to get the job done, as long
>> as there's some way to extend it if I get stuck.
>> 
>> The design is simple and is an age-old story:
>> I have a database with about 15 tables.  5 contain data with the same
>> primary key, 2 have their own primary key but still a 1-to-1 mapping
>> to the "main" primary key, and 8 are master lists that the other
>> tables reference (site id, customer id, that sort of thing). I need
>> the following screens:
>> simple search based on a couple fields
>> advanced search based on most available fields
>> search results simple display, showing a reasonable set of fields
>> search results advanced display, showing large or configurable set of
>> fields
>> simple display, showing most commonly desired fields
>> advanced display, showing all data
>> add new record simple, requesting most commonly entered fields
>> add new record advanced, allowing all fields to be manipulated
>> edit existing record simple
>> edit existing record advanced
>> editing for each of the 'master' tables
>
>Oracle have tools to do all that but it costs a fortune.
JDeveloper costs $1000.00 which is substantially less than similar
tools from IBM or Borland. You can use it with any database that has a
JDBC interface so you do not need to buy an Oracle database.
Furthermore, their trial version is not time limited so, if you are a
cash-strapped, independent developer you can postpone paying for it
until your first application is deployed.
>
>gtoomey



------------------------------

Date: Mon, 10 May 2004 08:23:13 -0600
From: Scott Bryce <sbryce@scottbryce.com>
Subject: Re: upload file with perl cgi
Message-Id: <109v421jg3ill76@corp.supernews.com>

Sokar wrote:

> I have investigated the <input TYPE='file' NAME='pic' size='15'> for use in
> the html part.

You need to include an encoding type in the form tag.

<form action='cgi-bin/myscript.pl', method='post' 
ENCTYPE='multipart/form-data'>

If that doesn't solve your problem, and you can't find the answer in the 
docs, read the posting guidelines for this group, then post a short but 
complete script that demonstrates the problem you are having.



------------------------------

Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 6 Apr 01)
Message-Id: <null>


Administrivia:

#The Perl-Users Digest is a retransmission of the USENET newsgroup
#comp.lang.perl.misc.  For subscription or unsubscription requests, send
#the single line:
#
#	subscribe perl-users
#or:
#	unsubscribe perl-users
#
#to almanac@ruby.oce.orst.edu.  

NOTE: due to the current flood of worm email banging on ruby, the smtp
server on ruby has been shut off until further notice. 

To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.

#To request back copies (available for a week or so), send your request
#to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
#where x is the volume number and y is the issue number.

#For other requests pertaining to the digest, send mail to
#perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
#sending perl questions to the -request address, I don't have time to
#answer them even if I did know the answer.


------------------------------
End of Perl-Users Digest V10 Issue 6548
***************************************


home help back first fref pref prev next nref lref last post