print $new $l;
The first of those (without a comma) didn't print anything at all. The second one printed "foobar", as expected.perl -le '$x="foo"; $y="bar"; print $x $y' perl -le '$x="foo"; $y="bar"; print $x, $y'
In the first try, without the comma, the 'print' function is trying to interpret $x as a file handle, and failing. In the absence of use warnings;' there wasn't even a hint about the problem, but a third experiment was more instructive:
Given that sort of condition, the default (prudent) behavior is for the print function to do nothing at all.perl -wle '$x="foo"; $y="bar"; print $x $y' print() on unopened filehandle foo at -e line 1.
Sorry - total brain fart on on the stuff above. I forgot that $new was supposed to be a file handle. Oh well.
UPDATE: Random Walk has apparently solved your problem, but here's a slightly different version of the same solution anyway... (possibly a bit less different from the OP code, possibly a little simpler, and, well, at least this allows my reply to have some usable content):
use strict; use warnings; my $name = "name"; # open( my $rfh,'<', $entry ) or die "cannot open > $entry: $!"; open( my $new, '>', "$name\_new.txt" ) or die "cannot open: $!"; my $signal1 = "s_abc_out"; my $signal2 = "s_abc_in"; my $label = "label"; while ( <DATA> ) { # would be <$rfh> for you if ( /$signal2\(\d+\).*\s*<=\s*$signal1\(\d+\).*/ ) { for my $i ( 0 .. 6 ) { my $j = $i + 1; print $new "$signal2\_rrfa_$label($j) <= $signal1\_rrfa_$l +abel($i);\n"; } } else{ print $new $_; } } __DATA__ ................................. s_abc_in(1450) <= s_abc_out(324); s_abc_in(1451 <= s_abc_out(1450); .................................
In reply to Re: Filehandle problem
by graff
in thread Filehandle problem
by amma
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |