Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses

Re^2: Symbolic Reference in Method Call

by kennethk (Abbot)
on Jun 27, 2013 at 18:27 UTC ( #1041073=note: print w/replies, xml ) Need Help??

in reply to Re: Symbolic Reference in Method Call
in thread Symbolic Reference in Method Call

You are quite close to a clean (IMHO) solution here. Rather than using symbolic references, I would just use a hash to store the writer references:
use diagnostics; use File::Slurp; use RTF::Writer; my @destinations = ('IAs','Defs','Term','Payoffs','RWs','Boilerplate2' +); my $targetfolder = "contract/new2"; opendir(DIR, "$targetfolder"); my @files = readdir(DIR); closedir(DIR); my $count = 0; foreach $file (@files) { if ($file =~ /rtf/i) { my %writer; for my $dest (@destinations) { $writer{$dest} = RTF::Writer->new_to_file("contract +/$dest/$file"); } my $contract = read_file("$targetfolder/$file"); my @paragraphs = split('cf', $contract); foreach $clause (@paragraphs) { my @lines = split("\n", "$clause"); if ($lines[0] =~ /^\d$/){ my $colour = $lines[0]; my $goal = $writer{$destinations[$colour]}; + #NO-LONGER-PROBLEMATIC CODE my $destinationfolder = ("contract/$destinations +[$colour]"); # Also changed this one foreach $line (@lines) { if ($line =~ /^\s*\w/ && $line !~ /^\d$ +/){ $goal->paragraph ( "$line", ); } } } } } $count++; }
Untested, though it passes strict. I think there are some simplifications you could make in the logic in your @lines loop as well.

Remember that objects are just a subclass of scalars; and consider perusing perlreftut and perllol.

#11929 First ask yourself `How would I do this without a computer?' Then have the computer do it the same way.

Replies are listed 'Best First'.
Re^3: Symbolic Reference in Method Call
by EclecticScion (Novice) on Jun 28, 2013 at 15:23 UTC

    I had some trouble for a while with a bug relating to my first program, but I can now confirm that the above code works perfectly. Thanks very much!

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1041073]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (12)
As of 2017-05-23 21:38 GMT
Find Nodes?
    Voting Booth?