OPEN command

F

Filippo

Hi all,
I'm a very beginner with the Perl and I have this problem: trying to
use Satellite2 (search engine for website) with PdfToHtml (so that it
can search inside pdfs) the first indexes strange and nonsense words.

If I use pdftohtml from the command line (es. "pdftohtml -stdout
hello.pdf") it works, printing the html file resulting from the pdf.

Scanning Satellite's scripts I found these lines:

$a = open(fileIN, "etc/pdftohtml -q -i -stdout \"$file\"
\"data/myTemp/temp\" | ");

while(<fileIN>)
{
$_ =~ s/\n/ /;
$content .= $_;
}
close fileIN;

I can't understand this way of using the OPEN command.
Can anybody explain it to me?
 
A

Arndt Jonasson

$a = open(fileIN, "etc/pdftohtml -q -i -stdout \"$file\"
\"data/myTemp/temp\" | ");

while(<fileIN>)
{
$_ =~ s/\n/ /;
$content .= $_;
}
close fileIN;

I can't understand this way of using the OPEN command.
Can anybody explain it to me?

perldoc -f open

says, among other things:

"If the filename begins with C<'|'>, the filename is interpreted as a
command to which output is to be piped, and if the filename ends with a
C<'|'>, the filename is interpreted as a command which pipes output to
us."

It probably says somewhere that trailing spaces are not significant,
because they don't seem to be.
 
M

Michele Dondi

Scanning Satellite's scripts I found these lines:

$a = open(fileIN, "etc/pdftohtml -q -i -stdout \"$file\"
\"data/myTemp/temp\" | ");

BTW: as it is this line of code suggests it's a badly written script
for, just to pinpoint some issues:

(i) $a shouldn't be used as a general purpose variable (see 'perldoc
perlvar'). A more illustrative name like $pid would have been better
anyway; also, I can't say for sure, but this strongly makes one
suspect that we're not running under strict;

(ii) no error checking that open() succeeded: very bad!

(iii) clumsy use of all those quoted quotes, whereas

qq{etc/pdftohtml -q -i -stdout "$file" "data/myTemp/temp" |}

would have been just as good;

(iv) using lexical filehandles and the three arguments form of open()
is preferrable in any case. (But this may depend on which version of
perl the script was written for.)
while(<fileIN>)
{
$_ =~ s/\n/ /;
$content .= $_;
}
close fileIN;

more badly written code, from indentation style to useless use of

$_ =~ ... ;

Also I *guess* that one may want to

s/\n/ /g;
# ^

instead. (But I may well be wrong on this!)
I can't understand this way of using the OPEN command.
Can anybody explain it to me?

Well I can't, but 'perldoc -f open' can.


Michele
 
T

Tad McClellan

Filippo said:
I'm a very beginner with the Perl


You should make an attempt to find the answer to your question
in the standard docs that come with the perl distribution *before*
asking hundreds of people to help you with it.

I can't understand this way of using the OPEN command.


There is no "OPEN" in Perl, only "open". Case matters.

open() is not a "command".

Can anybody explain it to me?


The documentation for the open() function can explain the use
of the open() function:

perldoc -f open
 
A

Ala Qumsieh

Michele said:
more badly written code, from indentation style to useless use of

$_ =~ ... ;

Also I *guess* that one may want to

s/\n/ /g;
# ^

instead. (But I may well be wrong on this!)

I believe you are :)
Since the OP does not show any modification to $/, I'll assume that it
has its default value of "\n", in which case there can be at most one
newline character in $_, and it will necessarily be at the end. Hence,
the /g is superfluous.

FWIW, I would've done things like this:

chomp;
$content .= " $_";

But, TMTOWTDI.

--Ala
 
S

Soxos

I'm sorry, my question didn't follow the netiquette, but, as I just saw,
even you "gurus" aren't agree on the form and on the substance of the
problem...

I've already spent some hours on my problem, perhaps searching in the
wrong places, so I thought you could answer me in a while!
That wasn't right, so I repeat I'm sorry!

I will search on PERLDOC (THIS is a good suggestion, without you have to
remark that open is not a command!).

Bye!
 
M

Michele Dondi

Ala Qumsieh said:
while(<fileIN>)
{
$_ =~ s/\n/ /;
[snip]
Also I *guess* that one may want to

s/\n/ /g;
# ^

instead. (But I may well be wrong on this!)

I believe you are :)

Of course I am!! For some reason I thought that $_ could contain
multiple \n's: I posted in a hurry and I didn't even realize that it
was more-bad-codese for "chomp() and append a space". (Now I slap my
forhead!)
FWIW, I would've done things like this:

chomp;
$content .= " $_";

But, TMTOWTDI.

Well, we always insist to process line by line, but since the OP won't
discard any, this could probably be one of the cases in which

chomp (my @lines = <fileIN>);
$content = "@lines";

or something along the same lines is sensible.


Michele
 
T

Tad McClellan

I've already spent some hours on my problem, perhaps searching in the
wrong places,


Where _did_ you search?

Maybe we can suggest some better places...

I will search on PERLDOC (THIS is a good suggestion,


Case *still* matters. The name of the program is "perldoc".


You asked how open() works, and I assumed that the 1st place you
would look would be the documentation for open().

Since you still posted asking how a pipe open works, I assumed
that you had not spent any time at all trying to find the
answer on your own.

Sorry if my assumption was not correct.

without you have to
remark that open is not a command!).


I don't see anything offensive it that, but I think that you do.

open() is not a "command" and you did not know that, so I let
you know it. You did come here to learn, yes?




Have you seen the Posting Guidelines that are posted here frequently?
 
M

Michele Dondi

I'm sorry, my question didn't follow the netiquette, but, as I just saw,

As a side note this post doesn't either: please provide relevant
quotations (hopefully trimmed down to a minimum) when replying.


Michele
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,164
Messages
2,570,901
Members
47,439
Latest member
elif2sghost

Latest Threads

Top