User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the Perl section within the Software Development category of DaniWeb, a massive community of 423,330 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 5,297 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our Perl advertiser: Programming Forums
Views: 689 | Replies: 4
Reply
Join Date: Jul 2008
Posts: 1
Reputation: Achmat is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
Achmat Achmat is offline Offline
Newbie Poster

Struggling Newbie

  #1  
Jul 4th, 2008
Hi guys,
I've been fiddling with Perl for the past 2months and still I have difficulty with it, I've read 3books already but I'm kinda in the deep end cause I'm in a working environment. I'm currently working on this:
#!/usr/bin/perl
print "Content-type: text/html\n\n";

#all variables starting with 'i' are inputs from a seperate screen


require cfg ;					#module specifiying frequently used paths

if ($local eq 'n') {
    use lib  "/home/gevens/cgi-bin/ecco/modules" ;
    use lib  "/home/gevens/cgi-bin/ecco/html/agent" ;
    }
else
    {
    use lib  "C:/Program Files/Apache Group/Apache2/cgi-bin/ecco/modules" ;
    use lib  "C:/Program Files/Apache Group/Apache2/cgi-bin/ecco/html/agent" ;
    }

use Fcntl qw(:flock);				#CPAN Modules
use Date::Calc qw(:all);
use CGI::Minimal;
use CGI::Carp qw(fatalsToBrowser);
use Mail::Sendmail;
use MIME::Base64;

#------------------------------------------------------------------------------------------
$title = "RATES CHECK SPREADSHEET";
#------------------------------------------------------------------------------------------

if (($username ne '000')			        #agent sign-ons
and ($username ne '001')) {
    exit;
    }

$q           = CGI::Minimal -> new();
$action      = $q -> param('action')     || '';		#input action

$iregionall  = $q -> param('iregionall') || '';		#input region
$iselldd     = $q -> param('iselldd')    || '';		#input sell date
$isellmm     = $q -> param('isellmm')    || '';		#input sell month
$isellyy     = $q -> param('isellyy')    || '';		#input sell year

$istartdd    = $q -> param('istartdd')   || '';		#input start date
$istartmm    = $q -> param('istartmm')   || '';		#input start month
$istartyy    = $q -> param('istartyy')   || '';		#input start year
$ienddd      = $q -> param('ienddd')     || '';		#input end date
$iendmm      = $q -> param('iendmm')     || '';		#input end month
$iendyy      = $q -> param('iendyy')     || '';		#input end year
							
($iregion, $ifoldern) = split (/\:/, $iregionall) ;	#split the inout region and folder by ':'

$iregion_selected = $iregion;

$isellccyymmdd  = "20$isellyy$isellmm$iselldd";		#input sell date
$istartccyymmdd = "20$istartyy$istartmm$istartdd";	#input start date
$iendccyymmdd   = "20$iendyy$iendmm$ienddd";		#input end date

$filename  = "RATES-$iregion.CSV";			#specifying the region file and thus providing the output for the spreadsheet
$filename2 = "RATES-$iregion-SUPP.CSV";

#------------------------------------------------------------------------------------------

&today; 						#sub-routine calculating dates

if ($action eq "") {					#if form blank leave message
    $iselldd  = $now_dd;				#PLEASE ENTER DETAILS
    $isellmm  = $now_mm;
    $isellyy  = $now_yy;
    $istartdd = 'dd' ;
    $istartmm = 'mm' ;
    $istartyy = 'yy' ;
    $ienddd   = 'dd' ;
    $iendmm   = 'mm' ;
    $iendyy   = 'yy' ;
    $msg = "PLEASE ENTER DETAILS";
    &screen1;
    }

if ($action eq "sprdsht5") {				#if statement when form is completed, input action = sprdsht 5 yields true
    &check_fields ;					#calls sub-routine checking fields
    &load_suppliers ;					#calls sub-routine loading suppliers
    &read_tariff1 ;					#calls sub-routine reading tarrifs
    &print_array;					#calls sub-routine printing sorted array
    &email1;						#calls e-mail sub-routine that defines e-mail content
    $msg = "THE SPREADSHEET HAS BEEN EMAILED TO YOU...";
    &screen1;						#sub-routine calling module with HTML content
    }

exit;

#------------------------------------------------------------------------------------------
sub check_fields {
#------------------------------------------------------------------------------------------

$error  = "";						

&dcheck("SELL FROM DATE", "$iselldd", "$isellmm", "$isellyy");
&dcheck("FROM DATE", "$istartdd", "$istartmm", "$istartyy");
&dcheck("TO DATE",   "$ienddd", "$iendmm", "$iendyy");

if ($error){ $msg = $error ; &screen1 ; exit; }

#------------------------------------------------------------------------------------------
}
#------------------------------------------------------------------------------------------

