请高手帮助几道 perl 编程题# JobHunting - 待字闺中
i*5
1 楼
1)write a perl script to merge data files with identical format based on
first field. it takes location of two or more input data files as command
line argument, merges and prints merged data to stdout.the result has to be
sorted on first field. You can assume that all data are sorted in all input
files. You are not allowed to use UNIX “sort” command. Each input tick
data file could have several hundred gigabytes. You should optimize your
solution for memory and CPU usage.
datafile1.txt
2009.12.11,ROD,12.26,90.48
2010.11.10,RKP,220.10,29.03
datafile2.txt
2009.11.11,ROD,12.26,90.48
2009.12.18,RKP,220.10,29.03
2)Writing a PERL script to find the certain pattern /zoo/ in the file and
remove the previous 2 lines including the pattern line;
The test file:
bad 1
zoo
good 1
good 2
good 3
bad 2
bad 3
zoo
good 4
good 5
good 6
bad 4
bad 5
zoo
good 7
bad 6
bad 7
zoo
good 8
3)Run the perl script below. As you will see, by changing the value in %h3,
the script also changes the value for %h4, please provide a brief
explanation. Please also provide a generalized solution for this issue.
my %h1 = ( k1 => "v1" );
my %h2 = ( k2 => \%h1 );
my %h3 = ( k3 => \%h2 );
my %h4 = %h3;
print "h3\n";
foreach my $i ( keys %h3 ) {
print "$i => $h3{$i}\n";
foreach my $j (keys %{$h3{$i}}) {
print " $j => $h3{$i}{$j}\n";
foreach my $k ( keys %{$h3{$i}{$j}}) {
print " $k => $h3{$i}{$j}{$k}\n";
}
}
}
$h3{k3}{k2}{k1} = "v2";
print "h4\n";
foreach my $i ( keys %h4 ) {
print "$i => $h4{$i}\n";
foreach my $j (keys %{$h4{$i}}) {
print " $j => $h4{$i}{$j}\n";
foreach my $k ( keys %{$h4{$i}{$j}}) {
print " $k => $h4{$i}{$j}{$k}\n";
}
}
}
多谢!
first field. it takes location of two or more input data files as command
line argument, merges and prints merged data to stdout.the result has to be
sorted on first field. You can assume that all data are sorted in all input
files. You are not allowed to use UNIX “sort” command. Each input tick
data file could have several hundred gigabytes. You should optimize your
solution for memory and CPU usage.
datafile1.txt
2009.12.11,ROD,12.26,90.48
2010.11.10,RKP,220.10,29.03
datafile2.txt
2009.11.11,ROD,12.26,90.48
2009.12.18,RKP,220.10,29.03
2)Writing a PERL script to find the certain pattern /zoo/ in the file and
remove the previous 2 lines including the pattern line;
The test file:
bad 1
zoo
good 1
good 2
good 3
bad 2
bad 3
zoo
good 4
good 5
good 6
bad 4
bad 5
zoo
good 7
bad 6
bad 7
zoo
good 8
3)Run the perl script below. As you will see, by changing the value in %h3,
the script also changes the value for %h4, please provide a brief
explanation. Please also provide a generalized solution for this issue.
my %h1 = ( k1 => "v1" );
my %h2 = ( k2 => \%h1 );
my %h3 = ( k3 => \%h2 );
my %h4 = %h3;
print "h3\n";
foreach my $i ( keys %h3 ) {
print "$i => $h3{$i}\n";
foreach my $j (keys %{$h3{$i}}) {
print " $j => $h3{$i}{$j}\n";
foreach my $k ( keys %{$h3{$i}{$j}}) {
print " $k => $h3{$i}{$j}{$k}\n";
}
}
}
$h3{k3}{k2}{k1} = "v2";
print "h4\n";
foreach my $i ( keys %h4 ) {
print "$i => $h4{$i}\n";
foreach my $j (keys %{$h4{$i}}) {
print " $j => $h4{$i}{$j}\n";
foreach my $k ( keys %{$h4{$i}{$j}}) {
print " $k => $h4{$i}{$j}{$k}\n";
}
}
}
多谢!