Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
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

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

  • 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.
Log In?

What's my password?
Create A New User
Domain Nodelet?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (3)
As of 2022-11-27 18:05 GMT
Find Nodes?
    Voting Booth?