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.'


In reply to Use of a global scalar by Grey Fox

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.