Sorry for my stupidness, but if you tell me what should I write, it'll save me.

Write more subs , debug small subs, write more subs ... easier to trace ... like this

#!/usr/bin/perl -- ## ## ## perltidy -olq -csc -csci=3 -cscl="sub : BEGIN END " -otr -opr -ce +-nibc -i=4 -pt=0 "-nsak=*" ## perltidy -olq -csc -csci=10 -cscl="sub : BEGIN END if " -otr -opr +-ce -nibc -i=4 -pt=0 "-nsak=*" #!/usr/bin/perl -- use strict; use warnings; use Path::Tiny qw/ path tempdir /; ## makes your life easier Main( @ARGV ); exit( 0 ); sub Main { #~ my $dir = tempdir(); ## you might use for testing/development my $dir = '.'; my @files = qw/ ro sham bo /; touchFiles( $dir, @files ); ## so you don't have to loop twice fillFiles( $dir, @files ); } ## end sub Main sub touchFiles { return warn "no files created in testing"; my $dir = shift; for my $file ( @_ ) { path( $dir, $file )->touchpath; ## Path::Tiny saves :) } } ## end sub touchFiles sub fakeLink { return "its fake @_\n"; } ## end sub fakeLink sub realLink { return "its real @_\n"; } ## end sub realLink sub fillFiles { my $dir = shift; chdir $dir; for my $file ( @_ ) { fillFile( $file ); } } ## end sub fillFiles sub fileExists { return -e shift; } ## end sub fileExists sub fillFile { my( $filename ) = @_; ## the fakeness begins my $outfile = \*STDOUT; #~ createHeader( $outfile , ... ); createButtons( $outfile, $filename ); #~ createFooter( $outfile , ... ); } ## end sub fillFile sub layDft { my( $file, $search, $replace ) = @_; ## your logic here return $file, $file; } ## end sub layDft sub createButtons { my( $outfh, $filename ) = @_; my %layDft = layDft( $filename, 'ay', 'dft' ); while( my( $file, $link ) = each %layDft ) { if( fileExists( $filename ) ) { print $outfh realLink( $filename ); } else { print $outfh fakeLink( $filename ); } } } ## end sub createButtons __END__ no files created in testing at snickers line 25. its fake ro its fake sham its fake bo

Once you get more of these you're realize you probably want to have createButtons return a string or array of strings so fillFile instead of using  createButtons( $outfile, $filename ); would use  print $outfile createButtons( $filename );


In reply to Re^5: Problem with creating Files (maybe) by Anonymous Monk
in thread Problem with creating Files by David92

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.