Clear questions and runnable code get the best and fastest answer |
|
PerlMonks |
Loading all .txt files within current directoryby TJCooper (Beadle) |
on Jan 31, 2016 at 12:13 UTC ( [id://1154128]=perlquestion: print w/replies, xml ) | Need Help?? |
TJCooper has asked for the wisdom of the Perl Monks concerning the following question: I'm trying to deparse the following one-liner (using -MO=Deparse) in-order to construct it as a .pl script: perl -i.tmp -lane '@ar = split /([ABC])/, $F[5]; $s = 0; $s += $n * ("A" eq $op ? 0 : 1) while ($n, $op) = splice @ar, 0, 2; $w = "g"; $l = length($F[9]); print "$w\t$F[2]\t$F[3]\t$l\t$F[5]\t0" if $F[1] =~ 50; $w = "y"; $l = length($F[9]); $p = $F[3]+$s; print "$w\t$F[2]\t$p\t$l\t$F[5]\t$s" if $F[1] =~ 10; print "Head1\tHead2\tHead3\tHead4\tVar1\tVar2" if $.==1; close ARGV if eof;' *.txt;-MO=Deparse Output:
The deparsed output does not appear to include the ability to read in all .txt files within the current directory - without having to specify them on the command line such that they feed into ARGV. I was under the impression I could simply add to line-1: my @ARGV = glob("*.txt");And each file would be passed to <ARGV> for processing, however when running: perl script.plWhilst in a current directory containing .txt files, nothing happens. No error is returned, but it does not process anything nor complete. I have also tried to wrap the code in a for-loop using:
And alternatively getting the directory itself:
But this produces the same issue. What am I missing? Also, given that I was originally creating backups using -i within the one-liner, how is this now handled within a script? Could this also cause issues?
Back to
Seekers of Perl Wisdom
|
|