Vishal Vasan wrote:
> Hi All,
> 
> I have a file with the following contents (temp.txt).
> A1110
> G1115
> B1110
> C1111
> D1111
> E1113
> F1115
> and so on. I have to read the contents from this file and create 2
> seperate files. The 1st file contains the lines ending with 0 and 1
> while the 2nd file contains the lines ending with 3 and 5. I can do
> this easily by creating a seperate perl script. But I have a
> constraint. I should not write a seperate file to do this processing.
> 
> I am calling the perl from a shell script. Is there any way of calling
> the Perl program "in-line" with all the required parameters? "In-line"
> means no seperate file containing the script.

Yes, do something like this (assuming a Bourne-type shell; others will have
to help you with csh):

   #!/bin/sh

   ...

   perl <<'EOT' - input.dat
   while(<>) {
      ...
   }
   EOT

The "-" means that your script is coming from STDIN. See perldoc perlrun.

> 
> Is it worth doing this? Is there a better way of doing it?

How about using awk?

   awk '/[01]$/ {print >>"01.dat"} /[35]$/ {print >>"35.dat"}' input.dat

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to