#------------------------------------------------------------------------------------------
sub push_the_first_array {
#------------------------------------------------------------------------------------------

&prices1;						#sub-routine containing price calculations

#print "<BR>$tcode - $tariff1{$tcode},$tariff2{$tcode},$tariff3{$tcode},$tariff4{$tcode},$thotel";

if (lc $tptnr eq 'bbb') {
    $sort_key_tptnr = 'AAA' ;
    }
else
    {
    $sort_key_tptnr = 'ZZZ' ;
    }

$sort_key  = "$tstartccyymmdd$tendccyymmdd$troomtyp$tstaymin$sort_key_tptnr" ;

#print "<BR>$sort_key";

if ($tmaxchd > 1) {
    $print_tshareage = "($tshareage)";
    }
else
    {
    $print_tshareage = "";
    }

$sort_line = "$tariff1{$tcode},$tariff2{$tcode},$tariff3{$tcode},$tariff4{$tcode},$thotel,$sort_key,$tstartccyymmdd,$tendccyymmdd,$troomtyp,$tminocc,$tmaxadu,$tmaxchd $print_tshareage,$tminage,$tstaymin,$tstaymax,$tntsfree,$sgl_room_ttl,$dbl_room_ttl,$tpl_room_ttl,$qad_room_ttl,$qin_room_ttl,$sex_room_ttl,$tchdpola,$cha_room_ttl,$tchdpolb,$chb_room_ttl,$tchdpolc,$chc_room_ttl,$tsellcur,$twkend,$tcode,$tpricenote";

#print "<BR> $sort_line";

push @thearray, $sort_line;

&print_hotel_details;

#------------------------------------------------------------------------------------------
}
#------------------------------------------------------------------------------------------

#------------------------------------------------------------------------------------------
sub print_array {
#------------------------------------------------------------------------------------------

$print_S1FILE .= "REGION:$ifoldern, DATE RANGE:$istartdd.$istartmm.$istartyy - $ienddd.$iendmm.$iendyy,\n";
$print_S1FILE .= "Start Date,End Date,Room Type,Stay,Min Occ,Max Adult,Max Child,Min Age,Min Stay,Max Stay,Free Nts,Sell Curr,Dbl/Twn,Single,Triple,Quad,Quin,Sext,Child Policy A,Child Supp A,Child Policy B,Child Supp B,Child Policy C,Child Supp C,Note,\n" ;

@sorted1 = sort @thearray;

foreach $array1line (@sorted1) {
    ($sort_stariff1,$sort_stariff2,$sort_stariff3,$sort_stariff4,$sort_hotel,$sort_key,$sort_start,$sort_end,$sort_roomtyp,$sort_minocc,$sort_tmaxadu,$sort_tmaxchd,$sort_minage,$sort_tstaymin,$sort_tstaymax,$sort_freents,$sort_sgl_room_ttl,$sort_dbl_room_ttl,$sort_tpl_room_ttl,$sort_qad_room_ttl,$sort_qin_room_ttl,$sort_sex_room_ttl,$sort_tchdpola,$sort_cha_room_ttl,$sort_tchdpolb,$sort_chb_room_ttl,$sort_tchdpolc,$sort_chc_room_ttl,$sort_tsellcur,$sort_twkend,$sort_tcode,$sort_tpricenote) = split(/\,/, $array1line);

    $test = "$sort_hotel$sort_roomtyp$sort_start$sort_tstaymin$sort_twkend";

    unless ($done{$test}) {
        &print_it_out ;
        $done{$test} = 'y' ;
        }
    }

#------------------------------------------------------------------------------------------
}
#------------------------------------------------------------------------------------------

