Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re^2: A Tribute To The Monks Of Wisdom

by koolgirl (Hermit)
on Nov 17, 2008 at 00:02 UTC ( [id://723965]=note: print w/replies, xml ) Need Help??


in reply to Re: A Tribute To The Monks Of Wisdom
in thread A Tribute To The Monks Of Wisdom

Wow, the diamond operator opens the files? Is this only true for @ARGV, or can you also open other files without "open"? Is this something sort of like not declaring your variables, in that just because Perl allows it, doesn't mean it's good form, or is it something commonly done when using @ARGV?

Replies are listed 'Best First'.
Re^3: A Tribute To The Monks Of Wisdom
by gwadej (Chaplain) on Nov 17, 2008 at 01:12 UTC

    The diamond always works on the files in @ARGV. It also provides another level of magic, if @ARGV is empty, it reads STDIN. This is a very common idiom for writing filter programs.

    Another useful trick is to realize that @ARGV starts out with the command line parameters, but it is just a variable. You can change it. (For example, remove some flags or commands and then process the rest, or use the parameters to construct a list of filenames that replaces @ARGV before processing.

    The last trick is not one to be used lightly, because it's likely to confuse some people. But, sometimes it is exactly the tool you need.

    G. Wade
Re^3: A Tribute To The Monks Of Wisdom
by blazar (Canon) on Nov 21, 2008 at 12:17 UTC

    I personally believe that the "only" risk associated with it is that you can pass arbitrary code to be executed, so it all depends on whom do you plan to make your script available to and to security settings. Thus

    perl -pe ''

    can be considered as an equivalent to cat(1) (well, except for the bazillion cmd line switches, of course!) but if you do

    perl -pe '' "rm -rfv $HOME |"

    then you're on your own. However FWIW it just boils down to doing

    rm -rfv $HOME

    in the first place. You "just" have to make sure others are not allowed to do the same or similar things, if you use the diamond operator: of course the issue has nothing to do with Perl anymore, but with your system's administration instead.

    --
    If you can't understand the incipit, then please check the IPB Campaign.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others chanting in the Monastery: (3)
As of 2024-04-25 23:34 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found