Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

(tye)Re: 'perl -p' ne 'cat'

by tye (Sage)
on Jun 04, 2002 at 19:06 UTC ( [id://171603]=note: print w/replies, xml ) Need Help??


in reply to 'perl -p' ne 'cat'

At first, I was thinking I could support "perl -p" (not in the #! line) giving a helpful message since it is expecting both its script and its input from STDIN. But I immediately thought of using a "TTY" as STDIN such that you can have two "ends of file" on the one STDIN:

shell> stty eof ^Z shell> perl -p >>notes BEGIN { print ''.localtime(),$/ } $_= "$.: $_" CTRL-Z Here are my notes for today. I should really make this a real script. CTRL-Z

But then I realized you can use __END__ to do this trick anywhere:

shell> cat script $_= "$.: $_"; __END__ Testing this. shell> perl -p <script 1: Testing 2: this.

Granted, I haven't come up with a great use of this feature, but I'm reluctant to promote disabling it merely based on my lack of imagination. (:

        - tye (but my friends call me "Tye")

Replies are listed 'Best First'.
Re: (tye)Re: 'perl -p' ne 'cat'
by danger (Priest) on Jun 04, 2002 at 19:57 UTC

    I often add cases of test data after __END__ or __DATA__ in scripts that use while(<>) loops --- and I used to always switch between <> and <DATA> for testing purposes (and usually forgot to switch back when done). I recall being quite happy a few years back when I realized ("Doh!") I could just leave the bare diamond op and run the script on the test data via  perl -w < script.pl. Actually, I mostly test within the editor by sending the buffer to a filter of  perl -w with output directed to another buffer, but its the same thing.

Log In?
Username:
Password:

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

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

    No recent polls found