in reply to concatenation through substitution?

Regex work fine, but seems like using a fork to spread butter and cut bread. Whats wrong with:
1: die 'insufficient arguments' unless @ARGV == 1; 2: open(IN, $ARGV[0]) or die "unable to open '$ARGV[0]'"; 3: while (my $line = <IN>) { 4: my $prefix = sprintf '%4d', $.; 5: print "$prefix: $line"; 6: } 7: close IN; 8: or 1: die 'insufficient arguments' unless @ARGV == 1; 2: open(IN, $ARGV[0]) or die "unable to open '$ARGV[0]'"; 3: while (my $line = <IN>) { 4: my $prefix = sprintf '%4d: ', $.; 5: print $prefix . $line; 6: } 7: close IN; 8:
?


-Waswas

Replies are listed 'Best First'.
Re^2: concatenation through substitution?
by revdiablo (Prior) on Dec 30, 2004 at 21:47 UTC
    or 1: die 'insufficient arguments' unless @ARGV; 2: open(IN, $ARGV[0]) or die "unable to open '$ARGV[0]': $!"; 3: while (my $line = <IN>) { 4: printf "%4d: %s", $., $line; 5: } 6: close IN;
      Or for that matter:
      while (<>) { printf '%4d: %s', $., $_ }
Re^2: concatenation through substitution?
by Anonymous Monk on Dec 31, 2004 at 14:58 UTC

    Regex work fine, but seems like using a fork to spread butter and cut bread. Whats wrong with:

    Well, your suggestion doesn't use a fork to spread butter and cut bread, that's what's wrong! The point of the exercise is to figure out whether you can use a fork to spread butter and cut bread. It's not to spread butter and to cut bread, no, the essence is to use the fork. Read what the OP says:

    A question was posed to me about using substitution to perform concatenation -- more as a question as to whether substitution is flexible enough to do so rather than is this the best way to use the tools Perl provides.

    So, your suggestion utterly fails to answer the question - by avoiding the thing being queried.