Re: Convert int for string

2007-08-26 Thread Xavier Noria

On Aug 26, 2007, at 3:22 AM, Randal L. Schwartz wrote:

Perl is a very strongly typed language.  The problem is that people  
keep
thinking number or string is a type in Perl.  It isn't.  The  
type is
called scalar.  Other types are array and hash and  
filehandle and

dirhandle and built-in object and user-defined object.


In that line, I think Perl is not as dynamically typed as other  
scripting languages, in the sense that sigils do put types in the  
source code somehow. Since Perl tries to give meaning almost to  
anything and context allows to add a scalar to an array, the compiler  
does not complain that much in practice. But from a formal point of  
view there are types in the code.


-- fxn


--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




Re: Convert int for string

2007-08-26 Thread Peter Scott
On Sat, 25 Aug 2007 18:22:13 -0700, (Randal L. Schwartz) wrote:
 Jeff == Jeff Pang [EMAIL PROTECTED] writes:
 
 Jeff Perl isn't a strong type language like C,so you don't have the need to
 Jeff convert the variable type distinctly.
 
 Perl is a very strongly typed language.  The problem is that people keep
 thinking number or string is a type in Perl.  It isn't.  The type is
 called scalar.  Other types are array and hash and filehandle and
 dirhandle and built-in object and user-defined object.
 
 Please stop with the perl is loosely typed nonsense.

The term strong typing is so ill-defined as to make this an
angels-dancing-on-a-pinhead discussion and unlikely to lead to any
enlightenment.  Even the Wikipedia definition says that there *is* no
accepted definition and some of the common usages contradict each other. 

Under the interpretations I subscribe to I couldn't think of a language
that would qualify as weakly typed if Perl were strongly typed, so I
believe that you're apply some other interpretation.  In keeping with
the multiple interpretations, there doesn't appear to be any consensus
about Perl's strength of typing.  http://use.perl.org/~Ovid/journal/22311
sums it up well for me.

-- 
Peter Scott
http://www.perlmedic.com/
http://www.perldebugged.com/


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




Re: Convert int for string

2007-08-26 Thread Xavier Noria

On Aug 26, 2007, at 3:52 PM, Peter Scott wrote:


The term strong typing is so ill-defined as to make this an
angels-dancing-on-a-pinhead discussion and unlikely to lead to any
enlightenment.  Even the Wikipedia definition says that there *is* no
accepted definition and some of the common usages contradict each  
other.


I remember MJD has a nice slice about it. I don't know whether it's  
online though.


-- fxn


--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




Convert int for string

2007-08-25 Thread Rodrigo Tavares
Hello,

In many languages there is a function for convert int
for string. Ho I can do it in Perl ?

Best regards,

Rodrigo Faria


  Flickr agora em português. Você clica, todo mundo vê.
http://www.flickr.com.br/

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




Re: Convert int for string

2007-08-25 Thread Jeff Pang
2007/8/26, Rodrigo Tavares [EMAIL PROTECTED]:
 Hello,

 In many languages there is a function for convert int
 for string. Ho I can do it in Perl ?


Hello,

Perl isn't a strong type language like C,so you don't have the need to
convert the variable type distinctly.
for example,

my $x = 123;
print $x * 2;

would print 246 correctly,perl treat $x as an int type variable.

but when you say,

my $x = 123;
print $x . '@abc.com';

would print [EMAIL PROTECTED] joining $x with a string,Perl treat $x as
a char variable.

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




Re: Convert int for string

2007-08-25 Thread Rodrick Brown
On 8/25/07, Jeff Pang [EMAIL PROTECTED] wrote:
 2007/8/26, Rodrigo Tavares [EMAIL PROTECTED]:
  Hello,
 
  In many languages there is a function for convert int
  for string. Ho I can do it in Perl ?
 

 Hello,

 Perl isn't a strong type language like C,so you don't have the need to
 convert the variable type distinctly.
 for example,

 my $x = 123;
 print $x * 2;

 would print 246 correctly,perl treat $x as an int type variable.

 but when you say,

 my $x = 123;
 print $x . '@abc.com';

 would print [EMAIL PROTECTED] joining $x with a string,Perl treat $x as
 a char variable.


There are certain situations where you can just call int($x) for some
operations.
 --
 To unsubscribe, e-mail: [EMAIL PROTECTED]
 For additional commands, e-mail: [EMAIL PROTECTED]
 http://learn.perl.org/





-- 
Rodrick R. Brown
http://www.rodrickbrown.com

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




Re: Convert int for string

2007-08-25 Thread Rodrigo Tavares
Hello Jeff,

See this simple script:

print Enter with the fisrst number\n;
my $num = STDIN;

How I can to convert variable $num, in string ?

Best regards,

Rodrigo Faria




