Re: [問題] 讀取檔案的內容
我試了一下,$raw_read_in是指讀入的檔案的變數吧?
所以我改成這樣
-------
use strict;
use Data::Dumper ;
my %count_of_si ; #統計si出現的次數
my %p_of_si ; #統計si為0的次數
my $raw_read_in = "aaa_inc"; #讀入的檔案
if (-e $raw_read_in)
{
print "$raw_read_in exist\n";
open (FILE , "<". $raw_read_in);
while(<FILE>)
{
my @filtered = ( $raw_read_in =~ m/^ [\s\t]* (\d+) [\s\t]+ (\d+) /x);
next if ( !defined $filtered[0] ) ;
$count_of_si{ $filtered[1] }++ if $filtered[1] == 1;
$p_of_si{ $filtered[1] }++ if $filtered[0] == 0 ;
}
}
print Dumper( @count_of_si{ sort keys %count_of_si } ) ;
print "\n" ;
print Dumper( @p_of_si{ sort keys %p_of_si} ) ;
------
但是讀不到內容,我試著print %count_of_si也沒有內容
想請問@filtered = ( $raw_read_in =~ m/^ [\s\t]* (\d+) [\s\t]+ (\d+) /x);
是指將$1與$2丟到@filtered裡嗎?
那這樣我print @filtered應該也要有內容才是
可是也沒有內容@@"
可否幫忙解答一下
感恩~
※ 引述《flu (Crazy Rhythm)》之銘言:
: 順便說一下, eq, lt, gt是拿來作字串比對用的
: ==, <, > 才是拿來作數字比對用的
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 111.253.110.221
討論串 (同標題文章)
Perl 近期熱門文章
PTT數位生活區 即時熱門文章