CONTENT
  • CHANGES
Szukaj
counter

#top Miscellaneous


code / perl / misc

#top Predefined Constants


No Predefined Constants here.





#top Datatypes / MACROS


#top ARGV


Documentacja online: perldoc.perl.org | www.tutorialspoint.com

Deklaracja zmiennej globalnej ARGV jest następująca:
ENV

Powiązane:

Opis:
description

Example:
zawartość pliku ARGV.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 ($key);



if ($#ARGV+1<=0) {
	print("Usage: $self [arg1 [, arg2 [, arg3 [, ...]]]]\n");
	print("Examples:\n");
	print("       $self arg1\n");
	print("       $self arg1, arg2\n");
	print("       $self arg1, arg2, arg3\n");
}

print""$self: foreach \$key (0..$#ARGV):\n");
foreach $key (0..$#ARGV) {
	print("$self: \@ARGV[$key]=|$ARGV[$key]|\n");
}
print""$self: foreach \$key (0..$#ARGV): end.\n");

Aby zobaczyć jak działa program należy go uruchomić bez argumentów:
/home/local/code/perlcode/misc/ARGV.pl
program wyświetli informacje o sposobie uruchamiania programu:
Usage: /home/local/code/perlcode/misc/ARGV.pl [arg1 [, arg2 [, arg3 [, ...]]]]
Examples:
       /home/local/code/perlcode/misc/ARGV.pl arg1
       /home/local/code/perlcode/misc/ARGV.pl arg1, arg2
       /home/local/code/perlcode/misc/ARGV.pl arg1, arg2, arg3
ARGV.pl: foreach $key (0..-1):
ARGV.pl: foreach $key (0..-1): end.

jako argument wywołania programu można podać analogiczne jak poniżej argumenty:
/home/local/code/perlcode/misc/ARGV.pl arg1
/home/local/code/perlcode/misc/ARGV.pl arg1 arg2
/home/local/code/perlcode/misc/ARGV.pl arg1 arg2 arg3
rezultat będzie zależny od podanego argumentu wywołania programu:
ARGV.pl: foreach $key (0..0):
ARGV.pl: @ARGV[0]=|arg1|
ARGV.pl: foreach $key (0..0): end.

ARGV.pl: foreach $key (0..1):
ARGV.pl: @ARGV[0]=|arg1|
ARGV.pl: @ARGV[1]=|arg2|
ARGV.pl: foreach $key (0..1): end.

ARGV.pl: foreach $key (0..2):
ARGV.pl: @ARGV[0]=|arg1|
ARGV.pl: @ARGV[1]=|arg2|
ARGV.pl: @ARGV[2]=|arg3|
ARGV.pl: foreach $key (0..2): end.



#top BEGIN


Documentacja online: perldoc.perl.org | www.tutorialspoint.com

Deklaracja sekcji BEGIN jest następująca:
BEGIN

Powiązane:
BEGIN(), END(),

Opis:
description

Example:
zawartość pliku BEGIN.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 ($textarg);



BEGIN {
	# executed always at start
	my $self=$0; $self=~s,^.*/,,g;
	print("$self: BEGIN code section\n");
}

END {
	# atexit() is C-specific: use END {} instead
	print("$self: END code section\n");
}

if ($#ARGV+1<1) {
	print("Usage: $0 <argument>\n");
	print("Examples:\n");
	print("       $0 test\n");
	print("       $0 exit\n");
	print("       $0 END\n");
	exit(1);
}

$textarg=$ARGV[0];

if ($textarg eq 'END') {
	exit(0);
}

print""$self: before IF\n");

if ($textarg eq 'exit') {
	print("$self: exit(0): call\n");
	exit(0);
	print("$self: exit(0): end.\n");
}

print""$self: after IF\n");

Aby zobaczyć jak działa program należy go uruchomić bez argumentów:
/home/local/code/perlcode/misc/BEGIN.pl
program wyświetli informacje o sposobie uruchamiania programu:
BEGIN.pl: BEGIN code section
Usage: /home/local/code/perlcode/misc/BEGIN.pl <argument>
Examples:
       /home/local/code/perlcode/misc/BEGIN.pl test
       /home/local/code/perlcode/misc/BEGIN.pl exit
       /home/local/code/perlcode/misc/BEGIN.pl END
BEGIN.pl: END code section

jako argument wywołania programu można podać analogiczne jak poniżej argumenty:
/home/local/code/perlcode/misc/BEGIN.pl test
/home/local/code/perlcode/misc/BEGIN.pl exit
/home/local/code/perlcode/misc/BEGIN.pl END
rezultat będzie zależny od podanego argumentu wywołania programu:
BEGIN.pl: BEGIN code section
BEGIN.pl: before IF
BEGIN.pl: after IF
BEGIN.pl: END code section

BEGIN.pl: BEGIN code section
BEGIN.pl: before IF
BEGIN.pl: exit(0): call
BEGIN.pl: END code section

BEGIN.pl: BEGIN code section
BEGIN.pl: END code section



#top defined


Documentacja online: perldoc.perl.org | www.tutorialspoint.com
Documentacja online: perldoc.perl.org | www.tutorialspoint.com

Deklaracja funkcji defined() jest następująca:
defined

Powiązane:
delete(), defined(), exists(),

Opis:
description



#top END


Documentacja online: perldoc.perl.org | www.tutorialspoint.com

Deklaracja sekcji END jest następująca:
END

Powiązane:
BEGIN(), END(),

Opis:
sub atexit {
    unimpl "atexit() is C-specific: use END {} instead";
}
Sekcja END jest odpowiednikiem C-funkcji atexit() i analogicznie jak funkcja atexit() sekcja END wykonywana jest zawsze przy zakończeniu programu.



#top __END__


Documentacja online: perldoc.perl.org | www.tutorialspoint.com

Deklaracja sekcji __END__ jest następująca:
__END__

Powiązane:
BEGIN(), END(),

Opis:
#!/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

#
# perl code here
#

__END__

all lines here are treatet as comment

Sekcja __END__ jest ... .



#top ENV


Documentacja online: perldoc.perl.org | www.tutorialspoint.com

Deklaracja zmiennej globalnej ENV jest następująca:
ENV

Powiązane:

Opis:
description

Example:
zawartość pliku ENV.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 ($key);



if ($#ARGV+1<0) {
	print("Usage: $0\n");
	exit(1);
}

print""$self: for \$key (sort(keys(\%ENV))):\n");
for $key (sort(keys(%ENV))) {
	print("$self: \%ENV{$key}=|$ENV{$key}|\n");
}
print""$self: for \$key (sort(keys(\%ENV))): end.\n");

Aby zobaczyć jak działa program należy go uruchomić bez argumentów:
/home/local/code/perlcode/misc/ENV.pl
program wyświetli stosowne informacje o sposobie działania:
ENV.pl: for $key (sort(keys(%ENV))):
ENV.pl: %ENV{COLORTERM}=||
ENV.pl: %ENV{DESKTOP_SESSION}=|default|
ENV.pl: %ENV{DISPLAY}=|:0|
ENV.pl: %ENV{DM_CONTROL}=|/var/run/xdmctl|
ENV.pl: %ENV{GREP_OPTIONS}=|--color=auto|
ENV.pl: %ENV{GS_LIB}=|/home/user/.fonts|
ENV.pl: %ENV{G_BROKEN_FILENAMES}=|1|
ENV.pl: %ENV{HISTCONTROL}=|ignoredups|
ENV.pl: %ENV{HISTFILE}=|/home/user/.kde/share/apps/konsole/sessions/myphp-docs---hist13|
ENV.pl: %ENV{HISTSIZE}=|10000|
ENV.pl: %ENV{HOME}=|/home/user|
ENV.pl: %ENV{HOSTNAME}=|*****|
ENV.pl: %ENV{IFS}=|
|
ENV.pl: %ENV{INPUTRC}=|/etc/inputrc|
ENV.pl: %ENV{KDEDIR}=|/usr|
ENV.pl: %ENV{KDE_FULL_SESSION}=|true|
ENV.pl: %ENV{KDE_IS_PRELINKED}=|1|
ENV.pl: %ENV{KDE_MULTIHEAD}=|false|
ENV.pl: %ENV{KDE_NO_IPV6}=|1|
ENV.pl: %ENV{KONSOLE_DCOP}=|DCOPRef(konsole-6613,konsole)|
ENV.pl: %ENV{KONSOLE_DCOP_SESSION}=|DCOPRef(konsole-6613,session-12)|
ENV.pl: %ENV{LANG}=|pl_PL.UTF-8|
ENV.pl: %ENV{LANGUAGE}=|pl_PL.UTF-8|
ENV.pl: %ENV{LESS}=| -R -R|
ENV.pl: %ENV{LESSOPEN}=||/usr/bin/lesspipe.sh %s|
ENV.pl: %ENV{LOGNAME}=|user|
ENV.pl: %ENV{LS_COLORS}=|no=00:fi=00:di=00;34:ln=00;36:pi=40;33:so=00;35:bd=40;33;01:cd=40;33;01:or=01;05;37;41:mi=01;05;37;41:ex=00;32:*.cmd=00;32:*.exe=00;32:*.com=00;32:*.btm=00;32:*.bat=00;32:*.sh=00;32:*.csh=00;32:*.tar=00;31:*.tgz=00;31:*.arj=00;31:*.taz=00;31:*.lzh=00;31:*.zip=00;31:*.z=00;31:*.Z=00;31:*.gz=00;31:*.bz2=00;31:*.bz=00;31:*.tz=00;31:*.rpm=00;31:*.cpio=00;31:*.jpg=00;35:*.gif=00;35:*.bmp=00;35:*.xbm=00;35:*.xpm=00;35:*.png=00;35:*.tif=00;35:|
ENV.pl: %ENV{MAIL}=|/var/spool/mail/user|
ENV.pl: %ENV{PAGER}=|less|
ENV.pl: %ENV{PATH}=|/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:/usr/X11R6/bin:/usr/X11R6/sbin:/home/local/sbin:/home/local/bin|
ENV.pl: %ENV{PS1}=|[\u@\h \W]\$ |
ENV.pl: %ENV{PWD}=|/home/user|
ENV.pl: %ENV{QTDIR}=|/usr/lib/qt-3.3|
ENV.pl: %ENV{QTINC}=|/usr/lib/qt-3.3/include|
ENV.pl: %ENV{QTLIB}=|/usr/lib/qt-3.3/lib|
ENV.pl: %ENV{SESSION_MANAGER}=|local/*****:/tmp/.ICE-unix/5908|
ENV.pl: %ENV{SHELL}=|/bin/bash|
ENV.pl: %ENV{SHLVL}=|6|
ENV.pl: %ENV{SSH_AGENT_PID}=|5813|
ENV.pl: %ENV{SSH_AUTH_SOCK}=|/tmp/ssh-dvKJZw5791/agent.5791|
ENV.pl: %ENV{TERM}=|xterm|
ENV.pl: %ENV{USER}=|user|
ENV.pl: %ENV{WINDOWID}=|50331655|
ENV.pl: %ENV{XDG_CONFIG_DIRS}=|/etc/kde/xdg:/etc/xdg|
ENV.pl: %ENV{XDM_MANAGED}=|/var/run/xdmctl/xdmctl-:0,maysd,mayfn,sched,rsvd,method=classic|
ENV.pl: %ENV{_}=|/home/local/code/perlcode/misc/ENV.pl|
ENV.pl: for $key (sort(keys(%ENV))): end.





#top Miscellaneous Functions


#top alarm


Documentacja online: perldoc.perl.org | www.tutorialspoint.com

Deklaracja funkcji alarm() jest następująca:
alarm EXPR
alarm

Powiązane:
alarm(), ualarm(),

Opis:
description

Example:
zawartość pliku alarm.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 ($alarmtime, $sleeptime);



if ($#ARGV+1<2) {
	print("Usage: $0 <alarmtime> <sleeptime>\n");
	print("Examples:\n");
	print("       $0 5 10\n");
	print("       $0 10 5\n");
	exit(1);
}

$alarmtime=int($ARGV[0]);
$sleeptime=int($ARGV[1]);

print""$self: eval { alarm($alarmtime); sleep($sleeptime); };\n");
eval {
print""$self: alarm($alarmtime);\n");
alarm($alarmtime);
print""$self: sleep($sleeptime);\n");
sleep($sleeptime);
};

print""$self: alarm(0);\n");
alarm(0);

Aby zobaczyć jak działa program należy go uruchomić bez argumentów:
/home/local/code/perlcode/misc/alarm.pl
program wyświetli informacje o sposobie uruchamiania programu:
Usage: /home/local/code/perlcode/misc/alarm.pl <alarmtime> <sleeptime>
Examples:
       /home/local/code/perlcode/misc/alarm.pl 5 10
       /home/local/code/perlcode/misc/alarm.pl 10 5

jako argument wywołania programu można podać analogiczne jak poniżej argumenty:
/home/local/code/perlcode/misc/alarm.pl 5 10
/home/local/code/perlcode/misc/alarm.pl 10 5
rezultat będzie zależny od podanego argumentu wywołania programu:
alarm.pl: eval { alarm(5); sleep(10); };
alarm.pl: alarm(5);
alarm.pl: sleep(10);
Alarm clock

alarm.pl: eval { alarm(10); sleep(5); };
alarm.pl: alarm(10);
alarm.pl: sleep(5);
alarm.pl: alarm(0);



#top caller


Documentacja online: perldoc.perl.org | www.tutorialspoint.com

Deklaracja funkcji caller() jest następująca:
caller

Powiązane:

Opis:
description

Example:
zawartość pliku caller.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;



sub callerinfo {
	my ($package, $filename, $line, $subroutine, $hasargs, $wantarray, $evaltext, $is_require, $hints, $bitmask, $hinthash);
	my (@LIST, $key);
	
	($package, $filename, $line)=caller();
	print("$self: (\$package, \$filename, \$line)=caller(): \$package=$package \$filename=$filename, \$line=$line\n");
	
	($package, $filename, $line, $subroutine, $hasargs, $wantarray, $evaltext, $is_require, $hints, $bitmask, $hinthash)=caller(0);
	if (!defined($package   )) { $package   ='undef!!!'; }
	if (!defined($filename  )) { $filename  ='undef!!!'; }
	if (!defined($line      )) { $line      ='undef!!!'; }
	if (!defined($subroutine)) { $subroutine='undef!!!'; }
	if (!defined($hasargs   )) { $hasargs   ='undef!!!'; }
	if (!defined($wantarray )) { $wantarray ='undef!!!'; }
	if (!defined($evaltext  )) { $evaltext  ='undef!!!'; }
	if (!defined($is_require)) { $is_require='undef!!!'; }
	if (!defined($hints     )) { $hints     ='undef!!!'; }
	if (!defined($bitmask   )) { $bitmask   ='undef!!!'; }
	if (!defined($hinthash  )) { $hinthash  ='undef!!!'; }
	print("$self: (\$package, \$filename, \$line, \$subroutine, \$hasargs, \$wantarray, \$evaltext, \$is_require, \$hints, \$bitmask, \$hinthash)=caller(0): \$package=$package \$filename=$filename \$line=$line \$subroutine=$subroutine \$hasargs=$hasargs \$wantarray=$wantarray, \$evaltext=$evaltext \$is_require=$is_require \$hints=$hints \$bitmask=$bitmask \$hinthash=$hinthash\n");
	print("$self:\n");
	
	@LIST=caller();
	print("$self: \@LIST=caller(): \@LIST(".($#LIST+1).")=\n");
	foreach $key (0..$#LIST) {   if (defined($LIST[$key])) { print("$self: \$LIST[$key]=$LIST[$key]\n"); } else { print("$self: \$LIST[$key]=undef!!!\n"); }   }
	print("$self:\n");
	
	@LIST=caller(0);
	print("$self: \@LIST=caller(0): \@LIST(".($#LIST+1).")=\n");
	foreach $key (0..$#LIST) {   if (defined($LIST[$key])) { print("$self: \$LIST[$key]=$LIST[$key]\n"); } else { print("$self: \$LIST[$key]=undef!!!\n"); }   }
	print("$self:\n");
}

if ($#ARGV+1<0) {
	print("Usage: $0\n");
	exit(1);
}

&callerinfo();

Aby zobaczyć jak działa program należy go uruchomić bez argumentów:
/home/local/code/perlcode/misc/caller.pl
program wyświetli stosowne informacje o sposobie działania:
caller.pl: ($package, $filename, $line)=caller(): $package=main $filename=/home/local/code/perlcode/misc/caller.pl, $line=51
caller.pl: ($package, $filename, $line, $subroutine, $hasargs, $wantarray, $evaltext, $is_require, $hints, $bitmask, $hinthash)=caller(0): $package=main $filename=/home/local/code/perlcode/misc/caller.pl $line=51 $subroutine=main::callerinfo $hasargs=1 $wantarray=undef!!!, $evaltext=undef!!! $is_require=undef!!! $hints=2 $bitmask=UUUUUUUUUUU $hinthash=undef!!!
caller.pl:
caller.pl: @LIST=caller(): @LIST(3)=
caller.pl: $LIST[0]=main
caller.pl: $LIST[1]=/home/local/code/perlcode/misc/caller.pl
caller.pl: $LIST[2]=51
caller.pl:
caller.pl: @LIST=caller(0): @LIST(10)=
caller.pl: $LIST[0]=main
caller.pl: $LIST[1]=/home/local/code/perlcode/misc/caller.pl
caller.pl: $LIST[2]=51
caller.pl: $LIST[3]=main::callerinfo
caller.pl: $LIST[4]=1
caller.pl: $LIST[5]=undef!!!
caller.pl: $LIST[6]=undef!!!
caller.pl: $LIST[7]=undef!!!
caller.pl: $LIST[8]=2
caller.pl: $LIST[9]=UUUUUUUUUUU
caller.pl:



#top defined


Documentacja online: perldoc.perl.org | www.tutorialspoint.com

Deklaracja funkcji defined() jest następująca:
defined

Powiązane:
defined(), undef(),

Opis:
description

Example:
zawartość pliku defined.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 ($value);



if ($#ARGV+1<1) {
	print("Usage: $0 <arg0>\n");
	print("Examples:\n");
	print("       $0 test\n");
	print("       $0 undef\n");
	print("       $0 text\n");
	exit(1);
}

if (defined($value)) { print("$self: \$value=$value\n"); }
else                 { print("$self: \$value: undefined!!!\n"); }

$value=$ARGV[0];
if (defined($value)) { print("$self: \$value=\$ARGV[0]: \$value=$value\n"); }
else                 { print("$self: \$value=\$ARGV[0]: \$value: undefined!!!\n"); }
undef($value);
if (defined($value)) { print("$self: \$value=\$ARGV[0]: undef(\$value): \$value=$value\n"); }
else                 { print("$self: \$value=\$ARGV[0]: undef(\$value): \$value: undefined!!!\n"); }

$value=$ARGV[0];
if (defined($value)) { print("$self: \$value=\$ARGV[0]: \$value=$value\n"); }
else                 { print("$self: \$value=\$ARGV[0]: \$value: undefined!!!\n"); }
$value=undef();
if (defined($value)) { print("$self: \$value=\$ARGV[0]: \$value=undef(): \$value=$value\n"); }
else                 { print("$self: \$value=\$ARGV[0]: \$value=undef(): \$value: undefined!!!\n"); }

Aby zobaczyć jak działa program należy go uruchomić bez argumentów:
/home/local/code/perlcode/misc/defined.pl
program wyświetli informacje o sposobie uruchamiania programu:
Usage: /home/local/code/perlcode/misc/defined.pl <arg0>
Examples:
       /home/local/code/perlcode/misc/defined.pl test
       /home/local/code/perlcode/misc/defined.pl undef
       /home/local/code/perlcode/misc/defined.pl text


jako argument wywołania programu można podać analogiczne jak poniżej argumenty:
/home/local/code/perlcode/misc/defined.pl test
/home/local/code/perlcode/misc/defined.pl undef
/home/local/code/perlcode/misc/defined.pl text
rezultat będzie zależny od podanego argumentu wywołania programu:
defined.pl: $value: undefined!!!
defined.pl: $value=$ARGV[0]: $value=test
defined.pl: $value=$ARGV[0]: undef($value): $value: undefined!!!
defined.pl: $value=$ARGV[0]: $value=test
defined.pl: $value=$ARGV[0]: $value=undef(): $value: undefined!!!

defined.pl: $value: undefined!!!
defined.pl: $value=$ARGV[0]: $value=undef
defined.pl: $value=$ARGV[0]: undef($value): $value: undefined!!!
defined.pl: $value=$ARGV[0]: $value=undef
defined.pl: $value=$ARGV[0]: $value=undef(): $value: undefined!!!

defined.pl: $value: undefined!!!
defined.pl: $value=$ARGV[0]: $value=text
defined.pl: $value=$ARGV[0]: undef($value): $value: undefined!!!
defined.pl: $value=$ARGV[0]: $value=text
defined.pl: $value=$ARGV[0]: $value=undef(): $value: undefined!!!



#top die


Documentacja online: perldoc.perl.org | www.tutorialspoint.com

Deklaracja funkcji die() jest następująca:
die LIST

Powiązane:
die(), exit(),

Opis:
description

Example:
zawartość pliku die.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 ($diearg);



if ($#ARGV+1<1) {
	print("Usage: $0 <print-message-when-exit>\n");
	print("Examples:\n");
	print("       $0 \"die script with message\"; echo \$?\n");
	exit(1);
}

$diearg=$ARGV[0];

print""$self: die($diearg): call\n");
die($diearg);
print""$self: die($diearg): end.\n");

Aby zobaczyć jak działa program należy go uruchomić bez argumentów:
/home/local/code/perlcode/misc/die.pl
program wyświetli informacje o sposobie uruchamiania programu:
Usage: /home/local/code/perlcode/misc/die.pl <print-message-when-exit>
Examples:
       /home/local/code/perlcode/misc/die.pl "die script with message"; echo $?

jako argument wywołania programu można podać analogiczne jak poniżej argumenty:
/home/local/code/perlcode/misc/die.pl "die script with message"; echo $?
rezultat będzie zależny od podanego argumentu wywołania programu:
die.pl: die(die script with message): call
Uncaught exception from user code:
        die script with message at /home/local/code/perlcode/misc/die.pl line 24.
 at /home/local/code/perlcode/misc/die.pl line 24
255



#top exit


Documentacja online: perldoc.perl.org | www.tutorialspoint.com

Deklaracja funkcji exit() jest następująca:
exit EXPR
exit

Powiązane:
die(), exit(),

Opis:
description

Example:
zawartość pliku exit.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);



if ($#ARGV+1<1) {
	print("Usage: $0 <exit-int-value>\n");
	print("Examples:\n");
	print("       $0 0; echo \$?\n");
	print("       $0 1; echo \$?\n");
	print("       $0 2; echo \$?\n");
	print("       $0 3; echo \$?\n");
	exit(1);
}


$intarg=$ARGV[0];
$intval=int($intarg);
print""$self: exit($intval): call\n");
exit$intval$intval);
print""$self: exit($intval): end.\n");

Aby zobaczyć jak działa program należy go uruchomić bez argumentów:
/home/local/code/perlcode/misc/exit.pl
program wyświetli informacje o sposobie uruchamiania programu:
Usage: /home/local/code/perlcode/misc/exit.pl <exit-int-value>
Examples:
       /home/local/code/perlcode/misc/exit.pl 0; echo $?
       /home/local/code/perlcode/misc/exit.pl 1; echo $?
       /home/local/code/perlcode/misc/exit.pl 2; echo $?
       /home/local/code/perlcode/misc/exit.pl 3; echo $?

jako argument wywołania programu można podać analogiczne jak poniżej argumenty:
/home/local/code/perlcode/misc/exit.pl 0; echo $?
/home/local/code/perlcode/misc/exit.pl 1; echo $?
/home/local/code/perlcode/misc/exit.pl 2; echo $?
/home/local/code/perlcode/misc/exit.pl 3; echo $?
rezultat będzie zależny od podanego argumentu wywołania programu:
exit.pl: exit(0): call
0

exit.pl: exit(1): call
1

exit.pl: exit(2): call
2

exit.pl: exit(3): call
3



#top nanosleep


Documentacja online: perldoc.perl.org | www.tutorialspoint.com

Deklaracja funkcji nanosleep() jest następująca:
nanosleep

Powiązane:
nanosleep(), sleep(), usleep(),

Opis:
description



#top ref


Documentacja online: perldoc.perl.org | www.tutorialspoint.com

Deklaracja funkcji ref() jest następująca:
ref EXPR

Powiązane:
ref(), wantarray(),

Opis:
description
Returns a non-empty string if EXPR is a reference, the empty string otherwise.
If EXPR is not specified, $_ will be used. The value returned depends on the
type of thing the reference is a reference to.

Builtin types include:
1. SCALAR
2. ARRAY
3. HASH
4. CODE
5. REF
6. GLOB
7. LVALUE
8. FORMAT
9. IO
10. VSTRING
11. Regexp

Example:
zawartość pliku ref.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 ($vals, @LIST, %HASH, $globref, $coderef, $callref);

if ($#ARGV+1<0) {
	print("Usage: $0\n");
	exit(1);
}

sub callfunc {
	return 1;
}


open(FILEHANDLE,"/dev/null");
$globref=\*FILEHANDLE;
close(FILEHANDLE);
$coderef=sub { return 1; };
$callref=\&callfunc;
print""$self: ref(\$vals)=".ref(\$vals)."\n");
print""$self: ref(\@LIST)=".ref(\@LIST)."\n");
print""$self: ref(\%HASH)=".ref(\%HASH)."\n");
open(FILEHANDLE,"/dev/null");
$globref=\*FILEHANDLE;
close(FILEHANDLE);
$coderef=sub { return 1; };
$callref=\&callfunc;
print""$self: ref(\\\$vals)=".ref(\$vals)."\n");
print""$self: ref(\\\@LIST)=".ref(\@LIST)."\n");
print""$self: ref(\\\%HASH)=".ref(\%HASH)."\n");
print""$self: \$globref=\\\*FILEHANDLE;      ref(\$globref)=".ref($globref)."\n");
print""$self: \$coderef=sub { return 1; }; ref(\$coderef)=".ref($coderef)."\n");
print""$self: \$callref=\\\&callfunc;        ref(\$callref)=".ref($callref)."\n");

Aby zobaczyć jak działa program należy go uruchomić bez argumentów:
/home/local/code/perlcode/misc/ref.pl
program wyświetli informacje o sposobie działania programu:
ref.pl: ref(\$vals)=SCALAR
ref.pl: ref(\@LIST)=ARRAY
ref.pl: ref(\%HASH)=HASH
ref.pl: ref($globref)=REF $globref=*FILEHANDLE
ref.pl: ref($coderef)=REF $coderef=sub { return 1; };
ref.pl: ref($callref)=REF $callref=$callfunc



#top sleep


Documentacja online: perldoc.perl.org | www.tutorialspoint.com

Deklaracja funkcji sleep() jest następująca:
sleep

Powiązane:
nanosleep(), sleep(), usleep(),

Opis:
description

Example:
zawartość pliku sleep.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

use Time::HiRes qw(usleep nanosleep); # Time::HiRes::clock_nanosleep(): unimplemented in this platform, "stat" is not exported by the Time::HiRes module



my $self=$0; $self=~s,^.*/,,g;
my ($sleeptime, $usleeptime, $nsleeptime);



if ($#ARGV+1<3) {
	print("Usage: $0 <sleepinttime> <usleepinttime> <nanosleepinttime>\n");
	print("Examples:\n");
	print("       $0 3 2000000 1000000000\n");
	exit(1);
}

$sleeptime=int($ARGV[0]);
$usleeptime=int($ARGV[1]);
$nsleeptime=int($ARGV[2]);

print""$self: sleep($sleeptime): call\n");
sleep($sleeptime);
print""$self: sleep($sleeptime): end.\n");

print""$self: usleep($usleeptime): call\n");
usleep($usleeptime);
print""$self: usleep($usleeptime): end.\n");

print""$self: nanosleep($nsleeptime): call\n");
nanosleep($nsleeptime);
print""$self: nanosleep($nsleeptime): end.\n");

Aby zobaczyć jak działa program należy go uruchomić bez argumentów:
/home/local/code/perlcode/misc/sleep.pl
program wyświetli informacje o sposobie uruchamiania programu:
Usage: /home/local/code/perlcode/misc/sleep.pl <sleepinttime> <usleepinttime> <nanosleepinttime>
Examples:
       /home/local/code/perlcode/misc/sleep.pl 3 2000000 1000000000

jako argument wywołania programu można podać analogiczne jak poniżej argumenty:
/home/local/code/perlcode/misc/sleep.pl 3 2000000 1000000000
rezultat będzie zależny od podanego argumentu wywołania programu:
sleep.pl: sleep(3): call
sleep.pl: sleep(3): end.
sleep.pl: usleep(2000000): call
sleep.pl: usleep(2000000): end.
sleep.pl: nanosleep(1000000000): call
sleep.pl: nanosleep(1000000000): end.



#top ualarm


Documentacja online: perldoc.perl.org | www.tutorialspoint.com

Deklaracja funkcji ualarm() jest następująca:
ualarm EXPR
ualarm

Powiązane:
alarm(), ualarm(),

Opis:
description

Example:
zawartość pliku ualarm.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

use Time::HiRes qw(usleep ualarm); # Time::HiRes::clock_nanosleep(): unimplemented in this platform, "stat" is not exported by the Time::HiRes module



my $self=$0; $self=~s,^.*/,,g;
my ($alarmtime, $sleeptime);



if ($#ARGV+1<2) {
	print("Usage: $0 <alarmtime> <sleeptime>\n");
	print("Examples:\n");
	print("       $0 5 10\n");
	print("       $0 10 5\n");
	print("       $0 1800 5\n");
	print("       $0 1801 5\n");
	exit(1);
}

$alarmtime=$ARGV[0];
$sleeptime=$ARGV[1];

print""$self: eval { ualarm($alarmtime); usleep($sleeptime); };\n");
eval {
print""$self: ualarm($alarmtime);\n");
ualarm($alarmtime);
print""$self: usleep($sleeptime);\n");
usleep($sleeptime);
};

print""$self: ualarm(0);\n");
ualarm(0);

Aby zobaczyć jak działa program należy go uruchomić bez argumentów:
/home/local/code/perlcode/misc/ualarm.pl
program wyświetli informacje o sposobie uruchamiania programu:
Usage: /home/local/code/perlcode/misc/ualarm.pl <alarmtime> <sleeptime>
Examples:
       /home/local/code/perlcode/misc/ualarm.pl 5 10
       /home/local/code/perlcode/misc/ualarm.pl 10 5

jako argument wywołania programu można podać analogiczne jak poniżej argumenty:
/home/local/code/perlcode/misc/ualarm.pl 5 10
/home/local/code/perlcode/misc/ualarm.pl 10 5
/home/local/code/perlcode/misc/ualarm.pl 1800 5
/home/local/code/perlcode/misc/ualarm.pl 1801 5
rezultat będzie zależny od podanego argumentu wywołania programu:
ualarm.pl: eval { ualarm(5); usleep(10); };
ualarm.pl: ualarm(5);
ualarm.pl: usleep(10);
Alarm clock

ualarm.pl: eval { ualarm(10); usleep(5); };
ualarm.pl: ualarm(10);
ualarm.pl: usleep(5);
Alarm clock

ualarm.pl: eval { ualarm(1800); usleep(5); };
ualarm.pl: ualarm(1800);
ualarm.pl: usleep(5);
Alarm clock

ualarm.pl: eval { ualarm(1801); usleep(5); };
ualarm.pl: ualarm(1801);
ualarm.pl: usleep(5);
ualarm.pl: ualarm(0);



#top undef


Documentacja online: perldoc.perl.org | www.tutorialspoint.com

Deklaracja funkcji undef() jest następująca:
undef

Powiązane:
defined(), undef(),

Opis:
description



#top usleep


Documentacja online: perldoc.perl.org | www.tutorialspoint.com

Deklaracja funkcji usleep() jest następująca:
usleep

Powiązane:
nanosleep(), sleep(), usleep(),

Opis:
description



#top wantarray


Documentacja online: perldoc.perl.org | www.tutorialspoint.com

Deklaracja funkcji wantarray() jest następująca:
wantarray

Powiązane:
ref(), wantarray(),

Opis:
description

Example:
zawartość pliku wantarray.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 (@VALLIST, $valscalar, $void);



sub callreturn {
	my (@SUBLIST, $subscalar);
	
	@SUBLIST=('val1','val2','val3');
	$subscalar=join(' ', @SUBLIST);
	if (wantarray()) { print("callreturn(): return \@SUBLIST;\n"); return @SUBLIST; }
	if (defined(wantarray())) { print("callreturn(): return \$subscalar;\n"); return $subscalar; }
	print("callreturn(): return;\n");
	return;
}

if ($#ARGV+1<0) {
	print("Usage: $0\n");
	exit(1);
}

print""$self: \@VALLIST=&callreturn():\n");
@VALLIST=&callreturn();
print""$self: \@VALLIST=&callreturn(): ref(\@VALLIST)=".ref(\@VALLIST)."\n");
print""$self:\n");
print""$self: \$valscalar=&callreturn():\n");
$valscalar=&callreturn();
print""$self: \$valscalar=&callreturn(): ref(\$valscalar)=".ref(\$valscalar)."\n");
print""$self:\n");
print""$self: &callreturn():\n");
&callreturn();
print""$self: &callreturn():\n");

Aby zobaczyć jak działa program należy go uruchomić bez argumentów:
/home/local/code/perlcode/misc/wantarray.pl
program wyświetli stosowne informacje o sposobie działania:
wantarray.pl: @VALLIST=&callreturn():
callreturn(): return @SUBLIST;
wantarray.pl: @VALLIST=&callreturn(): ref(@VALLIST)=ARRAY
wantarray.pl:
wantarray.pl: $valscalar=&callreturn():
callreturn(): return $subscalar;
wantarray.pl: $valscalar=&callreturn(): ref($valscalar)=SCALAR
wantarray.pl:
wantarray.pl: &callreturn():
callreturn(): return;
wantarray.pl: &callreturn():





Zmodyfikowany ostatnio: 2014/11/21 13:09:25 (9 lat temu), textsize: 35,3 kB, htmlsize: 69,5 kB

Zapraszam do komentowania, zgłaszania sugestii, propozycji, własnych przykładów, ...
Dodaj komentarzKomentarze użytkowników