--- Jeff Pang [EMAIL PROTECTED] escreveu:

 2007/8/26, Rodrigo Tavares
 [EMAIL PROTECTED]:
  Hello,
 
  In many languages there is a function for convert
 int
  for string. Ho I can do it in Perl ?
 
 
 Hello,
 
 Perl isn't a strong type language like C,so you
 don't have the need to
 convert the variable type distinctly.
 for example,
 
 my $x = 123;
 print $x * 2;
 
 would print 246 correctly,perl treat $x as an int
 type variable.
 
 but when you say,
 
 my $x = 123;
 print $x . '@abc.com';
 
 would print [EMAIL PROTECTED] joining $x with a
 string,Perl treat $x as
 a char variable.
 



  Flickr agora em português. Você clica, todo mundo vê.
http://www.flickr.com.br/

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




Re: Convert int for string

2007-08-25 Thread Jeff Pang
2007/8/26, Rodrigo Tavares [EMAIL PROTECTED]:
 Hello Jeff,

 See this simple script:

 print Enter with the fisrst number\n;
 my $num = STDIN;

 How I can to convert variable $num, in string ?


This is really depend on what operation context the variable is in.
As I've said,when you use it in string operation environment,it is a
string then.

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




Re: Convert int for string

2007-08-25 Thread Rodrigo Tavares
Hello,

I want to convert the int for string, then use the
function lenght, and return the size of string.

How It is possible ?

Best regards,

Rodrigo Faria


--- Jeff Pang [EMAIL PROTECTED] escreveu:

 2007/8/26, Rodrigo Tavares
 [EMAIL PROTECTED]:
  Hello Jeff,
 
  See this simple script:
 
  print Enter with the fisrst number\n;
  my $num = STDIN;
 
  How I can to convert variable $num, in string ?
 
 
 This is really depend on what operation context the
 variable is in.
 As I've said,when you use it in string operation
 environment,it is a
 string then.
 



  Flickr agora em português. Você clica, todo mundo vê.
http://www.flickr.com.br/

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




Re: Convert int for string

2007-08-25 Thread Mr. Shawn H. Corey

Rodrigo Tavares wrote:

Hello,

I want to convert the int for string, then use the
function lenght, and return the size of string.

How It is possible ?


Perl automatically converts a number to and string (and back again) as needed.  
To get the length of its string, use the length function:

 my $length = length( $number );

Example of automatic conversions:
#!/usr/bin/perl

use strict;
use warnings;

# set $num to a number
my $num = 123;
# convert it to a string for printing
print $num\n;

# concatenate the character zero to its end
$num .= '0';
# print the string
print $num\n;

# divide the string by 2
$num /= 2;
# convert it to a string for printing
print $num\n;

# convert to a string and get its length
print length($num), \n;

__END__


--
Just my 0.0002 million dollars worth,
 Shawn

For the things we have to learn before we can do them, we learn by doing them.
 Aristotle

If you think Terrans are comprehensible, you don't understand them.
 Great Fang Talphon

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




Re: Convert int for string

2007-08-25 Thread Tom Phoenix
On 8/25/07, Rodrigo Tavares [EMAIL PROTECTED] wrote:

 In many languages there is a function for convert int
 for string. Ho I can do it in Perl ?

It's so easy to put a number into a string, we don't have a function
for it. We simply interpolate:

  my $age = 6 * 7; # or any other number
  print I'm $age years old.\n;

The number in $age is converted to a string form (42) and
interpolated into the string, which is then printed. Is that what you
were needing?

When you need more control over how numbers become strings, printf and
its cousin sprintf offer many flexible options. For example, it's nice
to have leading zeroes when formatting minutes and seconds:

  # Result looks like  1:02:03
  my $hhmmss = sprintf %2d:%02d:%02d, $h, $m, $s;

Hope this helps!

--Tom Phoenix
Stonehenge Perl Training

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




Re: Convert int for string

2007-08-25 Thread Dr.Ruud
Rodrigo Tavares schreef:

 print Enter with the fisrst number\n;
 my $num = STDIN;

 How I can to convert variable $num, in string ?

$num already contains a string. When you input 1 2 3 Enter, it will
contain 123\n.

With chomp() you can remove the newline, but you can also use int(), see
`perldoc -f int`.

-- 
Affijn, Ruud

Gewoon is een tijger.


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




Re: Convert int for string

2007-08-25 Thread Randal L. Schwartz
 Jeff == Jeff Pang [EMAIL PROTECTED] writes:

Jeff Perl isn't a strong type language like C,so you don't have the need to
Jeff convert the variable type distinctly.

Perl is a very strongly typed language.  The problem is that people keep
thinking number or string is a type in Perl.  It isn't.  The type is
called scalar.  Other types are array and hash and filehandle and
dirhandle and built-in object and user-defined object.

Please stop with the perl is loosely typed nonsense.

-- 
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
[EMAIL PROTECTED] URL:http://www.stonehenge.com/merlyn/
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/