[13647] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 1057 Volume: 9

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Oct 15 14:11:34 1999

Date: Fri, 15 Oct 1999 11:11:18 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <940011078-v9-i1057@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Fri, 15 Oct 1999     Volume: 9 Number: 1057

Today's topics:
        Connecting SQL Server from Perl <Latha.Sudharshan@compaq.com>
    Re: Connecting SQL Server from Perl <ernstc@post3.tele.dk>
    Re: Connecting SQL Server from Perl (Brett W. McCoy)
        control keys <lsnguyen@softway.fr>
    Re: control keys <rootbeer@redcat.com>
    Re: Counter <amonotod@netscape.net>
        Datek to Quicken account converter topalli@my-deja.com
        datek2quicken converter topalli@my-deja.com
        DBD DELETE statement jhagerty@my-deja.com
    Re: DBD:MySQL install problems. steve19184774@my-deja.com
        DBI. local host  is not allowed to connect to this MySQ <coreto03@axa-seguros.pt>
    Re: DBI. local host is not allowed to connect to this M wooflock@my-deja.com
        dbi.pm rkuryk8035@my-deja.com
    Re: dbi.pm <sjohns17@uic.edu>
    Re: dbi.pm <gellyfish@gellyfish.com>
        DBILogin and tns resolve ? <dnichols@fhcrc.org>
    Re: debugging question <rootbeer@redcat.com>
    Re: debugging question <andreas@vierengel.de>
        Decoding mime attchs (jpg) in stored email <af778NOafSPAM@iname.com.invalid>
    Re: Decoding mime attchs (jpg) in stored email <NukeEmUp@ThePentagon.com>
        Difference between a string and an int (Gene Johannsen)
    Re: Difference between a string and an int <laurensmith@sprynet.com>
    Re: Difference between a string and an int (Larry Rosler)
    Re: Difference between a string and an int (Sam Holden)
    Re: Difference between a string and an int <rootbeer@redcat.com>
    Re: Difference between a string and an int <makarand_kulkarni@my-deja.com>
    Re: Difference between a string and an int <amonotod@netscape.net>
    Re: Difference between a string and an int (Philip 'Yes, that's my address' Newton)
    Re: Difference between a string and an int (hymie!)
    Re: Difference between a string and an int <amonotod@netscape.net>
    Re: Difference between a string and an int (Gene Johannsen)
        Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)

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

Date: Thu, 14 Oct 1999 16:35:15 -0700
From: "Latha Sudharshan" <Latha.Sudharshan@compaq.com>
Subject: Connecting SQL Server from Perl
Message-Id: <7u5pgg$58u$1@mailint03.im.hou.compaq.com>

Hi,

I am faced with the problem of inserting the HTMLform data into the SQL
database. I am using MS ODBC SQLServer driver ( which is already installed
on my Windows NT 4.0 machine ). I am using Microsoft SQL Server 6.5 and Perl
version 5.005_03 built from ActiveState.com. I am trying to insert the data
using CGI script with Perl on the server side. I even tried installing
Win32::ODBC module. I guess I get the connection to the ODBC driver. I get
the error as :

C:\PERL>perl test.pl
Connection number returned is:1

Excecuting connection 1
sql statement: "SELECT * FROM members"
Error: "208[Microsoft][ODBC SQL Server Driver][SQL Server]Invalid object
name 'members'.10"
--------------------
Error: Win32::ODBC=HASH(0xcb3cf4)->Error()


I have a snippet of my perl script as:
***************************************************************************
#!/perl

use Win32::ODBC;

$DSN = dsnname";
if(!($db = new Win32::ODBC("dsn=$DSN;UID=****;PWD=****")))
{
print "Error connecting to $DSN since handle returned is:$db\n";
print Win32::ODBC::Error();
exit;
}
$connectnum = $db->Connection;
print( "Connection number returned is:$connectnum\n" );
print LOG qq(Current connection: "), $db->GetDSN, qq("\n);
if( $db->Run("SELECT * FROM members" ))
{
print( "Error: $db->Error()\n" );
$db->Close();
exit(1);
}
$db->Close;

*******************************************************************
But when I give SQL instead of Run i.e., SQL("SELECT * FROM members" ),
I get the error as:

C:\PERL>perl test.pl
Connection number returned is:1
Can't locate auto/Win32/ODBC/SQL.al in @INC (@INC contains: C:/Perl/lib
C:/Perl/si
te/lib .) at test.pl line 15

