CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner:
please help

 



tkrason
Novice

May 25, 2016, 8:08 AM

Post #1 of 5 (1597 views)
please help Can't Post

 
I have the code , but unfortunately it does not work as I want. I need to find if linni one string and the other does not search the directory with the files pdf, matched the name of the pdf file to a string in the line of the file ( it works ) . It does not work the case where you do not find the file name in the line of the file. If the name is not in line I will want to write a "not found" .

my $htmlFileName = 'C:\Temp\2016-04-06-125843-U01D-0000000001.html';
my $pdfDir = 'C:\FFOM\wfd_prod\EnergOS_JR0607\umowy_ulotki\umowy_cenniki';

open(HTMLFILE, '<:encoding(iso-8859-2)', $htmlFileName)
or die "Could not open file '$htmlFileName' $!";
my $WYD_html = '';


my @pdfFileNamesList;
opendir(DIR, $pdfDir) or die $!;
while (my $file = readdir(DIR)) {

next unless (-f "$pdfDir/$file");

next unless ($file =~ m/\.pdf$/i);
$file =~ s/\.pdf$//i;
push(@pdfFileNamesList, $file)
}
closedir(DIR);

while (<HTMLFILE>) {
$WYD_html .= $_;
$linia = $_;
if ($_ =~ /aaaaa/ and $_ =~/bbbbbbb/){
print "taryfa \n";
}
elsif ($_ =~ /aaaaa/ and $_ !~/bbbbbbb/){

$foundPDF = '';

for (@pdfFileNamesList){
if (index($linia, $_)>= 0 ){

print "- znalazłem [$_]\n";
$foundPDF .= "$_|\n";
}
}

}
}

close HTMLFILE;


bulrush
User

May 26, 2016, 9:04 AM

Post #2 of 5 (1567 views)
Re: [tkrason] please help [In reply to] Can't Post

I don't quite understand your English. Can you give example input and output data?
-----


Laurent_R
Veteran / Moderator

May 26, 2016, 2:54 PM

Post #3 of 5 (1560 views)
Re: [tkrason] please help [In reply to] Can't Post

I also don't really understand your question.


tkrason
Novice

May 26, 2016, 11:51 PM

Post #4 of 5 (1551 views)
Re: [bulrush] please help [In reply to] Can't Post

the program checks whether the line of the input file will string "aaaaa" and "bbbbbbb" if so displays "taryfa" if you can not find it in the next step, check if the string is "aaaaa", and that there are no strng "bbbbbbb" if so it will be directory files pdf try to match the name of any file located in this line. if he does not fit a show "not found"


BillKSmith
Veteran

May 30, 2016, 4:14 AM

Post #5 of 5 (1522 views)
Re: [tkrason] please help [In reply to] Can't Post

If I understand you correctly, all you need is one statement to print the missing message.

Code
elsif ($_ =~ /aaaaa/ and $_ !~/bbbbbbb/){  

$foundPDF = '';

for (@pdfFileNamesList){
if (index($linia, $_)>= 0 ){

print "- znalazłem [$_]\n";
$foundPDF .= "$_|\n";
}
}
print "Not found\n" if !$foundPDF;

}


Remember that an empty string is FALSE.
Good Luck,
Bill

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives