sanjay nayak has asked for the wisdom of the Perl Monks concerning the following question:
When i run the above program, the output comes asuse strict; use warnings; use DDD::test2; my $incr = 0; my @array=""; undef $/; open DATA, "san.txt" or die $!; my @blocks = map { [ split /\n/ ] } ( split /(?=ITEM NO:)/, ( map { s/\#.*\n//; $_ } <DATA> )[0] ); while(1) { @array = @{ $blocks[$incr] }; if (@array eq "") { print "There is no item remaining in the file"; last; } test2::REQUEST(@array); $incr++; } #test2.pm contains package test2; sub REQUEST (@) { my @array=@_; print "@array\n"; } 1; #Suppose san.txt file contains #This is the ITEM file #This is a perl config file # I am ok ITEM NO:1 [aaa] 111 ffff [bbb] 222 [ccc] 333 #This not taken ITEM NO:2 [ddd] 444 [eee] 555 0000 [fff] 666 #This is not taken ITEM NO:3 [ddd1] 4441 [eee1] 5551 [fff1] 6661 # I am sanjay ITEM NO:4 ... ... ...
Can you suggest me some suitable code so that while readingITEM NO:1 [aaa] 111 ffff [bbb] 222 [ccc] 333 #This not taken ITEM NO:2 [ddd] 444 [eee] 555 0000 [fff] 666 #This is not taken ITEM NO:3 [ddd1] 4441 [eee1] 5551 [fff1] 6661 # I am sanjay ITEM NO:4 ... ... ... Can't use an undefined value as an ARRAY reference at test1.pl line 12 +, <DATA> chunk 1
and also how can i operate the if block."Can't use an undefined value as an ARRAY reference at test1.pl line 1 +2, <DATA> chunk 1"
Please Suggest me.if (@array eq "") { print "There is no item remaining in the file"; last; }
20061023 Janitored by Corion: Added formatting, put data in code tags
2006-10-23 Retitled by planetscape, as per Monastery guidelines
Original title: 'Suggest me some suitable code?'
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Problems reading records from file
by bingos (Vicar) on Oct 23, 2006 at 07:53 UTC | |
|
Re: Problems reading records from file
by reneeb (Chaplain) on Oct 23, 2006 at 07:55 UTC | |
by sanjay nayak (Sexton) on Oct 23, 2006 at 10:23 UTC | |
|
Re: Problems reading records from file
by jwkrahn (Abbot) on Oct 23, 2006 at 09:19 UTC |