Home: Perl Programming Help: Beginner:
pattern with join hangs when printing



regex2012
User

Dec 19, 2016, 8:52 AM


Views: 5961
pattern with join hangs when printing

 
This is my first experience using join and I'm wondering why this hangs. If I write it to a file handle, instead of an array it does not hang.
$pattern hangs after it prints out. If I wanted to stop it from hanging and return to command prompt, what is the best way?


Code
my @bfilearr = `$bcmd`; 
chomp(@bfilearr);
print "This is @bfilearr";
my $pattern = join '|', @bfilearr;
print "THIS is $pattern\n";



FishMonger
Veteran / Moderator

Dec 19, 2016, 9:21 AM


Views: 5956
Re: [regex2012] pattern with join hangs when printing

What command are you running in $bcmd?

What happens when you run that same exact command from the command line instead of the script? Does it wait for user input?

There's nothing about the join statement that would cause the script to hang. Something else is causing it to hang.

Please post a short but complete test script that demonstrates the problem so that we can test it and try to duplicate the problem. If you do that, you will most likely learn the true cause of it hanging while writing that test script.


FishMonger
Veteran / Moderator

Dec 19, 2016, 9:26 AM


Views: 5955
Re: [regex2012] pattern with join hangs when printing

This statement might be where it's hanging.

Code
print "This is @bfilearr";


Since the last element in the array does not contain a line terminator, you are probably "suffering from buffering". Turn of buffering by adding this above that code.

Code
$|++;

or add a line terminator to the statement.

Code
print "This is @bfilearr\n";



(This post was edited by FishMonger on Dec 19, 2016, 9:29 AM)