I do have ODBC directory but under C:\Perl\site\lib\auto\Win32 and in this
ODBC
directory, I have odbc.dll.

Please let me know if anybody has any idea.

Thanks,
Latha






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

Date: Fri, 15 Oct 1999 09:27:26 +0100
From: ec <ernstc@post3.tele.dk>
Subject: Re: Connecting SQL Server from Perl
Message-Id: <3806E56E.FDEAA9DD@post3.tele.dk>

Hi
The second qustion,: remember that this is case sensitive use sql instead of
SQL.
The first qustin indicates that there is no table named members

mvh
EC

Latha Sudharshan wrote:

> Hi,
>
> I am faced with the problem of inserting the HTMLform data into the SQL
> database. I am using MS ODBC SQLServer driver ( which is already installed
> on my Windows NT 4.0 machine ). I am using Microsoft SQL Server 6.5 and Perl
> version 5.005_03 built from ActiveState.com. I am trying to insert the data
> using CGI script with Perl on the server side. I even tried installing
> Win32::ODBC module. I guess I get the connection to the ODBC driver. I get
> the error as :
>
> C:\PERL>perl test.pl
> Connection number returned is:1
>
> Excecuting connection 1
> sql statement: "SELECT * FROM members"
> Error: "208[Microsoft][ODBC SQL Server Driver][SQL Server]Invalid object
> name 'members'.10"
> --------------------
> Error: Win32::ODBC=HASH(0xcb3cf4)->Error()
>
> I have a snippet of my perl script as:
> ***************************************************************************
> #!/perl
>
> use Win32::ODBC;
>
> $DSN = dsnname";
> if(!($db = new Win32::ODBC("dsn=$DSN;UID=****;PWD=****")))
> {
> print "Error connecting to $DSN since handle returned is:$db\n";
> print Win32::ODBC::Error();
> exit;
> }
> $connectnum = $db->Connection;
> print( "Connection number returned is:$connectnum\n" );
> print LOG qq(Current connection: "), $db->GetDSN, qq("\n);
> if( $db->Run("SELECT * FROM members" ))
> {
> print( "Error: $db->Error()\n" );
> $db->Close();
> exit(1);
> }
> $db->Close;
>
> *******************************************************************
> But when I give SQL instead of Run i.e., SQL("SELECT * FROM members" ),
> I get the error as:
>
> C:\PERL>perl test.pl
> Connection number returned is:1
> Can't locate auto/Win32/ODBC/SQL.al in @INC (@INC contains: C:/Perl/lib
> C:/Perl/si
> te/lib .) at test.pl line 15
>
> I do have ODBC directory but under C:\Perl\site\lib\auto\Win32 and in this
> ODBC
> directory, I have odbc.dll.
>
> Please let me know if anybody has any idea.
>
> Thanks,
> Latha



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

Date: Fri, 15 Oct 1999 13:10:43 GMT
From: bmccoy@foiservices.com (Brett W. McCoy)
Subject: Re: Connecting SQL Server from Perl
Message-Id: <slrn80ea6m.4oc.bmccoy@moebius.foiservices.com>

Also Sprach ec <ernstc@post3.tele.dk>:

>The second qustion,: remember that this is case sensitive use sql instead of
>SQL.
>The first qustin indicates that there is no table named members

Actually, the method name is Win32::ODBC->Sql (the first letter is
capitalized).

-- 
Brett W. McCoy                             bmccoy@foiservices.com
Computer Operations Manager (Alpha Geek)   http://www.foiservices.com
FOI Services, Inc./DIOGENES                301-975-0110
---------------------------------------------------------------------------


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

Date: Wed, 13 Oct 1999 19:33:29 +0200
From: lam son nguyen <lsnguyen@softway.fr>
Subject: control keys
Message-Id: <3804C269.9ED3158F@softway.fr>

hello,


I'd like to send a Ctrl d to an application
accessed with  Net::Telnet
But I can't see how.

thanks in advance


lam son



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

Date: Wed, 13 Oct 1999 14:23:18 -0700
From: Tom Phoenix <rootbeer@redcat.com>
Subject: Re: control keys
Message-Id: <Pine.GSO.4.10.9910131422370.25558-100000@user2.teleport.com>

On Wed, 13 Oct 1999, lam son nguyen wrote:

