Re: count the characters between the matches

2006-10-24 Thread Rob Dixon
zhihua li wrote:
 hi netters,
 
 I'm curious if there's any smart code to calculate the distance 
 between the matches in a text.
 Suppose I have a text like this:  
 syhk...yes...uhg;ka=...yes...yiealg.yes...ghe;a...yes...
 Apparently it has multiple words of yes. I'd like to know how many 
 characters there are between the first and the last yes. The way I now 
 come up with to do this is to use substitution to mark the first and 
 the last match, then use a counting loop to calculate the 
 characters..rather straightforward and stupid method.
 
 Anyone has a better idea about that?
 
 Thanks a lot!

Hi.

If you use a regex to capture the characters between the yeses you can just take
the length of the capture:

my $text = q(syhk...yes...uhg;ka=...yes...yiealg.yes...ghe;a...yes...);
$text =~ /yes(.*)yes/;
my $nchars = length $1;
print $nchars, \n;

The answer's 48!

HTH,

Rob

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




Re: Unitialised value in String

2006-10-24 Thread Rob Dixon

Richard Luckhurst wrote:

Hi All

I am a perl newbie.

I have a small perl script that is actually a cgi-bin script. I am told that
until a recent server change over it ran fine however now it produces no output.
I have tried running it from a command line and redirecting the input it would
have received as a cgi-bin script from a text file. I am getting a couple of
Use of uninitialized value in concatenation (.) or string errors and I can not
see why.

The script is as follows

#!/usr/bin/perl
#
# log-errors cgi-bin script to display the last 2000 lines of an error log.
# domain is the domain name of the virtual apache server
#

require '/www/server/cgi-bin/cgi-lib.pl';
ReadParse(*in);
$domain = $in{'domain'};
print Content-type: text/html\n\n;
print htmlheadtitleExodus Web Server Log/title/head\n;
print body link=\blue\ vlink=\blue\\n;
print font size=\4\bLast 2000 Lines of the Error log for: 
$domain/b/fontbr\n;
print font size=\1\br/fontGo to a href=\#bottom\iEnd of 
log/i/abrbr\n;
$tail = `tail -n2000 /var/log/httpd/$domain-error_log 2/dev/null | 
tac`;
$tail =~ s//lt\;/g;
$tail =~ s//gt\;/g;
print pre$tail\/pre\n;
print a name=\bottom\/a;
print brbEnd of log/bbr\n;
print /body/html\n;
exit 0;


When I run the script from the command line with the command

perl -w  log-err*  test.txt

Where test.txt contains domain=www.resmaster.com

I get the following output

Content-type: text/html

htmlheadtitleExodus Web Server Log/title/head
body link=blue vlink=blue
Use of uninitialized value in concatenation (.) or string at log-errors line 10.
font size=4bLast 2000 Lines of the Error log for: /b/fontbr
font size=1br/fontGo to a href=#bottomiEnd of log/i/abrbr
Use of uninitialized value in concatenation (.) or string at log-errors line 12.
pre/pre
a name=bottom/abrbEnd of log/bbr
/body/html

It seems that the value of the domain is not being passed in correctly and it is
not being passed down through the script.

When I run the script as a cgi-bin script called from a web page I get the html
code produced by the print statements but I get nothing from the $tail variable.
This is what I would expect as I get nothing between the pre/pre tags when I
run it from a command line.

I would appreciate any help in sorting out this problem.


Hello Richard

You are right that your problem is almost certainly because $domain is not being
set up properly, but the error lies in the ReadParse() subroutine in the
cgi-lib.pl file which you don't show. You are looking at a very old piece of
Perl programming which is doing things in ugly ways, so please don't try to
learn anything from its methods!

Rob

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




Re: Dynamical our/my/local

