Grey Fox has asked for the wisdom of the Perl Monks concerning the following question:
Hello Fellow Monks of perl;
As Bartles & Jaymes would say "Thank you for your support"
I'm having difficulties in declaring the $text field as global to the entire program. I've separated the slurp of the file into a separate scope, so that I can read the conversion parameter's line by line. How can I use the same $text that I slurped, in my while statement. What I have is a list of bogus names and clock numbers that I am globally replacing in my text file.
#!/usr/lib/perl use strict; use warnings; use Data::Dumper; { my $file1 = '/home/greyfox/data/TBLLOTUSNOTESPYRAMID.txt'; print "$file1\n"; local( $/, *INPUT ); open( INPUT, $file1 ) or die "Can't open $file1 $!\n"; our $text = <INPUT>; close INPUT or die "Can't close INPUT $!"; } my $file2 = '/home/greyfox/data/ConvTable.txt'; open (FD, $file2) or die "Can't open $file2 $!"; while (my $line = <FD>) { my @data = split (/\t/, $line); $data[0] =~ s/[ ]+$//g; $data[0] =~ s/,./,/g; our $text =~ s/$data[0]/$data[2]/g; our $text =~ s/$data[1]/$data[3]/g; print our $text; } close FD or die "Can't close FD $!";
As Bartles & Jaymes would say "Thank you for your support"
-- Grey Fox
Perl - Hours to learn lifetime to master.
Perl - Hours to learn lifetime to master.
2006-09-03 Retitled by Arunbear, as per Monastery guidelines
Original title: 'Use of a global scaler.'
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Use of a global scalar
by friedo (Prior) on Sep 02, 2006 at 21:49 UTC | |
by betterworld (Curate) on Sep 03, 2006 at 02:22 UTC | |
Re: Use of a global scalar
by shmem (Chancellor) on Sep 02, 2006 at 23:58 UTC | |
by Grey Fox (Chaplain) on Sep 03, 2006 at 05:22 UTC | |
Re: Use of a global scalar
by betterworld (Curate) on Sep 03, 2006 at 02:31 UTC | |
by Grey Fox (Chaplain) on Sep 03, 2006 at 05:28 UTC |
Back to
Seekers of Perl Wisdom