PERL foreach & open not working together


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting PERL foreach & open not working together
# 1  
Old 03-17-2012
PHP PERL foreach & open not working together

My script is as below:

Code:
my $tile_list = `egrep "FCFP_TILE_LIST.*=" ${BudgetDir}/tile.params | sed -e 's/FCFP_TILE_LIST//' | sed -e 's/=//'`;
print "Tile List = ".$tile_list."\n";
my @tiles = split(/\s+/, $tile_list);
$unconst_out = "${DestDir}/Unconstrained_ports.rpt";
$check_tim_out = "${DestDir}/reports.rpt";
open(CHKTIMOUT, ">$check_tim_out") || die "I cannot open $check_tim_out";
open(UNCNSTOUT, ">$unconst_out") || die "I cannot open $unconst_out";
foreach $sblk1 (@tiles) {
    #$sblk1 = $_;
    print "Check ".$sblk1."\n";
    $khush_W = 0; 
    $unconst_in = "${Dir}/${sblk1}/${sblk1}.txt";
    open(UNCNSTIN, "<$unconst_in") || die "Khush I cannot open the input file @ $unconst_in";
    #print UNCNSTOUT "\n<<<<<<<<<< ".$sblk1." >>>>>>>>>>\n";
    #while ($line1 = <UNCNSTIN>) {
    #    if ($line1 =~ /Start Section: Ports without constraints/) {
    #        $khush_W = 1;
    #        next;
    #    } elsif ($line1 =~ /End Section: Ports without constraints/) {
    #        $khush_W = 0; 
    #        next;
    #    }
    #    if ($khush_W == 1) {
    #        if ($line1 =~ /^Port:\s+(.*)\s+\(setup\)/) {
    #            $port_W = $1;
    #            print UNCNSTOUT $port_W."\n";
    #            next;
    #        }
    #    }
    #}
    #close(UNCNSTIN) || die "close $!";
}

The moment I use the line '/proj/starshapd_vol25/a0/fcwork/NLC_1/fcfp/main/pd/tiles/gnb_c_12_TileBuilder_Mar01-1651_c_12' my $sblk1 variable contains nothing. Does anyone know what the problem is?

Thank you!

Moderator's Comments:
Mod Comment Video tutorial on how to use code tags in The UNIX and Linux Forums.

Last edited by radoulov; 03-17-2012 at 03:44 AM..
# 2  
Old 03-17-2012
Quote:
Originally Posted by kuchi7
The moment I use the line '/proj/starshapd_vol25/a0/fcwork/NLC_1/fcfp/main/pd/tiles/gnb_c_12_TileBuilder_Mar01-1651_c_12' my $sblk1 variable contains nothing. Does anyone know what the problem is?
1. Where and how are you using '/proj/starshapd_vol25/a0/fcwork/NLC_1/fcfp/main/pd/tiles/gnb_c_12_TileBuilder_Mar01-1651_c_12' ? I don't see it anywhere in the code you posted.

2. What exactly is the requirement? Just the gist of it.
# 3  
Old 03-17-2012
Sorry, I actually wanted to mention the line
open(UNCNSTIN, "<$unconst_in") || die "Khush I cannot open the input file @ $unconst_in";

---------- Post updated at 02:23 AM ---------- Previous update was at 02:20 AM ----------

So I figured out the problem, when I use the split function, it doesn't take the null value into account. Hence when I add the line 'if (sblk1 eq "") {next;}' after the foreach statement, the code works.

Thanks for the help.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Print perl hash value in foreach loop

Experts - Any advice on how to get a hash value in a foreach loop? Values print correctly on standalone print statements, but I can't access value in foreach loop. See sample code below and thanks in advance. foreach my $z (sort keys %hash) { for $y (@{$hash{$z}}) { print "$z... (6 Replies)
Discussion started by: timj123
6 Replies

2. Shell Programming and Scripting

Foreach .gz file in a directory -- Not working

Hi, I am trying to add for loop in my code for all the .gz files in a directory. example code: for i in $PWD/input/*.dz do echo " file is :: $i " done This is not working as expectation and the output is : file is :: /home/IB/input/*.dz However, for i in $PWD/input/*... (5 Replies)
Discussion started by: IB_88
5 Replies

3. UNIX for Advanced & Expert Users

Awk expressions working & not working

Hi, Putting across a few awk expressions. Apart from the last, all of them are working. echo a/b/c | awk -F'/b/c$' '{print $1}' a echo a/b/c++ | awk -F'/b/c++' '{print $1}' a echo a/b/c++ | awk -F'/b/c++$' '{print $1}' a/b/c++ Request thoughts on why putting a '$' post double ++... (12 Replies)
Discussion started by: vibhor_agarwali
12 Replies

4. Shell Programming and Scripting

foreach loop working in terminal but not in the script

Hi, I am new here I have used the forums a long time to search for things they are very helpful. I have unfortunately used up all my resources (professors, grad students) and need some help. I have this very simple piece of code (using to isolate the problem) in a csh script: #!/bin/csh... (12 Replies)
Discussion started by: bflinchum
12 Replies

5. Shell Programming and Scripting

Perl - Sort and Count foreach line

Can any one please help I am trying to sort each item in every line and count the common (non case sensitive) and at the end printing all the unique alphabetically. Here is what i did ... I can print all the lines but struck to sort each line some were: I am getting the output as: I... (5 Replies)
Discussion started by: sureshcisco
5 Replies

6. Programming

PERL, search and replace inside foreach loop

Hello All, Im a Hardware engineer, I have written this script to automate my job. I got stuck in the following location. CODE: .. .. ... foreach $key(keys %arr_hash) { my ($loc,$ind,$add) = split /,/, $arr_hash{$key}; &create_verilog($key, $loc, $ind ,$add); } sub create_verilog{... (2 Replies)
Discussion started by: riyasnr007
2 Replies

7. Shell Programming and Scripting

Find & Replace string in multiple files & folders using perl

find . -type f -name "*.sql" -print|xargs perl -i -pe 's/pattern/replaced/g' this is simple logic to find and replace in multiple files & folders Hope this helps. Thanks Zaheer (0 Replies)
Discussion started by: Zaheer.mic
0 Replies

8. Shell Programming and Scripting

Nested foreach in perl

I have two arrays @nextArray contains some files like \main\1\Xul.xml@@\main\galileo_integration_sjc\0 \main\1\PortToStorageDialog.xml@@\main\galileo_integration_sjc\0 . . . \main\1\PreferencesDialog.xml@@\main\galileo_integration_sjc\0 @otherArray contains some files like ... (2 Replies)
Discussion started by: nmattam
2 Replies

9. UNIX for Dummies Questions & Answers

Foreach loop to run a perl script on multiple files

Hi, I have thousands of files in a directory that have the following 2 formats: 289620178.aln 289620179.aln 289620180.aln 289620183.aln 289620184.aln 289620185.aln 289620186.aln 289620187.aln 289620188.aln 289620189.aln 289620190.aln 289620192.aln.... and: alnCDS_1.fasta (1 Reply)
Discussion started by: greptastic
1 Replies

10. Shell Programming and Scripting

Perl - Iterating a hash through a foreach loop - unexpected results

i've reworked some code from an earlier post, and it isn't working as expected i've simplified it to try and find the problem. i spent hours trying to figure out what is wrong, eventually thinking there was a bug in perl or a problem with my computer. but, i've tried it on 3 machines with the... (5 Replies)
Discussion started by: quantumechanix
5 Replies
Login or Register to Ask a Question