Im fairly new to Perl and was wondering why my code isnt printing to the files? Im trying to create 2 sepereate files based on the store number. could it be because I open and close my file within the loop? Thanks in advance. Jim..
$last_4_chars = "0001"; @all_stores = qw("24","25"); foreach $store(@all_stores) { #This sas file will seperate the datasets by stores #Opens file to write to die("Cannot open weekly_$store_pdf.sas to read from ") unless(open(FINAL, ">weekly_$store_pdf.sas")); $prep_pdf = "libname bce '/cdw/dept/dss/home_dir/s006258/BCE';\n". "proc sql;\n". "SELECT FILEDATE,RPTSTORE,RPTTEAM,FIRSTNAME,LASTNAME,WTDTRAN, \n". " WTDOFFERS,WTDAPPS, substr(WTDOFFERS/WTDAPPS,0,5) as WTD_RATE, +\n". " (case\n". " when (substr(sum(WTDAPPS)/sum(WTDOFFERS),0,4)*100) >= 1. +2 then 'G'\n". " when (substr(sum(WTDAPPS)/sum(WTDOFFERS),0,4)*100) <= 1. +2 and\n". " (substr(sum(WTDAPPS)/sum(WTDOFFERS),0,4)*100) >= + .65 then 'Y'\n". " when (substr(sum(WTDAPPS)/sum(WTDOFFERS),0,4)*100) < .65 + then 'R'\n". " end) as WTD_Color \n". " MTDTRAN,MTDOFFERS,MTDAPPS, substr(MTDOFFERS/MTDAPPS,0,5) as M +TD_RATE,\n". " (case\n". " when (substr(sum(WTDAPPS)/sum(WTDOFFERS),0,4)*100) >= 1. +2 then 'G'\n". " when (substr(sum(WTDAPPS)/sum(WTDOFFERS),0,4)*100) <= 1. +2 and\n". " (substr(sum(WTDAPPS)/sum(WTDOFFERS),0,4)*100) >= + .65 then 'Y'\n". " when (substr(sum(WTDAPPS)/sum(WTDOFFERS),0,4)*100) < .65 + then 'R'\n". " end) as MTD_Color\n". "FROM bce.yearly_g$last_4_charsv00\n". "WHERE RPTSTORE = $store\n". "Order by RPTTEAM"; print FINAL "$prep_pdf"; close(FINAL); }

In reply to Printing to file by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.