2006-10-24 Thread Oleg V. Volkov
Jenda Krynicky [EMAIL PROTECTED] wrote:
  Provide code, so we can guess better.
 Here's example how I use it in functions:
 sub add_service{
  our($login, $type_id, $account_id, $ap_id, $rule);
 Please DON'T!
 You DO want to use
my ($login, $type_id, $account_id, $ap_id, $rule);

No. While I do want to use my, I, unfortunately, have to use globals,
because Alias::attr (and, as far as I understand all other
modules that perform namespace/glob tricks) operate exclusively
on globals.

 Maybe there are already modules that will do what you want and more. 
 And safer. Have a look at 
 Go to http://search.cpan.org/ and see
 Params::Named, Sub::Parameters, Sub::Signatures, Params::Smart, 
 Perl6::Parameters, Sub::Parameters, ... 

Though I didn't check entire list yet, I've seen some of them before
and they're either source filters or just expand arguments in some
kind of hash, which doesn't give me benefit of one-time dereference
that I get with aliasing arguments to variables either manually
or with Alias::attr, and this speed gain is the thing that I need
in functions with long loops.

-- 
Oleg Rowaa[SR13] V. Volkov

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




Re: count the characters between the matches

2006-10-24 Thread Dr.Ruud
zhihua li schreef:

 I'm curious if there's any smart code to calculate the distance
 between the matches in a text.
 Suppose I have a text like this:
 syhk...yes...uhg;ka=...yes...yiealg.yes...ghe;a...yes...
 Apparently it has multiple words of yes.
  I'd like to know how many characters there are between the first and
 the last yes. The way I now come up with to do this is to use
 substitution to mark the first and the last match, then use a
 counting loop to calculate the characters..rather straightforward
 and stupid method.

 Anyone has a better idea about that?


If the parts have some meaning later on, I would use a capturing split:

#!/usr/bin/perl
  use warnings ;
  use strict ;

  { local ($\, $) = (\n, '') ;

while (DATA)
{
  @_ = split /(yes)/ ;   #  -- the meat
  print length @_[2 .. $#_-2] ;
}
  }

__DATA__
..yes..yesyes..yes...
yes..yesyes..yes...
yes..yesyes..yes

This depends on the last 'yes' not being at the very end of the string,
as is the case with the DATA-approach, because then there is always at
least a newline following it.

-- 
Affijn, Ruud

Gewoon is een tijger.


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




Re: Dynamical our/my/local

2006-10-24 Thread Dr.Ruud
Oleg V. Volkov schreef:

 Alias::attr (and, as far as I understand all other
 modules that perform namespace/glob tricks) operate 
 exclusively on globals.

Did you check Data::Alias too?

From the examples:

  alias my $fi = $self-{FrobnitzIndex};

This works a bit like 

  for my $fi ($self-{FrobnitzIndex}) { ... }

-- 
Affijn, Ruud

Gewoon is een tijger.

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




File download in background.

2006-10-24 Thread Beginner
Hi All,

I posted this to this list as it's as much a fork() issue as a CGI 
one. Hope I've done the right thing.

I am trying to display a html page and at the same time download a 
file from a multi-part form. The files are quite large to I wanted to 
minimise the time it took for the browser to render the page by 
having the file download happen in the background as it's not 
required for the content.

I thought that fork() would be the function for this but my efforts 
are pouring the content into the browser window (not very pretty!). I 
read that fork() inherits the file descriptors from the parent and I 
guess this is why the file is being displayed. The file is copied to 
the remote server so I am half-way there.

Can anyone advice me how best to achieve this? Is fork() the right 
function in a CGI environment? Can I avoid the output going to the 
browser? 

An abridged version of my effort is below. Any tips are much 
appreciated.

TIA.
Dermot.


=
use strict;
use warnings;
use CGI qw(:standard);
use CGI::Carp qw(fatalsToBrowser);
# $CGI::POST_MAX = 1024 * 1; # Set limit to 10MB
$| = 1; # Not sure if this is necessary.

my $q = new CGI;

print $q-header()
print $q-start_html();

# The file to download.
my $filename = $q-param('file-path');
my $dsc_name = $q-param('basename');

my $childpid;
if (! defined($childpid = fork()) ) {
die Cannot fork for file download: $!\n;
}
elsif ($childpid == 0) {
my $untainted_filename;

if (! $filename  $q-cgi_error) {
print $q-header(-status=$q-cgi_error);
exit 0;
}
# Remove the spaces to avoid name issues.
(my $tmp_name = $dsc_name) =~ s/\W+/_/g;
if ($tmp_name =~ /^([-\@:\/\\\w.]+)$/) {
$untainted_filename = $1;
}
else {
die EOT;
Unsupported characters in the filename $tmp_name.
Your filename may only contain alphabetic characters and numbers,
and the characters '_', '-', '\@', '/', '\\' and '.'
EOT
}
my $output_file = /tmp/.$tmp_name..tmp;
my ($bytesread,$buffer);
my $numbytes = 1024;
open(OUT, $output_file) or die Can't open $output_file: 
$!\n;
while ( $bytesread = read($filename, $buffer, $numbytes)) {
print OUT $buffer;
print $buffer;
}
close(OUT);
}
else {

print Your file is on it's way in the meantime.;
print $q-end_html;
}


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




Re: File download in background.

2006-10-24 Thread Beginner
On 24 Oct 2006 at 12:12, Beginner wrote:

Sorry going to top post as I made a mistake. I was doing a straight 
print and that was why the file was was being displayed. 
Apologies.
Dp.


 Hi All,
 
 I posted this to this list as it's as much a fork() issue as a CGI 
 one. Hope I've done the right thing.
 


 open(OUT, $output_file) or die Can't open $output_file: 
 $!\n;
 while ( $bytesread = read($filename, $buffer, $numbytes)) {
 print OUT $buffer;
 print $buffer;


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




Re: Dynamical our/my/local

2006-10-24 Thread Oleg V. Volkov
Dr.Ruud [EMAIL PROTECTED] wrote:
 Alias::attr (and, as far as I understand all other
 modules that perform namespace/glob tricks) operate 
 exclusively on globals.
 Did you check Data::Alias too?

Really nice, but, alas, no Win32 and that's where I run most
of my stuff. It also wouldn be slower for functions that
are called often, because there's no functionality similar
to Alias' attr, which is XS.

Speaking of globals, AFAIK, I have virtually no drawbacks
against my, as long as I use our variables inside
the scope. So what's bad there in using our?

-- 
Oleg Rowaa[SR13] V. Volkov

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




Re: Opening .dat file in perl

2006-10-24 Thread Goksie
Tommy Nordgren wrote:

 On 20 okt 2006, at 21.31, Goke Aruna wrote:

 On 10/20/06, John W. Krahn [EMAIL PROTECTED] wrote:

 Goksie wrote:
  Thanks all for the past help
 
  Can someone advice me on how i can open .dat file in perl script?

 open my $fh, '', '00016367.DAT' or die Cannot open '00016367.DAT'
 $!;



 John
 -- 

 thanks John

 Each time i used it that way its giving me

 GLOB(0x22519c)


 This might occur because you are trying to print the file handle
 instead of reading FROM it.
 
 thanks

 goksie
 Thank you,

the code is as follow

#!c:/perl/bin/perl
 use warnings ;
 use strict ;
 my $fl = c:/Perl/CDR_MSC_DAT/00016363.DAT;
 { local ($\) = (\n) ;
  open my $fh, '', $fl or die open '$fl': $! ;
  while ($fh)
  {
print $fh;
  }
  }

the output is
perl fdmacdr.pl
GLOB(0x225218)
GLOB(0x225218)
GLOB(0x225218)
its not a music file... cos another program though proprietary has
opened it.

goksie

 --
 Home is not where you are born, but where your heart finds peace -
 Tommy Nordgren, The dying old crone
 [EMAIL PROTECTED]



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





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




Jumping to inner loops

2006-10-24 Thread Luba Pardo

Dear all:
I need to write a script that, given that a statement in the OUTER loop is
true goes immediatly to the INNER loop and finishes it before iterates in
OUTER again.
The problem is that I do not how to ask the program to run the inner loop
once the statement of the loop OUTER  is true.
Example: once that the element h=0 from arra1 is found in array2,  then move
to the inner loop for h to become h+2 and not h+4. Then when the 4
consecutive elements in the array 1are found in the array 2, then make h=
h+4 in the array1. Elements in the other array should move also every 4
elements. I tried several options like next and redo, but I can not get what
I want. Hope someone can help.
Thanks in advance.
Luba

The script looks like:

use strict;
use warnings;
my @arra1=(1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24);
my @arra2=
(0,0,0,0,0,0,0,0,0,0,0,0,x,x,0,0,3,4,d,e,1,2,a,b,5,6,l,c,x,x,0,0,7,8,f,g,0,0,0,0,0,0,0,0,0,0,0,0,11,12,n,o,13,14,p,q,0,0,0,0,0,0,0,0,15,16,r,s,21,22,aa,bb,19,20,cc,dd,17,18,ee,ff,23,24,gg,hh,21,22,jj,kk,9,10,m,i);


my $k=0;


for ($h=0; $h=$#arra1; $h= $h+4) {


OUTER: if ($arra2[$k]== $arra1[$h] $arra2[$k+1]== $arra1[$h+1] ||
$arra2[$k]== $arra1[$h+1] $arra2[$k+1]== $arra1[$h]) {
  print  $arra2[$k] and $arra2[$k+1] give $arra2[$k+2] and
$arra2[$k+3]\n;
$k=0;


INNER: if ($arra2[$k]== $arra1[$h+2] $arra2[$k+1]== $arra1[$h+3] ||
$arra2[$k]== $arra1[$h+3] $arra2[$k+1]== $arra1[$h+2]){
  print  $arra2[$k] and $arra2[$k+1] give $arra2[$k+2] and
$arra2[$k+3]\n;
 $k=0;
  }

}  elsif($k=$#arra2) {
  $k=$k+4;
  $h = $h-4;
 }
}


Re: Re: Opening .dat file in perl

2006-10-24 Thread Tom Phoenix

On 10/24/06, Goksie [EMAIL PROTECTED] wrote:


Tommy Nordgren wrote:
 This might occur because you are trying to print the file handle
 instead of reading FROM it.



print $fh;


Yep, Tommy Nordgren nailed it.

If you want to read binary data from a filehandle, you probably want
to start with the functions binmode() and read(), both documented in
perlfunc.

Hope this helps!

--Tom Phoenix
Stonehenge Perl Training

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




RE: Jumping to inner loops

2006-10-24 Thread Charles K. Clarkson
Luba Pardo mailto:[EMAIL PROTECTED] wrote:

: Example: once that the element h=0 from arra1 is found in
: array2, then move to the inner loop for h to become h+2
: and not h+4. Then when the 4 consecutive elements in the
: array 1are found in the array 2, then make h= h+4 in the
: array1. Elements in the other array should move also
: every 4 elements.

Can you explain that better? It really makes very
little sense. Ignore the script and just explain each step
you wish to take. Forget about h and k and the inner and
outer loop, just explain what you are trying to accomplish.


HTH,

Charles K. Clarkson
-- 
Mobile Homes Specialist
Free Market Advocate
Web Programmer

254 968-8328

http://www.clarksonenergyhomes.com/

Don't tread on my bandwidth. Trim your posts.


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




Re: Opening .dat file in perl

2006-10-24 Thread John W. Krahn
Goksie wrote:
 Tommy Nordgren wrote:
On 20 okt 2006, at 21.31, Goke Aruna wrote:

On 10/20/06, John W. Krahn [EMAIL PROTECTED] wrote:
Goksie wrote:

Can someone advice me on how i can open .dat file in perl script?
open my $fh, '', '00016367.DAT' or die Cannot open '00016367.DAT'
$!;

Each time i used it that way its giving me

GLOB(0x22519c)

This might occur because you are trying to print the file handle
instead of reading FROM it.
 
 the code is as follow
 
 #!c:/perl/bin/perl
  use warnings ;
  use strict ;
  my $fl = c:/Perl/CDR_MSC_DAT/00016363.DAT;
  { local ($\) = (\n) ;
   open my $fh, '', $fl or die open '$fl': $! ;

You are opening the file READONLY (the second argument '').


   while ($fh)

This is fine, you are allowed to read from the $fh filehandle.


   {
 print $fh;

You can't print to the filehandle because it is READONLY.  You probably want
to print the contents of the $_ variable:

  print $_;


   }
   }
 
 the output is
 perl fdmacdr.pl
 GLOB(0x225218)
 GLOB(0x225218)
 GLOB(0x225218)
 its not a music file... cos another program though proprietary has
 opened it.


John
-- 
Perl isn't a toolbox, but a small machine shop where you can special-order
certain sorts of tools at low cost and in short order.   -- Larry Wall

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




Worse than just a beginner

2006-10-24 Thread Brian
I'm wondering if someone can do me an enormous favour and write a cgi 
for me please, I just can't get my head around the books I have, they 
might just as well be written in Klingon.


I would like to be able to enter a number into a form. (eg 1234)
This number would also be output to result.html which I will get to in a 
minute.


So, taking the input (x), it needs to be compared against a fixed sum 
(z). (eg z = 25)
If x is greater than z, then value z needs to keep being subtracted 
until equal to or less than z. (but not less than 1)
(if input is a 6 digit number, another sum, say 2000, can be included to 
calc a bit faster than subtracting 25 over and over)


I have a string of numbers or letters that is z (25) in length, 
presently in a text file, but there is no reason why this string can't 
reside in the script as it will never change.
The end result of comparing x to z  = 9, so 9th char in string z is to 
be picked up.
I wish to print using if statements so that I could  have slight 
differences in the html of result.html to count for the 25 different 
possibilities of z.

The original input needs to be reflected in any instance of result.html.
Hopefully without any of the code being viewable with the exception of 
the html code.


I know it's a big ask, but I would really appreciate it.
Thanks
Brian

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




Re: Worse than just a beginner

2006-10-24 Thread Omega -1911

On 10/24/06, Brian [EMAIL PROTECTED] wrote:

I'm wondering if someone can do me an enormous favour and write a cgi
for me please, I just can't get my head around the books I have,


Sounds like a homework assignment...

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




Re: Worse than just a beginner

2006-10-24 Thread Brian

Omega -1911 wrote:


On 10/24/06, Brian [EMAIL PROTECTED] wrote:


I'm wondering if someone can do me an enormous favour and write a cgi
for me please, I just can't get my head around the books I have,



Sounds like a homework assignment...


Not at all , and just for the record, I am 50 years old.
Brian


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




RE: Worse than just a beginner

2006-10-24 Thread Charles K. Clarkson
Brian mailto:[EMAIL PROTECTED] wrote:

: I'm wondering if someone can do me an enormous favour and
: write a cgi for me please, I just can't get my head around
: the books I have, they might just as well be written in
: Klingon.

You want us to feed you for a day?

Think about what needs to be done. What are the steps
needed to perform the actions to get the results you want?
Here's an example.

1. Get numerical user input.
2. Divide input from step 1 by 25 and keep the remainder.
3. Use the result from step 2 as an index into a string.
4. ...


Notice that my algorithm does not contain elements of a
specific solution. These steps could equally apply to VB, C#,
Java or Perl.

Once you have listed all the steps needed to describe the
problem then you can apply a specific solution. Look at each
step and solve only that step. Solutions are a lot easier if
you break them down into more manageable pieces first.

BTW, You don't have to solve them in the order they will
be used. Solve the easiest one first, then the next and so
on.

Look at step 2 above. Repeated subtractions gets you a
remainder. Now you have a solution for the remaining value.
Try to solve the rest yourself. Come back here when you get
stuck solving a step.

print 1 % 25, \n;
print 30 % 25, \n;
print 300 % 25, \n;
print 1234 % 25, \n;
print 60001 % 25, \n;



HTH,

Charles K. Clarkson
-- 
Mobile Homes Specialist
Free Market Advocate
Web Programmer

254 968-8328

http://www.clarksonenergyhomes.com/

Don't tread on my bandwidth. Trim your posts.


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




Re: Jumping to inner loops

2006-10-24 Thread Rob Dixon

Luba Pardo wrote:
 Dear all:
 I need to write a script that, given that a statement in the OUTER
 loop is
 true goes immediately to the INNER loop and finishes it before iterates in
 OUTER again.
 The problem is that I do not how to ask the program to run the inner loop
 once the statement of the loop OUTER  is true.
 Example: once that the element h=0 from arra1 is found in array2,  then
 move
 to the inner loop for h to become h+2 and not h+4. Then when the 4
 consecutive elements in the array 1are found in the array 2, then make h=
 h+4 in the array1. Elements in the other array should move also every 4
 elements. I tried several options like next and redo, but I can not get
 what
 I want. Hope someone can help.
 Thanks in advance.
 Luba

 The script looks like:

 use strict;
 use warnings;
 my @arra1=(1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24);
 my @arra2=
 
(0,0,0,0,0,0,0,0,0,0,0,0,x,x,0,0,3,4,d,e,1,2,a,b,5,6,l,c,x,x,0,0,7,8,f,g,0,0,0,0,0,0,0,0,0,0,0,0,11,12,n,o,13,14,p,q,0,0,0,0,0,0,0,0,15,16,r,s,21,22,aa,bb,19,20,cc,dd,17,18,ee,ff,23,24,gg,hh,21,22,jj,kk,9,10,m,i); 





 my $k=0;


 for ($h=0; $h=$#arra1; $h= $h+4) {


 OUTER: if ($arra2[$k]== $arra1[$h] $arra2[$k+1]== $arra1[$h+1] ||
 $arra2[$k]== $arra1[$h+1] $arra2[$k+1]== $arra1[$h]) {
   print  $arra2[$k] and $arra2[$k+1] give $arra2[$k+2] and
 $arra2[$k+3]\n;
 $k=0;


 INNER: if ($arra2[$k]== $arra1[$h+2] $arra2[$k+1]== $arra1[$h+3] ||
 $arra2[$k]== $arra1[$h+3] $arra2[$k+1]== $arra1[$h+2]){
   print  $arra2[$k] and $arra2[$k+1] give $arra2[$k+2] and
 $arra2[$k+3]\n;
  $k=0;
   }

 }  elsif($k=$#arra2) {
   $k=$k+4;
   $h = $h-4;
  }
 }

Hello Luba

My best guess is that you're looking for the program below, is that right? I
think it's a misconception to be stepping through the first array in fours, as
it seems to be a list of number pairs, but you don't say enough about the
problem for me to be sure so I've left it as it is. If I'm right, then the loop
can be reduced to just


for (my $h = 0; $h = $#arra1; $h = $h + 2) {

  my @h = @arra1[$h,$h+1];

  for (my $k = 0; $k = $#arra2; $k = $k + 4) {

my @k = @arra2[$k .. $k+3];

if ($k[0] eq $h[0] and $k[1] eq $h[1]
or $k[0] eq $h[1] and $k[1] eq $h[0]) {
  printf  %s and %s give %s and %s\n, @k;
}
  }
}

which gives identical output with the data you give.

I hope this helps.

Rob



use strict;
use warnings;

my @arra1 = 1 .. 24;
my @arra2 = qw(
   0  0  0  0
   0  0  0  0
   0  0  0  0
   x  x  0  0
   3  4  d  e
   1  2  a  b
   5  6  l  c
   x  x  0  0
   7  8  f  g
   0  0  0  0
   0  0  0  0
   0  0  0  0
  11 12  n  o
  13 14  p  q
   0  0  0  0
   0  0  0  0
  15 16  r  s
  21 22 aa bb
  19 20 cc dd
  17 18 ee ff
  23 24 gg hh
  21 22 jj kk
   9 10  m  i
);


for (my $h = 0; $h = $#arra1; $h = $h + 4) {

  my @h = @arra1[$h .. $h+3];

  for (my $k = 0; $k = $#arra2; $k = $k + 4) {

my @k = @arra2[$k .. $k+3];

if ($k[0] eq $h[0] and $k[1] eq $h[1] or $k[0] eq $h[1] and $k[1] eq $h[0]) 
{
  printf  %s and %s give %s and %s\n, @k;
}
  }

  for (my $k = 0; $k = $#arra2; $k = $k + 4) {

my @k = @arra2[$k .. $k+3];

if ($k[0] eq $h[2] and $k[1] eq $h[3] or $k[0] eq $h[3] and $k[1] eq $h[2]) 
{
  printf  %s and %s give %s and %s\n, @k;
}
  }
}

**OUTPUT**

 1 and 2 give a and b
 3 and 4 give d and e
 5 and 6 give l and c
 7 and 8 give f and g
 9 and 10 give m and i
 11 and 12 give n and o
 13 and 14 give p and q
 15 and 16 give r and s
 17 and 18 give ee and ff
 19 and 20 give cc and dd
 21 and 22 give aa and bb
 21 and 22 give jj and kk
 23 and 24 give gg and hh


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