> I'd like to send a Ctrl d to an application
> accessed with  Net::Telnet
> But I can't see how.

If you want to send a chr(4), send that. If you want to close the
connection, do that. If you need something else, ask again!

-- 
Tom Phoenix       Perl Training and Hacking       Esperanto
Randal Schwartz Case:     http://www.rahul.net/jeffrey/ovs/



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

Date: Wed, 13 Oct 1999 16:54:23 GMT
From: amonotod <amonotod@netscape.net>
Subject: Re: Counter
Message-Id: <7u2dfo$vg1$1@nnrp1.deja.com>

In article <37F9EF1F.3FD99491@uni-paderborn.de>,
  Chris Loeser <loeser@uni-paderborn.de> wrote:
> Tach Post,
>
> ich moechte ganz gerne einen Counter in einem HTML-Dokument haben.
>
> 1.Server Side Includes ist bei dem HTTP-Server ausgeschaltet, daher :
>
> 2. In einer vorhandenen Seite soll ein Perl-Script aufgerufen werden
und
>    die Counterzahl soll in das Dokument eingebunden werden....
>
> Hat jemand das schon mal gemacht ??
>
> cheers
>
> Chris
>
> mailto:loeser@upb.de
>
What ever all that was... I don't know German language, but you titled
your post "Counter" so take a look at this...
http://www.geocities.com/amonotod
and something about "Server Side Includes" so try this...
http://hoohoo.ncsa.uiuc.edu/docs/tutorials/includes.html

ein gerfarhliches ding,
amonotod

