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:

BEGIN { $^I = ".tmp"; } BEGIN { $/ = "\n"; $\ = "\n"; } LINE: while (defined($_ = <ARGV>)) { chomp $_; our(@F) = split(' ', $_, 0); @ar = split(/([ABC])/, $F[5], 0); $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; } -e syntax OK

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.pl

Whilst 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:

my @ARGV = glob("*.txt"); foreach my $ARGV {

And alternatively getting the directory itself:

use cwd my $dir = cwd() foreach my $files (global("$dir/*.txt")) {

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?


In reply to Loading all .txt files within current directory by TJCooper

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.