Hello Fellow Monks of perl;
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.
2006-09-03 Retitled by Arunbear, as per Monastery guidelines Original title: 'Use of a global scaler.'
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|