--
    `\|||/                     amonotod@
      (@@)                     netscape.net
  ooO_(_)_Ooo________________________________
  _____|_____|_____|_____|_____|_____|_____|_____|


Sent via Deja.com http://www.deja.com/
Before you buy.


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

Date: Fri, 15 Oct 1999 02:12:36 GMT
From: topalli@my-deja.com
Subject: Datek to Quicken account converter
Message-Id: <7u62ia$lf5$1@nnrp1.deja.com>

I'm sure this is only of interest to a small number of people.


However,

I wrote a script to load files from a datek brokerage account into
quicken.

The script converts your datek account information (that you get
from account history on their web page) into a quicken "QIF" import file.
which you can then import into quicken.

This is one of my first scripts.  Thanks to those on the boards who gave
me a hand when I didn't know anything.

If anybody has a datek account, and uses Perl you might want to check it
out and give me your feedback on how to improve the thing.

Ilir


Sent via Deja.com http://www.deja.com/
Before you buy.


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

Date: Fri, 15 Oct 1999 02:50:55 GMT
From: topalli@my-deja.com
Subject: datek2quicken converter
Message-Id: <7u64qb$mvl$1@nnrp1.deja.com>

(Ooops forgot the html address)

I'm sure this is only of interest to a small number of people.


However,

I wrote a script to load files from a datek brokerage account into
quicken.

The script converts your datek account information (that you get
from account history on their web page) into a quicken "QIF" import file.
which you can then import into quicken.

http://www.gis.net/~ilir/datek2quicken.html

This is one of my first scripts.  Thanks to those on the boards who gave
me a hand when I didn't know anything.

If anybody has a datek account, and uses Perl you might want to check it
out and give me your feedback on how to improve the thing.

Ilir




Sent via Deja.com http://www.deja.com/
Before you buy.


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

Date: Fri, 15 Oct 1999 17:13:53 GMT
From: jhagerty@my-deja.com
Subject: DBD DELETE statement
Message-Id: <7u7nc3$ra6$1@nnrp1.deja.com>

I am trying to write a DELETE statement and i keep getting an error
telling me I am giving too few parameters.  I can't find and SQL
statement help that was installed.

Here is what I am trying:

$dSQL = "DELETE FROM [TABLE1] WHERE (TABLE1.FIELD1 = $VALUE1)";
my $sth = $dbh->prepare($dSQL) || die "cant prepare $DBI::errstr \n";
$sth->execute || die "cant execute $DBI::errstr \n";

If it's relevant , this is writing to an Access database.

Thanks



Sent via Deja.com http://www.deja.com/
Before you buy.


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

Date: Tue, 12 Oct 1999 23:26:57 GMT
From: steve19184774@my-deja.com
Subject: Re: DBD:MySQL install problems.
Message-Id: <7u0g3i$je3$1@nnrp1.deja.com>

You don't need the SRC File you need to go to
mysql.com and down load the perl binary
file. It will have all the files you need.


In article <37FD58B6.B1754DA1@anlon.com>,
  Kangas <kangas@anlon.com> wrote:
> I am an NT guy who is converting to Linux. I
need to get Perl to connect
> to my MySQL database. This is what has been
happening while I have been
> trying to make this happen.
>
> I installed the MySQL server and client using
the RPM's.  I got the DBI
> installed but when it comes to the mSQL/MySQL
module installation it is
> asking me for the location of the MySQL.h file.
I grabed it from the
> tar.gz file. I created the 'include' directory
and stuck it in there.
> The next question asks for the libmysqlclient.a
or libmysqlclient.so
> file and these are not in the installation
directory or in the
> MySQL.src.rpm file that I downloaded.
>
> I tried to run the install for the
mysql.src.rpm but nothing happened. I
> was hoping that it would install the source
files. I managed to grab and
> gunzip the src.tar.gz file and copied the
source into my install
> directory but this accomplished nothing but
filing up my drive and
> getting the mysql.h file for me. I still need
the libmysqlclient.so file
> and any others I will need after I get past
this point of the mSQL/MySQL
> installation sticking point.
>
> 1.) Where do I find the libmysqlclient.so file?
> 2.) Is it o.k. to just grab the file it is
looking for and put it into
> the directory it is looking for it in?
> 3.) Is there another module I can use the
connect to MySQL?
>
> Thanks
> --
> Michael Kangas
> kangas@anlon.com
>
>



Sent via Deja.com http://www.deja.com/
Before you buy.


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

Date: Fri, 15 Oct 1999 08:04:21 +0100
From: "Rui Anastácio" <coreto03@axa-seguros.pt>
Subject: DBI. local host  is not allowed to connect to this MySQL server ???
Message-Id: <7u6rri$m84$2@duke.telepac.pt>

Hi ! I have a DB in MySQL. Using:

mysql -h hostname -u user -p db

I can connect to pontonet1. But using BDI with DNS='DBI:mysql:db'
I get:

ERROR 1130: Host 'localhost.xxx.xxx' is not allowed to connect to this MySQL
server

Is it a DNS problem ? How can I indicate the hostname in the DNS string ?

thanks in advance
Rui Anastácio






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

Date: Fri, 15 Oct 1999 14:47:43 GMT
From: wooflock@my-deja.com
Subject: Re: DBI. local host is not allowed to connect to this MySQL server ???
Message-Id: <7u7eqb$kb0$1@nnrp1.deja.com>

In article <7u6rri$m84$2@duke.telepac.pt>,
  "Rui Anastácio" <coreto03@axa-seguros.pt> wrote:
> Hi ! I have a DB in MySQL. Using:
>
> mysql -h hostname -u user -p db
>
> I can connect to pontonet1. But using BDI with
DNS='DBI:mysql:db'

DBI:mysql:db is not a valid DNS
(as far as i know anyway)

> I get:
>
> ERROR 1130: Host 'localhost.xxx.xxx' is not
allowed to connect to this MySQL
> server
Strange if you got something else

> Is it a DNS problem ? How can I indicate the
hostname in the DNS string ?

$DNS="thehost.youwant.com";

> thanks in advance
> Rui Anastácio
De nada Rui.

/Martin Quensel



Sent via Deja.com http://www.deja.com/
Before you buy.


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

Date: Wed, 13 Oct 1999 15:47:56 GMT
From: rkuryk8035@my-deja.com
Subject: dbi.pm
Message-Id: <7u29j6$s9j$1@nnrp1.deja.com>

I'm trying to install the DBI.pm perl module on a win32 platform.
Mainly for testing.  I use a UNIX server.  I can't even find it in a
(.zip) version.  I'm trying to get some mysql ODBC connectivity for
generating dynamic webpages.  Please e-mail me as I do not check the
forums too often, although I'll try for the next few days.  Thanks

rob
e-mail : rkuryk@classiccatering.com
website: http://www.classiccatering.com


Sent via Deja.com http://www.deja.com/
Before you buy.


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

Date: Wed, 13 Oct 1999 14:59:44 -0500
From: Seth David Johnson <sjohns17@uic.edu>
To: rkuryk8035@my-deja.com
Subject: Re: dbi.pm
Message-Id: <Pine.A41.4.10.9910131457080.176796-100000@tigger.cc.uic.edu>

Courtesy copy sent to original poster.

On Wed, 13 Oct 1999 rkuryk8035@my-deja.com wrote:

> I'm trying to install the DBI.pm perl module on a win32 platform.
> Mainly for testing.  I use a UNIX server.  I can't even find it in a
> (.zip) version.  I'm trying to get some mysql ODBC connectivity for
> generating dynamic webpages.  Please e-mail me as I do not check the
> forums too often, although I'll try for the next few days.  Thanks

Have you tried installing using ppm.pl (the package manager that comes
with the ActivePerl distribution)?

Refer to:

http://www.activestate.com/PPM/

-Seth
 www.pdamusic.com



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

Date: 13 Oct 1999 20:56:51 -0000
From: Jonathan Stowe <gellyfish@gellyfish.com>
Subject: Re: dbi.pm
Message-Id: <7u2rmj$ch$1@gellyfish.btinternet.com>

On Wed, 13 Oct 1999 15:47:56 GMT rkuryk8035@my-deja.com wrote:
> I'm trying to install the DBI.pm perl module on a win32 platform.
> Mainly for testing.  I use a UNIX server.  I can't even find it in a
> (.zip) version.  I'm trying to get some mysql ODBC connectivity for
> generating dynamic webpages.  Please e-mail me as I do not check the
> forums too often, although I'll try for the next few days.  Thanks

If you  are using the Activestate Perl then you should be able to
install DBD::ODBC with :

C:\> PPM INSTALL DBD-ODBC

/J\
-- 
Jonathan Stowe <jns@gellyfish.com>
<http://www.gellyfish.com>
Hastings: <URL:http://dmoz.org/Regional/UK/England/East_Sussex/Hastings>


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

Date: Wed, 13 Oct 1999 21:24:10 +0000
From: Douglas Nichols <dnichols@fhcrc.org>
Subject: DBILogin and tns resolve ?
Message-Id: <3804F87A.3F90AA2C@fhcrc.org>

> >
> > I installed DBILogin and have the ussual DBD:Oracle and DBI innstall and
> > I can run DBD:Oracle scripts fine. But when I try to authenticate usinng
> > DBILogin I get :
> >
> > ORACLE_HOME environment variable not set!
> > [Wed Oct 13 14:06:12 1999] [error] access to /dsc/ failed for
> > 140.117.215.226, reason: user doug: ORA-12154: TNS:could not resolve
> > service name (DBD ERROR: OCIServerAttach)
> >
> > But I can sqlplus fine and can connect using other cgi programs fine. So
> > I assume it is DBILogin that is not resolving correctly?
> >
> > Thanks for the help!
> >
> > --
> > Cheers, dn
> >
> > Douglas Nichols                              dnichols@fhcrc.org
> > ---------------------------------------------------------------
> > National Wilms Tumor Study Group                   206.667.4283
> > Seattle, WA


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

Date: Tue, 12 Oct 1999 13:36:24 -0700
From: Tom Phoenix <rootbeer@redcat.com>
Subject: Re: debugging question
Message-Id: <Pine.GSO.4.10.9910121335140.19155-100000@user2.teleport.com>

On Tue, 12 Oct 1999, Andreas Vierengel wrote:

> Attempt to free unreferenced scalar during global destruction.

Have you seen what the perldiag manpage says about this message? This
generally indicates an error in a compiled module. Cheers!

-- 
Tom Phoenix       Perl Training and Hacking       Esperanto
Randal Schwartz Case:     http://www.rahul.net/jeffrey/ovs/



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

Date: Wed, 13 Oct 1999 09:07:57 +0200
From: Andreas Vierengel <andreas@vierengel.de>
Subject: Re: debugging question
Message-Id: <F89F90F4A2317F4E.7326FC19933BE795.6197ADF532BC9E63@lp.airnews.net>



Tom Phoenix wrote:
> 
> On Tue, 12 Oct 1999, Andreas Vierengel wrote:
> 
> > Attempt to free unreferenced scalar during global destruction.
> 
> Have you seen what the perldiag manpage says about this message? This
> generally indicates an error in a compiled module. Cheers!

Thanks for your help. I searched the whole day yesterday and didn't manage to
find the damn cause.
According to your hint, I tested my used modules and found the cause in the
IO::Select-Module I am using. I created two objects, each with the same
filehandle as parameter to new(). If I quit the program just after these lines,
the error I mentioned above, occured. Nevertheless I didn't want to initialize
two seperate objects with the same filehandle. It was indeed a bug, introduced
by me...
I fixed it, and now it works !

Thanks again.

--Andy


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

Date: Wed, 13 Oct 1999 02:44:48 -0700
From: AF778 <af778NOafSPAM@iname.com.invalid>
Subject: Decoding mime attchs (jpg) in stored email
Message-Id: <2750ac20.23234021@usw-ex0102-012.remarq.com>

Hi guys, my first message here!
Can anyone help me?
I need to decode an e-mail (residing in a plain text file in the Apache
server /mail directory) with JPG attachs in it.
I want to read the plain text file and when i find the mime section,
decode it and save it as a JPG file in some directory.
Does anyone have a script or a pointer to one to do this job?
Thanks you a lot!
Anne


* Sent from RemarQ http://www.remarq.com The Internet's Discussion Network *
The fastest and easiest way to search and participate in Usenet - Free!



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

Date: Wed, 13 Oct 1999 17:12:51 +0100
From: David Cantrell <NukeEmUp@ThePentagon.com>
Subject: Re: Decoding mime attchs (jpg) in stored email
Message-Id: <PK4EOBlSOftJ6Fj9Ij50tziCBzdY@4ax.com>

On Wed, 13 Oct 1999 02:44:48 -0700, AF778
<af778NOafSPAM@iname.com.invalid> said:

>I want to read the plain text file and when i find the mime section,
>decode it and save it as a JPG file in some directory ...

Go to www.cpan.org and search for MIME.

Get to know and love CPAN.  It is your friend.

[Copying newsgroup posts to me by mail is considered rude]

-- 
David Cantrell, part-time Unix/perl/SQL/java techie
                full-time chef/musician/homebrewer
                http://www.ThePentagon.com/NukeEmUp


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

Date: 12 Oct 1999 22:15:09 GMT
From: gej@spamalot.corp.sgi.com (Gene Johannsen)
Subject: Difference between a string and an int
Message-Id: <7u0btd$4d9$1@murrow.corp.sgi.com>

Hey:

I am writing a function in which I would like to take either a one
character long string or an integer less than 256.  The problem I have
is how do I tell the string '1' from the integer 1?

gene
--


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

Date: Tue, 12 Oct 1999 15:49:41 -0700
From: "Lauren Smith" <laurensmith@sprynet.com>
Subject: Re: Difference between a string and an int
Message-Id: <7u0duc$de1$1@brokaw.wa.com>


Gene Johannsen wrote in message <7u0btd$4d9$1@murrow.corp.sgi.com>...
> how do I tell the string '1' from the integer 1?
$str = '1';
$int = 1;
print "they are both ints!\n" if ($str == $int);
print "they are both strings!" if ($str eq $int);

Perl will figure out what you want the type of $str and $int to be from
the context in which it is used.

Lauren




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

Date: Tue, 12 Oct 1999 16:11:13 -0700
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: Difference between a string and an int
Message-Id: <MPG.126d5fed2e871fad98a086@nntp.hpl.hp.com>

In article <7u0btd$4d9$1@murrow.corp.sgi.com> on 12 Oct 1999 22:15:09 
GMT, Gene Johannsen <gej@spamalot.corp.sgi.com> says...
> I am writing a function in which I would like to take either a one
> character long string or an integer less than 256.  The problem I have
> is how do I tell the string '1' from the integer 1?

The simplest answer is that you cannot tell.  Whether you give the value 
'1' or 1, if the expression needs a string, it converts 1 to '1'; if it 
needs a number, it converts '1' to 1.

You can force stringification:  my $string = "$number";
You can force numeralization:   my $number = $string + 0;

But you virtually never need to nor want to.

-- 
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com


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

Date: 12 Oct 1999 23:32:02 GMT
From: sholden@pgrad.cs.usyd.edu.au (Sam Holden)
Subject: Re: Difference between a string and an int
Message-Id: <slrn807h7h.n8o.sholden@pgrad.cs.usyd.edu.au>

On 12 Oct 1999 22:15:09 GMT, Gene Johannsen <gej@spamalot.corp.sgi.com> wrote:
>Hey:
>
>I am writing a function in which I would like to take either a one
>character long string or an integer less than 256.  The problem I have
>is how do I tell the string '1' from the integer 1?

I don't think you can.

You could do bitwise operations and try to work it out, but even that isn't
very useful, due to the magical nature of perl...

Observe the following :
[sholden@mrmph sholden]$ perl -de0

Loading DB routines from perl5db.pl version 1.0401
Emacs support available.

Enter h or `h h' for help.

