Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Re: perl one-liner

by Kanji (Parson)
on Jun 22, 2005 at 17:02 UTC ( #469095=note: print w/replies, xml ) Need Help??


in reply to perl one-liner

perl -0777 -i -nle 'print q{hello}' test.pl

...but as others have pointed out, it's much easier to handle this sort of thing with shell redirection.

    --k.


Replies are listed 'Best First'.
Re^2: perl one-liner
by mojobo (Initiate) on Jun 22, 2005 at 21:22 UTC
    hi guys,
    actually shell redirection is what i have been doing in the past (without perl), but i wanted to have a one-liner that can be called externally. The basic idea is to automate editing a file with different access permissions than the user, via sudo, and not have to chown the file first to the user..
    i can already edit a file if there is content in the file, without using shell redirection, using a perl one-liner like this:
    perl -i -ne 'print unless 1 .. 100; print q{testing} if$.==1' somefile

    of course this doesn't truncate the file, which is what i was interested in attempting..
Re^2: perl one-liner
by mojobo (Initiate) on Jun 22, 2005 at 21:25 UTC
    Hi Kanji, i didn't see your reply when i was posting mine..
    thanks! that's perfect..
    thanks to everyone for their help.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://469095]
help
Chatterbox?
[Corion]: Yay! As I had to reset my phone again, I now also back up my SMS automatically. Highly conveniently, there is a program to back up my SMS to my IMAP server as mails ;)
[1nickt]: Corion this is an android phone? If so, are you encountering problems with recent upgrades? Lately my phone dies suddenly quite often, seemingly coredumps caused by interaction of two actions, eg phone playing a sound and user swiping simultaneously :-/

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (5)
As of 2017-11-18 15:07 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    In order to be able to say "I know Perl", you must have:













    Results (277 votes). Check out past polls.

    Notices?