#------------------------------------------------------------------------------------------
sub print_it_out {
#------------------------------------------------------------------------------------------

#print "<BR>************* $sort_stariff1,$sort_stariff2,$sort_stariff3,$sort_stariff4,$sort_hotel,$sort_key,$sort_start";

if ($header1 ne $sort_stariff1) {
    $print_S1FILE .= "\n$sort_stariff1\n";
    $header1 = $sort_stariff1;
    }

if ($header2 ne $sort_stariff2) {
    $print_S1FILE .= "\n$sort_stariff2\n";
    $header2 = $sort_stariff2;
    }

if ($header3 ne $sort_stariff3) {
    $print_S1FILE .= "$sort_stariff3\n";
    $header3 = $sort_stariff3;
    }

if ($header4 ne "$sort_hotel-$sort_stariff4") {
    $print_S1FILE .= "$sort_hotel\n";
    $header4 = "$sort_hotel-$sort_stariff4";
    $current_date_start = ' ';
    $current_date_end   = ' ';
    }

if ($current_date_start ne $sort_start) {
    $current_date_start = $sort_start;
    $print_date_start = substr($sort_start,6,2) . "." . substr($sort_start,4,2) . ".". substr($sort_start,2,2);
    }
else
    {
    $print_date_start = ' ';
    }

if ($current_date_end ne $sort_end) {
    $current_date_end = $sort_end;
    $print_date_end = $sort_end;
    $print_date_end = substr($sort_end,6,2) . "." . substr($sort_end,4,2) . ".". substr($sort_end,2,2);
    }
else
    {
    $print_date_end = ' ';
    }

if ($sort_twkend) {
    $twkend = $sort_twkend ; # use $twkend just for the purpose of calling &twkend to get $wkend_name for printing
    &twkend ;
#   $sort_roomtyp = "$sort_roomtyp - $wkend_name" ;
    }

if  (lc $sort_tchdpola eq 'n/a') {
    $print_tchdpola = $sort_tchdpola ;
    }
else
    {
    if ($sort_tchdpola eq $sort_tchdpolb) {
        $print_tchdpola = "First ($sort_tchdpola)";
        }
    else
        {
        $print_tchdpola = "($sort_tchdpola)";
        }
    }

if  (lc $sort_tchdpolb eq 'n/a') {
    $print_tchdpolb = $sort_tchdpolb ;
    }
else
    {
    if ($sort_tchdpola eq $sort_tchdpolb) {
        $print_tchdpolb = "Second ($sort_tchdpolb)";
        }
    else
        {
        $print_tchdpolb = "($sort_tchdpolb)";
        }
    }


if  (lc $sort_tchdpolc eq 'n/a') {
    $print_tchdpolc = $sort_tchdpolc ;
    }
else
    {
    $print_tchdpolc = "($sort_tchdpolc)" ;
    }


$print_S1FILE .= "$print_date_start,$print_date_end,$sort_roomtyp,$wkend_name,$sort_minocc,$sort_tmaxadu,$sort_tmaxchd,$sort_minage,$sort_tstaymin,$sort_tstaymax,$sort_freents,$sort_tsellcur,$sort_dbl_room_ttl,$sort_sgl_room_ttl,$sort_tpl_room_ttl,$sort_qad_room_ttl,$sort_qin_room_ttl,$sort_sex_room_ttl,$print_tchdpola,$sort_cha_room_ttl,$print_tchdpolb,$sort_chb_room_ttl,$print_tchdpolc,$sort_chc_room_ttl,$sort_tpricenote,\n" ;

$wkend_name = '' ; # use $twkend just for purpose of calling &twkend and printing - now it needs to be reset to blank (used for printing only)

#------------------------------------------------------------------------------------------
}
#------------------------------------------------------------------------------------------

#------------------------------------------------------------------------------------------
sub read_tariff1 {
#------------------------------------------------------------------------------------------

$tariff1file = "$hotelpath/$iregion/$tariff1";							#defines the tarrif file

#print "<BR>-$tariff1file---";

open    (H1FILE, "$tariff1file") ;								#opens the tarrif file
if ($local eq 'n') { flock (H1FILE, LOCK_SH) or die "can't lock $tariff1file: $!"; }		#file locked if program is run
		
while (<H1FILE>) {										#starts the loop while file is opened:
    chomp;											#chomps the file by lines
    @linex = split(/\,/);									#split lines by slashes putting each line in an array
    &tfields;											#module with sub-routine with fields of tarrif file
    $tcode = lc $tcode;										#put codes in lower-case
    &date_range_check ;										#check the date range
    }

close   (H1FILE);										#close the FILE

#------------------------------------------------------------------------------------------
}
#------------------------------------------------------------------------------------------