main::(-e:1):   0
  DB<1> $one_num = 1;

  DB<2> $one_string = '1';

  DB<3> print ~$one_num,"\n",~$one_string,"\n";
4294967294
\xce    <--- paranoia made me change this, it should a character \xce or Î

  DB<4> $one_num == $one_string

  DB<5> print ~$one_num,"\n",~$one_string,"\n";
4294967294
4294967294

Didn't expect a simple comparison to magically change the variable so that
it now gives a different answer did you?

If you solve the problem for 1 and '1', try it for 0 and '0'.

The simple solution is to define two subs, one for integers and one for
strings. Otherwise no matter how you try someone will try to pass 5 and end
up giving you '5'. 

-- 
Sam

Even if you aren't in doubt, consider the mental welfare of the person
who has to maintain the code after you, and who will probably put parens
in the wrong place.	--Larry Wall


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

Date: Tue, 12 Oct 1999 16:43:31 -0700
From: Tom Phoenix <rootbeer@redcat.com>
Subject: Re: Difference between a string and an int
Message-Id: <Pine.GSO.4.10.9910121639420.19155-100000@user2.teleport.com>

On 12 Oct 1999, Gene Johannsen wrote:

> I am writing a function in which I would like to take either a one
> character long string or an integer less than 256.  The problem I have
> is how do I tell the string '1' from the integer 1?

