sub prerequest_collect_files_db_url {
...
}
You never call that subroutine.
Maybe if you call that subroutine, it will actually create the files you want. | [reply] [d/l] |
| [reply] |
| [reply] |
You would do yourself a great favor if you followed the following guidelines:
- indent your code consistently and properly;
- use strict; (you are doing it for the second script, but apparently not for the first)
- use warnings; (you are doing it for the second script, but apparently not for the first)
- use the 3-argument syntax for opening files and directories (see open) and check if the opening was successful;
- use lexical filehandles;
- use the modern syntax for calling subroutines:
domain_check();
and not:
&domain_check();
remove extra vertical spaces that are not needed;
close your files when they are no longer needed;
lay-out your question and code snippets in a clearer fashion, using code tags not only for code, but also for displaying program output.
Nothing of the above is absolutely necessary, but these things are more important than being necessary, they are essential (i.e. they are part of the essence of good programming). I am sorry to say that, but I frankly don't feel like spending the time to go through such messy code (and I would certainly not hire a programmer who would show me such a sloppy work). You might find my comments so far to be harsh, but they are really meant to help you (and to help us, poor monks, helping you). I am not being extremist or fanatic, quite to the contrary. If I had decided to follow Damian Conway's Perl Best Practices, I would have at least three dozen additional recommendations, so be happy that it is me, and not TheDamian, answering your post. (Just in case, I am just jokingly saying that I might have been much harsher, this is by no means, and should not be understood, construed or interpreted as, a critique on Damian's guidelines.)
Having said that, I am not a bad guy, I am actually much nicer than you might think at this point and, despite everything I said so far, I took a bit of time to look a bit through your code, and I have a couple of additional comments.
You should probably not use the do function to include external Perl code, this is quasi obsolete. Take a look at the require and use functions and other documentation on Perl modules.
This piece of code:
$url=$_;
foreach ($url)
{ #...
does not make much sense to me. The $_ scalar variable contains one single data item (in this case, a text line), and the $url scalar variable also contains one single data item. Why would you want to use foreach to loop on a single data item?
As for your precise question, I am sorry, I am unable to answer because your code is incomplete, you haven't shown a sample of the data files you are reading, we don't know what the scripts you are calling with the do function are doing, and your question is far from being clear. But if you do everything that I suggested above, you might actually see what the problem is and find a solution to it. And even if this is not sufficient, well, then post your cleaned-up code, I am sure many more monks (including myself) will feel like wanting to help you further.
| [reply] [d/l] [select] |
You might find my comments so far to be harsh, but they are really meant to help you (and to help us, poor monks, helping you). I am not being fanatic.
You're a nice guy! What the OP posted was a perfect illustration of "write-only Perl". But can Perl itself be blamed for it? I don't think so.
| [reply] |
| [reply] |
Your code seems a bit incomplete, since I don't see where prerequest_collect_files_db_url is being called, but I'll assume it's called before you do prerequest2.pl?
The thing that stands out to me is that you close your filehandles outside of the sub, why? I suggest you close your files right after you're done with them. Also, you may want to look into lexical filehandles, which aren't global and get closed when they go out of scope (in case you forget to do it explicitly, which you always should anyways). For example: open my $filehandle, "<", "filename.txt" or die $!; my @input = <$filehandle>; close $filehandle;
| [reply] [d/l] [select] |
| [reply] |
Your original post implied that the files were empty when you call prerequest2.pl, but if they have some content then the error situation is actually completely different. Please see "How do I post a question effectively?" and follow the suggestions there (such as providing sample input and expected output) so your posts are more helpful to those providing help.
How many lines are there in your input? Have you tested your conditions and other parts of the code (xpathconfiguration.pl, domain_check(), and the grep) to be working? I'd suggest printing some debug output in your innermost loops to see what actually gets written to the file. Also, see Basic debugging checklist
| [reply] [d/l] [select] |
Hi greetings to everyone.I am here to seek the wisdom of monks,here is my issue.
This seems familiar, maybe you missed my reply from yesterday Re: loop exits after printing the file
do is not how perl programmers make modules, or use modules; modules should only define/create subroutines, they shouldn't do anything on their own ... there should be no code outside of subroutines, subroutines should be self contained
Making a real module is easy if you follow these examples: Re: loop exits after printing the file, zentara package/module tutorial
If you write code this way and create real modules, with subroutines that take arguments and return values, it will be easy to figure out why you need to call your program twice for the files to be created in time to do the comparison
MakeFilesOrDie( $these, $files );
CompareFilesOrDie( $these, $files );
What you have posted is like a magic act $url=$_;
&domain_check();
$x="$competitor.html";
What does domain_check do? Where does $competitor come from?
Why doesn't domain_check take arguments?
Why doesn't domain_check return values?
Maybe it should be my $competitor = domain_check( $url ); but its impossible to know, your posted program has many missing pieces...
Its like a buying stuff at a store, the buyer doesn't reach into the cash register to pay for items and get change, the buyer gives money to cashier, the cashier gives change back or ask for more money my $change = gimmeChange( '20USD', 'milk','cookies' );
sub gimmeChange {
my( $payment , @items ) = @_;
my $price = gimmePrice( @items );
my $diff = $payment - $price;
if( $payment < $price ){
warn "You don't have enough money, you need $diff";
}
return $diff;
}
| [reply] [d/l] [select] |
| [reply] |