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

Re: Concatenation connected to find pipe behaves wierdly.

by sfink (Deacon)
on Jan 31, 2006 at 18:05 UTC ( [id://526829]=note: print w/replies, xml ) Need Help??


in reply to Concatenation connected to find pipe behaves wierdly.

find is giving you a list of filenames terminated by newlines. So when you print qq($_), you're printing out a newline after your filename. So all your foo are belong to us... dammit... all of your foo end up just after a newline, aka the beginning of the next line.

The quick fix isfind | perl -lne "print qq($_) . q(foo)"

That will strip off the newline when reading each line in, and append a newline to the output of print.

Replies are listed 'Best First'.
Re^2: Concatenation connected to find pipe behaves wierdly.
by blazar (Canon) on Feb 01, 2006 at 10:47 UTC

    And while we're there we may also remind him not to unnecessarily quote all variables:

    perl -lne "print $_ . 'foo'"

    Alternatives:

    • interpolation, but not on a single variable: qq(${_}foo) - ugly, but qq($_foo) wouldn't work;
    • introducing -p:
      perl -lpe "$_.='foo'"
    • ...

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others sharing their wisdom with the Monastery: (6)
As of 2024-04-24 12:34 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found