See also: perlfunc, perlsyn, perlop, and Getopt::Long.my ($infile, $outfile, $indent) = @ARGV; # Use my for better scoping $infile ||= "default_infile"; # For a default value, in case none is supplied; # if the value is required, die if it doesn't exist; $outfile ||= "default_outfile"; $indent ||= "20"; # Rather than using the order of arguments, # you might like Getopt::Long instead. # It gives you good option-checking, and # dies if any options are missing or otherwise ungood. open(IN, $infile) or die "Can't open input file: $!"; # Good. You're checking the returns of every system call. open(OUT, ">$outfile") or die "Can't open output file: $!"; # A little easier to read with variable interpolation print "Starting..."; select (OUT); # So you don't have to type the filehandle name all the time print "<%\n"; $indent = ' ' x $indent; # To save the time required to recompute this; # if you're using the value of $indent later, just say # length($indent), or save this in a separate variable print "${indent}Response.Write(",($_ ? "$_ +" : ""),"vbNewLine)\n" wh +ile(chomp ($_ = <IN>)); # Using var interpolation and quick if (?:), # you can combine all this into one print # statement; chomp can be put inside the while # condition; then, since you have a one-statement # while loop, you can use the alternate syntax # to avoid messy braces print "%>\n"; print STDOUT "Done."; # You could also do select(STDOUT); first close IN or die "Can't close input file: $!"; close OUT or die "Can't close output file: $!";
In reply to Re: A simple input/output script, suggestions wanted
by premchai21
in thread A simple input/output script, suggestions wanted
by patgas
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |