Dermot wrote:
> Welcome,
> 
> 
> 2008/6/24 jet speed <[EMAIL PROTECTED]>:
>> Hi,
>>
>> I am beginner to perl,
>>
>> I have a file name cxout and i want to capture just the LUN 415, LUN 815
>> into arrray & then print from the array. my idea is to capture different
>> element form this file and the print form the array. Any help would be much
>> appericated. my sample script looks as below.
>>
>>
>> $filename = "cxout" ;
>> open (FILE, "< $filename" ) or die "Could not open $filename: $!";
>>
>> while (<FILE>) {
>> if ( $line = (/\^LUN \d+/) ) {
>>  print $line ;
>> };
>> };
>>
>> -------------------------------------------------------------------------------------
> ...snip
> 
> 
> This appears to do the job. There may be better ways to do it. In
> particualar I think a hash might be better here but this should get
> you going.
> 
> #!/bin/perl
> 
> use strict;
> use warnings;
> 
> my @luns;
> while (<DATA>) {
>  chomp;
>  next unless $_ =~ /LUN/;
>  $_ =~ /\[(LUN\s+\d+)\]/;

It is best to combine these two lines, if only because a line containing /LUN/
may not contain /\[LUN\s+\d+\]/. So just

  next unless /\[(LUN\s+\d+)\]/;

>  print $1,"\n";
>  push(@luns,$1);
> }
>

HTH,

Rob


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


Reply via email to