I have something like
open(OUTPUT, `\/home\/masca\/org\/10\/exe`);
while(<OUTPUT>) {
print;
}
But nothing happens. If I directly place that on the commandline - it
works fine.I hope someone has some ideas. I am sure this must be simple
- but I am new to perl.
Thanks a lot.
O.O.
You don't need to open it as a filehandle - just process the command
output directly, such as:
my $output = `\/home\/masca\/org\/10\/exe`; #scalar return
or my @output = `\/home\/masca\/org\/10\/exe`; #list return
or foreach my $output(`\/home\/masca\/org\/10\/exe`) {... #loop
Don't forget that if your command output includes newlines, you
(probably) should chomp() them off...
foreach my $output_1(`\/home\/masca\/org\/10\/exe`) {
#chomp();
print;
}
(Both with and without the chomp commented.) This does not seem to
work. I am not sure if my program is executed - but I just get a long
line of 222222222222's
I then tried
my @out_2 = `\/home\/masca\/org\/10\/exe`;
foreach(@out_2) {
#chomp();
print;
}
This does indeed work. (I think that the chomp() would come useful when
I process this.)
Another thing I noticed was that my backslashes were irrelevant at
least in the second case. (I can say this because the second case at
least works.) i.e.
my @out_2 = `/home/masca/org/10/exe`;
foreach(@out_2) {
#chomp();
print;
}
Seems to work just as fine.
Thanks a lot for your help and advice.
Regards,
O.O.
P.S.: - This really seems odd. I realized that the topics discussed in
this group were interesting to me, and I decided to subscribe to this
group, through google.
I was trying to post this message i.e. start a new topic - to this
group since last evening and it did not get through. I tried this
multiple times - and still nothing happened. In the end I unsubscribed,
and this post showed up within an hour or so. (However during this
time, I could reply to posts.)
That's because you are assigning the value of each line in the output
to a specifically-named variable ($output_1), but you are doing a
"print" without an argument (which prints $_).
If you said "print $output_1" (or didn't stipulate a loop variable) it
would work.