Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re: concatenation through substitution?

by waswas-fng (Curate)
on Dec 30, 2004 at 21:22 UTC ( [id://418414]=note: print w/replies, xml ) Need Help??


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.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others having a coffee break in the Monastery: (7)
As of 2024-03-28 10:30 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found