ç¹æ®ãã¡ã¤ã«ãã³ãã« DATA
Perl ã³ã³ãã¤ã©ãã³ã¼ãã解éãã段éã§ãã__END__ããããã¯ã__DATA__ãã¨ããè¡ï¼ãã¼ã¯ã³ï¼ãè¦ã¤ããã¨ããã以éãããã¡ã¤ã«ã®çµããã¾ã§ã³ã¼ãã¨ãã¦è§£éãããªããªãã¾ããã³ã¡ã³ãã®ããã«ãä½ãæ¸ãã¦ãã³ã¼ãã¨ãã¦ã¯å®è¡ããã¾ãããããããã®ããã¹ãã¯ãDATAãã¨ããç¹æ®ãªãã¡ã¤ã«ãã³ãã«ã§åç
§ããäºãã§ãã¾ãã
ç¹æ®ãªãã¡ã¤ã«ãã³ãã«ã¨ãã£ã¦ããæ®éã®ãã¡ã¤ã«ãã³ãã«ã¨åãããã«è¡å
¥åæ¼ç®åï¼<>ï¼ãªã©ã§èªã¿è¾¼ãäºãã§ããã®ã§ãã³ã¼ãä¸ã«ç°¡åãªãã¼ã¿ãåãè¾¼ã¿ããæã«ä¾¿å©ã§ãã
ã__END__ãã¨æ¸ããå ´åã¯ãã©ããªããã±ã¼ã¸ã§ã常㫠main ããã±ã¼ã¸ã® DATA ãã¡ã¤ã«ãã³ãã«ï¼main::DATAï¼ã«é¢é£ä»ãããã¾ããã__DATA__ãã¨æ¸ããå ´åã¯ãç¾å¨ã®ããã±ã¼ã¸ã® DATA ãã¡ã¤ã«ãã³ãã«ï¼__PACKAGE__::DATAï¼ã«é¢é£ä»ãããã¾ãã
use strict;
while(<DATA>) { print; }
__END__
Hello, world!
I am Palmo the Perl student.
__END__ 以éã®ããã¹ããã³ã¼ãã¨ãã¦è©ä¾¡ãããã¨ã¨ã©ã¼ã«ãªãã¾ãããå®éã«ã¯ã¨ã©ã¼ã¯çºçãã¾ããã
å®è¡çµæã¯ä»¥ä¸ã®éãã§ãã
Hello, world! I am Palmo the Perl student.
ã¡ããã¨åãã¾ããã(^_^)
__END__ ã __DATA__ ã«å¤ãã¦ãåãã¾ãã
ã§ã¯ãè¤æ°ã®ããã±ã¼ã¸ã§è©¦ãã¦ã¿ã¾ãããã
# Data1.pl
package Data1;
1;
__DATA__
Here is after __DATA__ in Data1
# Data2.pl
package Data2;
1;
__END__
Here is after __END__ in Data2
Data1.pl 㨠Data2.pl ã¨ãã¦ä¿åãã¾ããä¼¼ããããªã³ã¼ãã§ããã__DATA__ 㨠__END__ ã®éããããã¾ãã
ããã±ã¼ã¸ã®æå¾ã«ããå¼ã®å¤ã¯ããã±ã¼ã¸ã®è©ä¾¡çµæã¨ãªãã¾ããããã§ã¯ã1;ãã¨ã㦠1 ãè¿ãã¦ãã¾ããããã±ã¼ã¸ã require ããå ´åãçãè¿ããªãã¨ã¨ã©ã¼ã¨ãªã£ã¦ãã¾ãã®ã§ããã®å¯¾çã§ãã
use strict;
require "Data1.pl";
require "Data2.pl";
sub show($*) {
my ($name, $data_ref) = @_;
print "$name : ";
while(<$data_ref>) { chomp; print; }
print "\n";
}
show("main", main::DATA);
show("Data1", Data1::DATA);
show("Data2", Data2::DATA);
__END__
Here is after __END__ in main
Data1.pl 㨠Data2.pl ãããããèªã¿è¾¼ãã§ãã¾ããshow é¢æ°ã¯ååã¨ãã¡ã¤ã«ãã³ãã«ãåãåã£ã¦ããã®å
容ã表示ããé¢æ°ã§ãããã¡ã¤ã«ãã³ãã«ã¯åã°ããã¨ãã¦åãåã£ã¦ãã¾ãã
ãããåããã©ã«ãã«ä¿åãã¦å®è¡ããã¨â¦â¦ã¨ã©ã¼ãçºçãã¾ãã
main : Here is after __END__ in main Data1 : Here is after __DATA__ in Data1 readline() on unopened filehandle at D:\home\palmo\data.pl line 8. Data2 :
Data2::DATA ãèªã¿è¾¼ããã¨ãã¦ããéããã¦ããªããã¡ã¤ã«ãã³ãã«ãã¨ã¨ã©ã¼ã«ãªã£ã¦ãã¾ãã¾ãããã¤ã¾ããData2::DATA ã¯åå¨ããªãã¨ããäºã§ããããã¯ãData2 㧠__END__ ã使ã£ã¦ãã¦ãmain::DATA ã«é¢é£ä»ããããããã§ããã
試ãã« Data2 ã®ä¸ã® __END__ ã __DATA__ ã«ç½®ãæããã¨ãä¸æãåãã¾ãã
# Data2.pl
package Data2;
1;
__DATA__
Here is after __DATA__ in Data2
main : Here is after __END__ in main Data1 : Here is after __DATA__ in Data1 Data2 : Here is after __DATA__ in Data2
ã¡ã¤ã³ããã±ã¼ã¸ä»¥å¤ã§ã¯ __DATA__ ã使ãæ¹ãç¡é£ããã§ããã(^_^)