ãã¡ã¤ã«ãã³ãã«ã®æ¦å¿µãç解ãã
Perl
›
ãã¡ã¤ã«å ¥åºå
›
here
ãPerlã«ããããã¡ã¤ã«ãã³ãã«ã®æ¦å¿µã¯ãããããã®ã§ã解説ãã¦ããã¾ãã
ãã¡ã¤ã«ãã³ãã«ã¯å®ä½ã§ã¯ãªãã¦æ¦å¿µçãªãã®
ãPerlã§ãã¡ã¤ã«ãã³ãã«ã¨ãã£ãå ´åã¯ãPerlããã¡ã¤ã«ãã³ãã«ã¨ãã¦èªèããè¤æ°ã®å®ä½ã®ãã¨ããã£ã¦ãã¾ãããã¡ã¤ã«ãã³ãã«ã¨ããå®ä½ãããããã§ã¯ãªãã®ã§ãã
Perlãããã¡ã¤ã«ãã³ãã«ã¨ãã¦èªèãããã®
- ã·ã³ãã«( FH )
- åã°ãã( *FH )
- åã°ããã¸ã®ãªãã¡ã¬ã³ã¹( \*FH )
- IO::Handleã¯ã©ã¹ã®ãªãã¸ã§ã¯ã
- IO::Handleãªãã¸ã§ã¯ããç¶æ¿ããã¯ã©ã¹ã®ãªãã¸ã§ã¯ã( IO::File ãªã© )
ãPerlãããã¡ã¤ã«ãã³ãã«ã¨ãã¦èªèãããã®ã¯ãä¸è¨ã®5ã¤ã§ãã以ä¸ã®è¨è¿°ã¯ãã¹ã¦æå¹ã§ãã
# 1. ã·ã³ãã« FH open(FH, "<", $file) or die "$!"; # 2. åã°ãã *FH open(*FH, "<", $file) or die "$!"; # 3. åã°ããã¸ã®ãªãã¡ã¬ã³ã¹ \*FH my $fh = \*FH; open($fh, "<", $file) or die "$!"; # 4. IO::Handleãªãã¸ã§ã¯ã use IO::Handle; my $fh = IO::Handle->new; open( $fh, "<", $file ) or die "$!"; # 5. IO::Fileãªãã¸ã§ã¯ã( IO::Handleãç¶æ¿ ) use IO::File; my $fh = IO::File->new; open($fh, "<", $file) or die "$!";
ç¾ä»£çãªãã¡ã¤ã«ãªã¼ãã³ã®æ¸ãæ¹
ãç¾ä»£çãªãã¡ã¤ã«ãªã¼ãã³ã®æ¸ãæ¹ã¯ã
open(my $fh, "<", $file) or die "Can't open file $file:$!";
ã§ãã
ãæªå®ç¾©ã®ã¹ã«ã©ã¼å¤æ°ãopené¢æ°ã®ç¬¬ä¸å¼æ°ã«æ¸¡ãããã¨ãç¡ååã°ããã¸ã®ãªãã¡ã¬ã³ã¹ãèªåçã«çæããã¾ããã3.åã°ããã¸ã®ãªãã¡ã¬ã³ã¹( \*FH )ãã¨åãè¨è¿°ã§ãmy $fh = \*FH; ã®é¨åãèªåçã«è¡ã£ã¦ããã ãã§ãã(ããã¯ãPerlã®ç¾ä»£ã®å®è£ ã§ãå°æ¥çã«ã¯IO::Handleã¸ã®ãªãã¸ã§ã¯ããèªåçæããããã«ãªãããããã¾ããã)
Perl
›
ãã¡ã¤ã«å ¥åºå
›
here