CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner: Re: [reld] Possibly a variable scope problem ...: Edit Log



reld
Novice

May 29, 2013, 3:39 AM


Views: 354
Re: [reld] Possibly a variable scope problem ...

If I add a variable at the top:


Code
#!/usr/bin/perl 

use strict;
use warnings;

use Path::Class;
use autodie; # die if problem reading or writing a file

my $dir = dir("./"); # Read from current directory
opendir(DIR, $dir) or die $!; # Open the directory
my $match = "string"; ####### <------ Here


And change the code I posted in my second reply to:


Code
while( my $line = $file_handle3->getline() ) {  


my @cut = split ( /,/, $line );

my $name = $cut[0];


while ( my $line2 = $file_handle1->getline() ) {

if ( $line2 =~ /$match/ ) { # works

$file_handle2->print($line2);
}
}
}


The code works, so for some reason the variable $name is the problem. I've tried declaring the variable $name at the top as well, in the same place as $match in the code above, and it still doesn't work.


(This post was edited by reld on May 29, 2013, 3:47 AM)


Edit Log:
Post edited by reld (Novice) on May 29, 2013, 3:39 AM
Post edited by reld (Novice) on May 29, 2013, 3:42 AM
Post edited by reld (Novice) on May 29, 2013, 3:47 AM


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives