Variable definition help needed

A

Anthony Litton

OK, this is in reference to my CgiComments problem, which asked for help on
on the 16th. The following lines are at the beginning of the script:

my($cgiquery) = new CGI;
my($blog_id) = $cgiquery->param('blog_id');

'blog_id' is an eighteen digit number, and for some reason I'm having
problems creating correctly named files. The final digit is always 0,
mysteriously. Would it be possible for me to define $blog_id as being only
the first seventeen, or sixteen digits of 'blog_id'?

Thanks for your help.
 
M

Mina Naguib

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Anthony said:
OK, this is in reference to my CgiComments problem, which asked for help on
on the 16th. The following lines are at the beginning of the script:

my($cgiquery) = new CGI;
my($blog_id) = $cgiquery->param('blog_id');

'blog_id' is an eighteen digit number, and for some reason I'm having
problems creating correctly named files. The final digit is always 0,
mysteriously. Would it be possible for me to define $blog_id as being only
the first seventeen, or sixteen digits of 'blog_id'?

Thanks for your help.

Look into the substr function.

perldoc substr or http://www.perldoc.com/perl5.8.0/pod/func/substr.html


-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.1 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQE/GBd9eS99pGMif6wRAi3hAJ4mku5N75BaQ+Dhgq+kxWPTI5YfhgCgrAPu
yJhrqjxc9BiVKLdg5TySfCM=
=is+H
-----END PGP SIGNATURE-----
 
A

Anthony Litton

Mina Naguib wrote:
|| -----BEGIN PGP SIGNED MESSAGE-----
|| Hash: SHA1
||
|| Anthony Litton wrote:
||| OK, this is in reference to my CgiComments problem, which asked for
||| help on on the 16th. The following lines are at the beginning of
||| the script:
|||
||| my($cgiquery) = new CGI;
||| my($blog_id) = $cgiquery->param('blog_id');
|||
||| 'blog_id' is an eighteen digit number, and for some reason I'm
||| having problems creating correctly named files. The final digit is
||| always 0, mysteriously. Would it be possible for me to define
||| $blog_id as being only the first seventeen, or sixteen digits of
||| 'blog_id'?
|||
||| Thanks for your help.
|||
||
|| Look into the substr function.
||
|| perldoc substr or
|| http://www.perldoc.com/perl5.8.0/pod/func/substr.html
||
||
|| -----BEGIN PGP SIGNATURE-----
|| Version: GnuPG v1.2.1 (GNU/Linux)
|| Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
||
|| iD8DBQE/GBd9eS99pGMif6wRAi3hAJ4mku5N75BaQ+Dhgq+kxWPTI5YfhgCgrAPu
|| yJhrqjxc9BiVKLdg5TySfCM=
|| =is+H
|| -----END PGP SIGNATURE-----

You are my new favourite person. Thank you. I've replaced the line:
my($blog_id) = $cgiquery->param('blog_id');

with the lines
my($blog_ida) = $cgiquery->param('blog_id');
my($blog_id) = substr $blog_ida, 0, 16;

I'm sure that can be done more elegantly, but it works and I'm extremely
happy. Thanks again,
Anthony
 
M

Mina Naguib

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
|| Anthony Litton wrote:
||| OK, this is in reference to my CgiComments problem, which asked for
||| help on on the 16th. The following lines are at the beginning of
||| the script:
|||
||| my($cgiquery) = new CGI;
||| my($blog_id) = $cgiquery->param('blog_id');
|||
||| 'blog_id' is an eighteen digit number, and for some reason I'm
||| having problems creating correctly named files. The final digit is
||| always 0, mysteriously. Would it be possible for me to define
||| $blog_id as being only the first seventeen, or sixteen digits of
||| 'blog_id'?
|||
||| Thanks for your help.
|||
||
|| Look into the substr function.
||
|| perldoc substr or
|| http://www.perldoc.com/perl5.8.0/pod/func/substr.html
You are my new favourite person. Thank you. I've replaced the line:
my($blog_id) = $cgiquery->param('blog_id');

with the lines
my($blog_ida) = $cgiquery->param('blog_id');
my($blog_id) = substr $blog_ida, 0, 16;

No need for intermediate variables:

my $blog_id = substr($cgiquery->param('blog_id'), 0, 16);

Otherwise, good job :)


-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.1 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQE/GDX8eS99pGMif6wRAqZVAKD0sSttEdgjhphtcHLNZv/ZfBMFeQCghT00
eKE45zWG767Xi3EfOwpr9O0=
=4JGT
-----END PGP SIGNATURE-----
 
E

Eric J. Roode

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

OK, this is in reference to my CgiComments problem, which asked for
help on on the 16th. The following lines are at the beginning of the
script:

my($cgiquery) = new CGI;
my($blog_id) = $cgiquery->param('blog_id');

'blog_id' is an eighteen digit number, and for some reason I'm having
problems creating correctly named files. The final digit is always 0,
mysteriously. Would it be possible for me to define $blog_id as being
only the first seventeen, or sixteen digits of 'blog_id'?

Before you put a band-aid on the problem, perhaps you should investigate
why the last digit is "mysteriously" always 0. Perhaps at some point along
the way, the id is being interpreted as a string, causing some precision to
be lost? If so, simply truncating your string is not going to be a good
solution.

- --
Eric
$_ = reverse sort qw p ekca lre Js reh ts
p, $/.r, map $_.$", qw e p h tona e; print

-----BEGIN PGP SIGNATURE-----
Version: PGPfreeware 7.0.3 for non-commercial use <http://www.pgp.com>

iQA/AwUBPxlBpWPeouIeTNHoEQJAKACg1G3LYqcpk/m6djWIdmDNadWcxMcAnAz8
XE8NhsmaLwLftckqQ3+aRKr6
=AYlA
-----END PGP SIGNATURE-----
 
A

Anthony Litton

Bob Walton wrote:
|| Anthony Litton wrote:
||
||| OK, this is in reference to my CgiComments problem, which asked for
||| help on on the 16th. The following lines are at the beginning of
||| the script:
|||
||| my($cgiquery) = new CGI;
||| my($blog_id) = $cgiquery->param('blog_id');
|||
||| 'blog_id' is an eighteen digit number, and for some reason I'm
||| having problems creating correctly named files. The final digit is
||| always 0, mysteriously. Would it be possible for me to define
||| $blog_id as being only the first seventeen, or sixteen digits of
||| 'blog_id'?
|| ...
||
||
|| The chances are pretty good that somewhere along the way, you did
|| something to $blog_id which converted it to a number and back.
|| Something like incrementing it, adding a constant to it, or applying
|| any other operator that forces a numeric context. If you don't do
|| any of that, it will stay a string, and the last digit would not
|| change. This scenario is likely because many platforms Perl runs on
|| have about 17 digits of precision in their floating point values --
|| and Perl may use such values when it stores scalars in numeric
|| context.
||
||
|| --
|| Bob Walton

Actually, my question was answered in the other thread, in
comp.lang.javascript. I should have come back here sooner. The solution was
to ensure that blog_id was treated as a string from the start, so:
<a href="javascript:cgicomments(<$BlogItemNumber$>)">
becomes
<a href="javascript:cgicomments('<$BlogItemNumber$>')">

And that has solved the problem.

Thanks very much for replying,
Anthony.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,781
Messages
2,569,615
Members
45,303
Latest member
Ketonara

Latest Threads

Top