garbage777 has asked for the wisdom of the Perl Monks concerning the following question:

Hi,
I have a small piece of code that I am trying to improvise. I see that when I remove the  $item->read($libfile) the file is not processed at all. Can you explain why this is so as I am not able to figure out?
#!/usr/bin/perl use strict; use warnings; package main; #my $testObj = Disk::Collection->new(); #$testObj->read(Disk::FileInput->new("inputtextfile")); #$testObj->print_dk_push_back; my $testObj = Disk->new("inputtextfile"); package Disk; sub new { my ($class, $fname) = @_; my $self = { lib => undef }; bless $self, $class; my $lib = Disk::Collection->new(); my $libfile = Disk::FileInput->new($fname); $lib->read($libfile); ($self->{lib}) = ($lib->get_list("JUNK")); return $self; } package Disk::Collection; sub new { my $class = shift; my $self = { line => shift, items => undef, close => undef, }; $self->{line} = "" unless $self->{line}; bless $self, $class; } sub read { my ($self, $libfile) = @_; ... ... my $item = Disk::Collection->new($line); if ($line =~ /{/) { die "syntax error:$lino: $line\n" if $line !~ /{\s*$/; $item->read($libfile); ----> If I remove this line, the file p +rocessing does not happen. print $line, "\n"; } ... ... } ... ...

Update: I just realized I accidentally posted the whole code.
Thanks.

Replies are listed 'Best First'.
Re: Processing file for reading
by bv (Friar) on Sep 14, 2009 at 17:18 UTC

    You didn't write this code, I guess. The read call is recursive. Every time a curly brace is encountered, it recurses again to a new Disk::Collection object. If you remove it, you won't get the depth reflected in whatever you are reading in. All the lines processed should be part of the first Collection. Why are you trying to remove the line? What is your real issue?

    XY Problem?

    print pack("A25",pack("V*",map{1919242272+$_}(34481450,-49737472,6228,0,-285028276,6979,-1380265972)))