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, 4:46 AM


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

I've narrowed the problem down to $cut[0]. If I set it equal to a string value, the code works and matches.


Code
my @cut = split ( /,/, $line ); 
$cut[0] = "string";



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

if ( $line2 =~ /$cut[0]/ ) { # works

$file_handle2->print($line2);
}


If I instead write the code below:


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


$name = $cut[0];


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

if ( $line2 =~ /$name/ ) { #doesn't work

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


The variable $name doesn't seem to have a value. Something is going wrong with $cut[0].

After some more testing I think there is something I am doing wrong with the array @cut.


(This post was edited by reld on May 29, 2013, 5:19 AM)


Edit Log:
Post edited by reld (Novice) on May 29, 2013, 4:47 AM
Post edited by reld (Novice) on May 29, 2013, 4:56 AM
Post edited by reld (Novice) on May 29, 2013, 5:06 AM
Post edited by reld (Novice) on May 29, 2013, 5:19 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