Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re^5: Problem with creating Files (maybe)

by Anonymous Monk
on Jul 25, 2014 at 10:49 UTC ( [id://1095029]=note: print w/replies, xml ) Need Help??


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

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1095029]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others avoiding work at the Monastery: (6)
As of 2024-04-18 12:04 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found