- ANSI C
- PERL
- » Variable handling
- » Miscellaneous
- » POSIX
- » Date/Time
- » Math
- » menu_code_perlcode_strings
- » PCRE
- » Arrays
- » Classes
- » Program execution
- » Directories
- » Filesystem
- » GD
- » Network
- » Sockets
- » DBI
- PHP
- JavaScript
CONTENT
- CHANGES
Szukaj
#top Variable handling¶
code / perl / varhandle
#top Predefined Constants¶
No Predefined Constants here.
#top Datatypes / MACROS¶
No Datatypes here.
#top Variable handling Functions¶
#top int¶
Documentacja online: perldoc.perl.org | www.tutorialspoint.com
Deklaracja funkcji
int()
jest następująca:int EXPR int
Powiązane:
Opis:
Funkcja
int()
zwraca wartość całkowitoliczbową (liczbę całkowitą) podanego jako argument wyrażenia.Example:
zawartość pliku
int.pl
SELECT ALL
#!/usr/bin/perl -w use strict; # force definations for all vars an subroutines use warnings; # force check of unset variables in expressions use diagnostics; # give var/code line number on faults my $self=$0; $self=~s,^.*/,,g; my ($intarg, $intval, $floatarg, $floatval); if ($#ARGV+1<2) { print("Usage: $0 <int-value> <float-value>\n"); print("Examples:\n"); print(" $0 123\n"); print(" $0 -123\n"); exit(1); } $intarg=$ARGV[0]; $floatarg=$ARGV[1]; if ($intarg=~m/^[+-]?[0-9]+$/) { $intval=int($intarg); print("$self: \$intval=int($intarg): \$intval=$intval\n"); } else { print("$self: \$intval=int($intarg): value \$intarg='$intarg' is not numeric !!!\n"); } if ($floatarg=~m/^[+-]?[0-9]+[\.]?[0-9]*$/) { $floatval=$floatarg+0.0; print("$self: \$floatval=$floatarg+0.0: \$floatval=$floatval\n"); } else { print("$self: \$floatval=$floatarg+0.0: value \$floatarg='$floatarg' is not numeric !!!\n"); }
Aby zobaczyć jak działa program należy go uruchomić bez argumentów:
/home/local/code/perlcode/varhandle/int.pl
program wyświetli informacje o sposobie uruchamiania programu:
Usage: /home/local/code/perlcode/varhandle/int.pl <int-value> Examples: /home/local/code/perlcode/varhandle/int.pl 123 /home/local/code/perlcode/varhandle/int.pl -123
jako argument wywołania programu można podać analogiczne jak poniżej argumenty:
/home/local/code/perlcode/varhandle/int.pl 123 123.456 /home/local/code/perlcode/varhandle/int.pl 123a 123.456a /home/local/code/perlcode/varhandle/int.pl 123a 123.45a6 /home/local/code/perlcode/varhandle/int.pl 123a 123.4a56 /home/local/code/perlcode/varhandle/int.pl 123a 123.a456 /home/local/code/perlcode/varhandle/int.pl 123a 123a.456 /home/local/code/perlcode/varhandle/int.pl 12a3 12a3.456 /home/local/code/perlcode/varhandle/int.pl 1a23 1a23.456 /home/local/code/perlcode/varhandle/int.pl a123 a123.456 /home/local/code/perlcode/varhandle/int.pl +123 +123.456 /home/local/code/perlcode/varhandle/int.pl ++123 ++123.456 /home/local/code/perlcode/varhandle/int.pl -123 -123.456 /home/local/code/perlcode/varhandle/int.pl --123 --123.456
rezultat będzie zależny od podanego argumentu wywołania programu:
int.pl: $intval=int(123): $intval=123 int.pl: $floatval=123.456+0.0: $floatval=123.456 int.pl: $intval=int(123a): value $intarg='123a' is not numeric !!! int.pl: $floatval=123.456a+0.0: value $floatarg='123.456a' is not numeric !!! int.pl: $intval=int(123a): value $intarg='123a' is not numeric !!! int.pl: $floatval=123.45a6+0.0: value $floatarg='123.45a6' is not numeric !!! int.pl: $intval=int(123a): value $intarg='123a' is not numeric !!! int.pl: $floatval=123.4a56+0.0: value $floatarg='123.4a56' is not numeric !!! int.pl: $intval=int(123a): value $intarg='123a' is not numeric !!! int.pl: $floatval=123.a456+0.0: value $floatarg='123.a456' is not numeric !!! int.pl: $intval=int(123a): value $intarg='123a' is not numeric !!! int.pl: $floatval=123a.456+0.0: value $floatarg='123a.456' is not numeric !!! int.pl: $intval=int(12a3): value $intarg='12a3' is not numeric !!! int.pl: $floatval=12a3.456+0.0: value $floatarg='12a3.456' is not numeric !!! int.pl: $intval=int(1a23): value $intarg='1a23' is not numeric !!! int.pl: $floatval=1a23.456+0.0: value $floatarg='1a23.456' is not numeric !!! int.pl: $intval=int(a123): value $intarg='a123' is not numeric !!! int.pl: $floatval=a123.456+0.0: value $floatarg='a123.456' is not numeric !!! int.pl: $intval=int(+123): $intval=123 int.pl: $floatval=+123.456+0.0: $floatval=123.456 int.pl: $intval=int(++123): value $intarg='++123' is not numeric !!! int.pl: $floatval=++123.456+0.0: value $floatarg='++123.456' is not numeric !!! int.pl: $intval=int(-123): $intval=-123 int.pl: $floatval=-123.456+0.0: $floatval=-123.456 int.pl: $intval=int(--123): value $intarg='--123' is not numeric !!! int.pl: $floatval=--123.456+0.0: value $floatarg='--123.456' is not numeric !!!
Zmodyfikowany ostatnio: 2013/11/20 22:42:16 (11 lat temu),
textsize: 4,67 kB,
htmlsize: 9,20 kB
Zapraszam do komentowania, zgłaszania sugestii, propozycji, własnych przykładów, ...
Dodaj komentarzKomentarze użytkowników