#!/usr/bin/perl
use strict;
use warnings;
use 5.010;
my $count = 0;
while (<DATA>) {
chomp;
for (split/abc /) {
$count++;
say "value $count=", ($count == 1 ? '' : ' '), $_;
}
}
__DATA__
123 abc xyz
456 abc sdf
789 abc ghj
あるいは、=
の後にスペースを省略している行の判定に、おそらくより多くのデータ駆動型のアプローチ:
#!/usr/bin/perl
use strict;
use warnings;
use 5.010;
my %nospace = (
1 => 1,
);
my $count = 0;
while (<DATA>) {
chomp;
for (split/abc /) {
$count++;
say "value $count=", ($nospace{$count} ? '' : ' '), $_;
}
}
__DATA__
123 abc xyz
456 abc sdf
789 abc ghj
こんにちはSruthi、あなたは自分で何かをしようとしたのですか?あなたが私たちにあなたが試したことを見せることができれば、そしてあなたが直面している問題は*素晴らしいことでしょう。一方、あなたは['How to ask']チェックするべきです(http://stackoverflow.com/help/how-to-ask) –
これは[XY問題]のように聞こえます(http://meta.stackexchange.com/質問/ 66377/what-is-the-xy-problem)。あなたは何を達成しようとしていますか?あなたがしていることを私たちに伝えるためのコードを私たちに示してもらえますか? – Sobrique