in reply to Re^4: Problem with creating Files (maybe)
in thread Problem with creating Files

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 );