#------------------------------------------------------------------------------------------
sub date_range_check {
#------------------------------------------------------------------------------------------

$tsellfccyymmdd = "20$tsellfyymmdd" ;								#add the  20 in front of the date
$tselltccyymmdd = "20$tselltyymmdd" ;								
$tstartccyymmdd = "20$tstartyymmdd" ;
$tendccyymmdd   = "20$tendyymmdd" ;

if (($isellccyymmdd < $tsellfccyymmdd) or ($isellccyymmdd > $tselltccyymmdd)) { return ; }

if ($tptnr) {
    if (lc $tptnr ne 'flc') { return ; }		#defines the partner logged on
    }

if ((($istartccyymmdd >= $tstartccyymmdd) and ($istartccyymmdd <= $tendccyymmdd))		#if input date is >= input start and tour start and input end <= tour end 
or  (($tstartccyymmdd >= $istartccyymmdd) and ($iendccyymmdd   >= $tstartccyymmdd))) {		#or tour start date >= input start and input end <= tarrif start
    &push_the_first_array ;									#call sub-routine
    }

#------------------------------------------------------------------------------------------
}
#------------------------------------------------------------------------------------------

#------------------------------------------------------------------------------------------
sub print_hotel_details {
#------------------------------------------------------------------------------------------

unless ($done_address{$tcode} eq 'y') {
    $print_canxpol = '';

    &canxpol($sbillcode{$tcode},'flc',$istartdd,$istartmm) ;

    $print_S2FILE .= "$thotel ($sstar{$tcode}) , Address : ,$sadd1{$tcode}, $sadd2{$tcode}, $sadd3{$tcode}, $sadd4{$tcode}, $spcode{$tcode}, $sctry{$tcode}\n";
    $print_S2FILE .= ", Phone : ,$sphone{$tcode},\n";
    $print_S2FILE .= ", Fax : ,$sfax{$tcode},\n";
    $print_S2FILE .= ", Child Policy :, $snote{$tcode}\n";
    $print_S2FILE .= ",$print_canxpol\n";
    $print_S2FILE .= "\n";

    $done_address{$tcode} = 'y';
    }

#------------------------------------------------------------------------------------------
}
#------------------------------------------------------------------------------------------

#------------------------------------------------------------------------------------------
sub screen1 {
#------------------------------------------------------------------------------------------

require flcsprdsht5 ;

exit;

#------------------------------------------------------------------------------------------
}
#------------------------------------------------------------------------------------------

#------------------------------------------------------------------------------------------
sub load_suppliers {
#------------------------------------------------------------------------------------------

$supplier1file = "$supplierpath/$iregion/suppliers.csv";

open    (S1FILE, "$supplier1file") ;
if ($local eq 'n') { flock (S1FILE, LOCK_SH) or die "can't lock $supplier1file: $!"; }

while (<S1FILE>) {
    chomp;
    @linex = split(/\,/);
    &sfields;

    $lc_scode = lc $scode;
#   $name{$lc_scode}    = $sname;
    $tariff1{$lc_scode}     = $stariff1;
    $tariff2{$lc_scode}     = $stariff2;
    $tariff3{$lc_scode}     = $stariff3;
    $tariff4{$lc_scode}     = $stariff4;
    $sstar{$lc_scode}       = $sstar;
    $sadd1{$lc_scode}       = $sadd1;
    $sadd2{$lc_scode}       = $sadd2;
    $sadd3{$lc_scode}       = $sadd3;
    $sadd4{$lc_scode}       = $sadd4;
    $spcode{$lc_scode}      = $spcode;
    $sphone{$lc_scode}      = $sphone;
    $sfax{$lc_scode}        = $sfax;
    $sctry{$lc_scode}       = $sctry;
    $sbillcode{$lc_scode}   = $sbillcode;
    $snote{$lc_scode}       = $snote;
    }

close   (S1FILE);

#------------------------------------------------------------------------------------------
}
#------------------------------------------------------------------------------------------

#------------------------------------------------------------------------------------------
sub email1 {
#------------------------------------------------------------------------------------------

if ($local eq 'y') {
    open(MAIL,">$mailprog")     or die "opening $mailprog failed: $!";
    }
else
    {
    open(MAIL,"|$mailprog -t")  or die "opening $mailprog failed: $!";
    }

my $boundary = "====" . time() . "====";

print MAIL "To: asamsodien\@eccotours.biz\n";
#print MAIL "To: tim.winkworth\@flightcentre.co.uk\n";

print MAIL <<ENDOFTEXT;
From: Website <website\@domian.biz>
Subject: Rates Check Spreadsheet - $ifoldern
MIME-Version: 1.0
Content-Type: multipart/mixed; boundary="$boundary"

--$boundary
Content-Type: text/plain; charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

Hi $username,

Here is the information that you requested from the website.
--$boundary
Content-Type: application/octet-stream; name="Rates-$iregion.csv"			#calls the input region thus printing the tarrif file of
											#specified region that has been input in the screen file	 	
Content-Transfer-Encoding: quoted-printable
Content-Disposition: attachment; filename="Rates-$iregion.csv"

$print_S1FILE
--$boundary
Content-Type: application/octet-stream; name="Suppliers-$iregion.csv"			#reads supplier file and spits out the contact details
Content-Transfer-Encoding: quoted-printable
Content-Disposition: attachment; filename="Suppliers-$iregion.csv"

$print_S2FILE
--$boundary--

ENDOFTEXT

close (MAIL);

#------------------------------------------------------------------------------------------
}
#------------------------------------------------------------------------------------------

