[EMAIL PROTECTED] wrote:
> Hi Perlers...........

Hello,

> I need to extract line between two words........
> 
> like 
> 
> 
> @line =  "The Sun rises in 
>                 the east and ";
> 
> Now I want to extract the line from The word to east
> 
> For tht I am using the following code:
> 
> #!/usr/bin/perl
> use warnings;
> use strict;
> my @line = "The Sun rises in
>                 the east and ";
> my $store;
> 
> while(<@line>){

The <> operator can be used as either the readline operator or the glob
operator depending on how it is used.

$ perl -MO=Deparse -e'
my @line = "The Sun rises in
                the east and ";
while(<@line>){
print if $_ =~ /The/ .. /east/ ;

}
print "\n";
'
my(@line) = "The Sun rises in\n                the east and ";
use File::Glob ();
while (defined($_ = glob(join($", @line)))) {
    print $_ if $_ =~ /The/ .. /east/;
}
print "\n";
-e syntax OK

All that glob does is split the string on whitespace and return each word in
turn.  You could do the same thing with:

for ( split ' ', "@line" ) {

and it will be more efficient because glob has to check the file system to see
if those "files" exist.


> print if $_ =~ /The/ .. /east/ ;

If you are going to use $_ then:

print $_ if $_ =~ /The/ .. $_ =~ /east/ ;

Or just don't use it:

print if /The/ .. /east/ ;


> }
> print "\n";
> 
> 
> But the output is coming like this TheSunrisesintheeast
> 
> But I want the output like this The Sun rises in the east

my @line = "The Sun rises in
                the east and ";
print join ' ', split ' ', $line[ 0 ];

Or:

my @line = "The Sun rises in
                the east and ";
$line[ 0 ] =~ s/\s+/ /g;
print $line[ 0 ];




John
-- 
use Perl;
program
fulfillment

-- 
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