Probably you should design the function differently. You could tell your
caller to always pass a character, or always pass a number. But you could
perhaps use this.

    #!/usr/bin/perl -w

    use strict;

    sub is_str ($) {
	'00' & $_[0] | '00';
    }

    for (1..3, qw/1 2 3/) {
	print "$_ is ", is_str $_ ? "a string.\n" : "a number.\n";
    }

Cheers!

-- 
Tom Phoenix       Perl Training and Hacking       Esperanto
Randal Schwartz Case:     http://www.rahul.net/jeffrey/ovs/



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

Date: Wed, 13 Oct 1999 18:14:45 GMT
From: Makarand Kulkarni <makarand_kulkarni@my-deja.com>
Subject: Re: Difference between a string and an int
Message-Id: <7u2i67$3cn$1@nnrp1.deja.com>

{In article <7u0btd$4d9$1@murrow.corp.sgi.com>,
  gej@spamalot.corp.sgi.com (Gene Johannsen) wrote:
> I am writing a function in which I would like to take either a one
> character long string or an integer less than 256.  The problem I have
> is how do I tell the string '1' from the integer 1?
>

(1) you can use Devel::Peek to look at the internal representation.
(2) print  "$_ is a string \n" if ( ~$_ & $_ ) ne '0' ;
The second technique is described in Item 60 in "Effective perl
Programming ".

--


Sent via Deja.com http://www.deja.com/
Before you buy.


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

Date: Wed, 13 Oct 1999 20:05:29 GMT
From: amonotod <amonotod@netscape.net>
Subject: Re: Difference between a string and an int
Message-Id: <7u2olv$8hu$1@nnrp1.deja.com>



> character long string or an integer less than 256.  The problem I have
> is how do I tell the string '1' from the integer 1?

From the Llama book, by Randal L. Schwartz:
chapter 2, para 1
<snippet>
A scalar is the simplest kind of data that Perl manipulates.  A scalar
is either a number (like 4 or 3.25e20) or a string of characters (like
hello or the Gettysgurg Address).  Although you may think of numbers and
strings as very different things, Perl uses them interchangeably, so
I'll describe them together.
</snippet>

I don't believe you even need to worry, except that you may want to add
0 or multiply by 1 to get rid of non-integer type stuff...

HTH,
amonotod

--
    `\|||/                     amonotod@
      (@@)                     netscape.net
  ooO_(_)_Ooo________________________________
  _____|_____|_____|_____|_____|_____|_____|_____|


Sent via Deja.com http://www.deja.com/
Before you buy.


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

Date: Thu, 14 Oct 1999 02:46:02 GMT
From: nospam.newton@gmx.net (Philip 'Yes, that's my address' Newton)
Subject: Re: Difference between a string and an int
Message-Id: <3804bef1.348905784@news.nikoma.de>

>The simple solution is to define two subs, one for integers and one for
>strings. Otherwise no matter how you try someone will try to pass 5 and end
>up giving you '5'. 

Especially since so many people like to stringify $var when passing it
to a function... as in

   print "$_";
   my_func("$num");

or similar.

Cheers,
Philip
-- 
Philip Newton <nospam.newton@gmx.net>


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

Date: 14 Oct 1999 13:02:07 GMT
From: hymie@lactose.smart.net (hymie!)
Subject: Re: Difference between a string and an int
Message-Id: <7u4k8f$lcd$1@news.smart.net>

In our last episode, the evil Dr. Lacto had captured our hero,
  amonotod <amonotod@netscape.net>, who said:

>> character long string or an integer less than 256.  The problem I have
>> is how do I tell the string '1' from the integer 1?

>Address).  Although you may think of numbers and
>strings as very different things, Perl uses them interchangeably, so
>I'll describe them together.

I think the concern of the original question is:

49 is unambiguously an integer less than 256.  But is '1' an integer less
than 256, or is it a single character whose value is 49?

 ..hymie!         http://www.smart.net/~hymowitz         hymie@lactose.smart.net
===============================================================================
Young lady, in this house, we obey the laws of thermodynamics!  --Homer Simpson
===============================================================================


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

Date: Thu, 14 Oct 1999 20:00:05 GMT
From: amonotod <amonotod@netscape.net>
Subject: Re: Difference between a string and an int
Message-Id: <7u5cnr$5ff$1@nnrp1.deja.com>

  hymie@lactose.smart.net (hymie!) did earlier state:
> 49 is unambiguously an integer less than 256.  But is '1' an integer
less
> than 256, or is it a single character whose value is 49?

I would think that to determine the "value" of the string 1, you would
need a preset table of string to numeric conversions, such as a keyed
array.  Otherwise, the "numeric value" of the string '1' can be found by
adding 0 to it, as in

if ( ( $input++ > 0) && ($input ne "") ) {
  print "Hey, we've got an integer!  It's value is $input \n";
} else { print "Hey, we've got a string, here it is: $input \n"; }

Of course, that precludes the option of numerical strings, like
'abc123', but using tr() or s() for an error code return should let you
know that...

amonotod


--
    `\|||/                     amonotod@
      (@@)                     netscape.net
  ooO_(_)_Ooo________________________________
  _____|_____|_____|_____|_____|_____|_____|_____|


Sent via Deja.com http://www.deja.com/
Before you buy.


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

Date: 14 Oct 1999 23:14:57 GMT
From: gej@spamalot.corp.sgi.com (Gene Johannsen)
Subject: Re: Difference between a string and an int
Message-Id: <7u5o5h$om8$1@murrow.corp.sgi.com>

hymie@lactose.smart.net (hymie!) writes:

| In our last episode, the evil Dr. Lacto had captured our hero,
|   amonotod <amonotod@netscape.net>, who said:
| 
| >> character long string or an integer less than 256.  The problem I have
| >> is how do I tell the string '1' from the integer 1?
| 
| >Address).  Although you may think of numbers and
| >strings as very different things, Perl uses them interchangeably, so
| >I'll describe them together.
| 
| I think the concern of the original question is:
| 
| 49 is unambiguously an integer less than 256.  But is '1' an integer less
| than 256, or is it a single character whose value is 49?

	Precisely.  What I would like (but perl provides no simple
	mechanism for) is something like C's char type.

gene

| 
| ..hymie!         http://www.smart.net/~hymowitz         hymie@lactose.smart.net
| ===============================================================================
| Young lady, in this house, we obey the laws of thermodynamics!  --Homer Simpson
| ===============================================================================
--


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

Date: 16 Sep 99 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 16 Sep 99)
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: The mail to news gateway, and thus the ability to submit articles
| through this service to the newsgroup, has been removed. I do not have
| time to individually vet each article to make sure that someone isn't
| abusing the service, and I no longer have any desire to waste my time
| dealing with the campus admins when some fool complains to them about an
| article that has come through the gateway instead of complaining
| to the source.

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 V9 Issue 1057
**************************************


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