Perl/ひな形

Top / Perl / ひな形

簡易スクリプト

#!/usr/bin/perl

=head1 NAME

=head1 SYNOPSIS

=head1 DESCRIPTION

=head1 OPTIONS

=cut

use strict;

モジュール

=head1 NAME

=head1 VERSION

=head1 SYNOPSIS

=head1 DESCRIPTION

=head1 METHODS

=cut

package ;
use strict;
use warnings;



1;

__END__

=head1 BUGS

=head1 SEE ALSO

=head1 AUTHOR

=head1 COPYRIGHT AND LICENSE

=cut

Unittest (Test::Class)

#!/usr/bin/perl

package XXXX::Test;

use strict;
use warnings;
use Test::More;
use base qw(Test::Class);
use XXXX;

XXXX::Test->runtests();

sub setup : Test(setup)
{
	my $self = shift;
	# 適当につっこむのが慣習?
	$self->{'test_xxxx'} = 〜;
}

sub test_xxxx : Test(no_plan)
{
	my $self = shift;
	my $xxxx = $self->{'test_xxx'};

	ok(1 == 1);
	is(1, 1);
}

日付を保持したまま更新

#!/usr/bin/perl

use strict;

foreach (@ARGV) {
	&main($_);
}

sub main
{
	my $path = shift;
	my $text = '';

	my ($atime,$utime) = (stat $path)[8,9];
	open(IN, $path) or die("can't open $path.");
	while (my $line = <IN>) {

		# change $line

		$text .= $line;
	}
	close(IN);

	open(OUT, ">$path") or die("can't write $path.");
	print OUT $text;
	close(OUT);
	utime($atime, $utime, $path);
}

ファイル名を書き換え

#!/usr/bin/perl

use strict;

foreach (@ARGV) {
	&main($_);
}

sub main
{
	my $src = shift;
	my $dest = $src;

	# change $dest

	return if ($dest eq $src);
	if (-e $dest) {
		warn("$dest already exists.\n");
		return;
	}
	rename $src, $dest;
}

トップ   差分 バックアップ リロード   一覧 単語検索 最終更新   ヘルプ   最終更新のRSS
Last-modified: 2006-02-15 (水) 01:46:42 (4965d)