use canxpol;				#module with cancellation policy
use twkend;
use sfields;				#module defining supplier.CSV file into recognizable variables 
use tfields;				#module with tarrif fields defined as recognizable variables
use fchecks;
use dcheck;				#checks dates
use today;				#prints todays date	
use prices1;
exit;

I need to call a another CSV file by maipulating this one in order to spit out data that'll just be from the specified CSV fiile the problem lies at the top of the code where the $iregion is defined as the input and ultimately output. I need to determine a way to call the other CSV file instead of the one called $iregion. Our coder of this is on leave so I couldn't get an answer from him. I know this prob looks and sounds confusing but can anyone help me in terms of where to start, I'm really frustrated
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Feb 2008
Location: Seattle
Posts: 713
Reputation: jephthah is a jewel in the rough jephthah is a jewel in the rough jephthah is a jewel in the rough 
Rep Power: 4
Solved Threads: 46
jephthah's Avatar
jephthah jephthah is offline Offline
Master Poster

Re: Struggling Newbie

  #2  
Aug 17th, 2008
i thought this thread was about "strangling newbies"

imagine my dismay when i found a ten-mile long post full of incoherent code with no syntax coloring.
Why so serious?
Reply With Quote  
Join Date: Sep 2004
Posts: 6,300
Reputation: Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of 
Rep Power: 28
Solved Threads: 455
Super Moderator
Narue's Avatar
Narue Narue is offline Offline
Expert Meanie

Re: Struggling Newbie

  #3  
Aug 28th, 2008
Originally Posted by jephthah View Post
i thought this thread was about "strangling newbies"

imagine my dismay when i found a ten-mile long post full of incoherent code with no syntax coloring.

That was completely uncalled for, jephthah. If you're going to take the path of the angry programmer, at least try to follow the lead of the successful ones. There's a fine line between tough love and violating Keep It Pleasant.

And for future reference, the highlighting feature of code tags is optional. You should be thrilled the OP used code tags at all. It could have been pages and pages of unformatted line noise rather than relatively well formatted and clean Perl code. I see no reason for complaint.
I'm a programmer. My attitude starts with arrogance, holds steady at condescension, and ends with hostility. Get used to it.
Reply With Quote  
Join Date: Feb 2008
Location: Seattle
Posts: 713
Reputation: jephthah is a jewel in the rough jephthah is a jewel in the rough jephthah is a jewel in the rough 
Rep Power: 4
Solved Threads: 46
jephthah's Avatar
jephthah jephthah is offline Offline
Master Poster

Re: Struggling Newbie

  #4  
Aug 28th, 2008
yeah, actually, it is pretty doggone clean code, esp. for Perl... I dont remember it being like that. did it get cleaned up? guess not, i dont see evidence of an edit...

Really, I did read "strangling newbies" in my dyslexia and found it amusing... too bad my comment wasn't nearly as cute.

i guess since it was already over a month old, with no replies, i figured it was a dead thread.

sorry.


(and really, im not "angry" ... im just a run-of-the-mill internet a--hole )



.
Last edited by jephthah : Aug 28th, 2008 at 5:38 pm.
Why so serious?
Reply With Quote  
Join Date: Feb 2008
Location: Seattle
Posts: 713
Reputation: jephthah is a jewel in the rough jephthah is a jewel in the rough jephthah is a jewel in the rough 
Rep Power: 4
Solved Threads: 46
jephthah's Avatar
jephthah jephthah is offline Offline
Master Poster

Re: Struggling Newbie

  #5  
Aug 28th, 2008
Dear Achmat

sorry for crapping in your thread. since it was over a month old when i first saw it, i figured you were long gone. if you're still around, let me know and i'll try to help you with it.

it would help if you can provide example files such as the ones you're trying to use


.
Last edited by jephthah : Aug 28th, 2008 at 5:43 pm.
Why so serious?
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb Perl Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the Perl Forum

All times are GMT -4. The time now is 11:35 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC