array problem

2010-11-15 Thread shawn wilson
so, i'm thinking i'm not understanding references here again, but here's
what i have.

i fill in my array here:
my $worksheetin = $workbookin-worksheet(0);

my ( $row_min, $row_max ) = $worksheetin-row_range();
my ( $col_min, $col_max ) = $worksheetin-col_range();

for my $row ( $row_min .. $row_max ) {
   for my $col ( $col_min .. $col_max ) {

  my $cell = $worksheetin-get_cell( $row, $col );
  next unless $cell;

  $xldata[ $row ][ $col ] = $cell-unformatted() ;
   }
}

and, i save it here (all works fine at this point):

my $worksheetout = $workbookout-add_worksheet( 'Data' );
$worksheetout-write_col( 0, 0, \...@xldata );

but, then i go and try to do an query with data in an element of the array,
and it fails. well, the array appears empty:

while ($year = $yearnow) {
   my $count = 0;
   my $worksheetout = $workbookout-add_worksheet( '$year' );

   for my $row ( 0 .. $#xldata ) {
  print @{ $xldata[ $row ] }\n;
  print MMSI: $xldata[ $row ][ 13 ]\t YEAR: $year\n;
  $sth-execute( $xldata[ $row ][ 13 ], $year );

  while (my $sqldata = $sth-fetchrow_arrayref) {
 $worksheetout-write_row( $count++, 0, \...@{ $sqldata } );

  }
   }
   $year++;
}


Re: array problem

2010-11-15 Thread shawn wilson
too much freaking data. i increased my scroll buffer and found that i do get
data, just not the last 1k lines err

On Mon, Nov 15, 2010 at 12:33 PM, shawn wilson ag4ve...@gmail.com wrote:

 so, i'm thinking i'm not understanding references here again, but here's
 what i have.

 i fill in my array here:
 my $worksheetin = $workbookin-worksheet(0);

 my ( $row_min, $row_max ) = $worksheetin-row_range();
 my ( $col_min, $col_max ) = $worksheetin-col_range();

 for my $row ( $row_min .. $row_max ) {
for my $col ( $col_min .. $col_max ) {

   my $cell = $worksheetin-get_cell( $row, $col );
   next unless $cell;

   $xldata[ $row ][ $col ] = $cell-unformatted() ;
}
 }

 and, i save it here (all works fine at this point):

 my $worksheetout = $workbookout-add_worksheet( 'Data' );
 $worksheetout-write_col( 0, 0, \...@xldata );

 but, then i go and try to do an query with data in an element of the array,
 and it fails. well, the array appears empty:

 while ($year = $yearnow) {
my $count = 0;
my $worksheetout = $workbookout-add_worksheet( '$year' );

for my $row ( 0 .. $#xldata ) {
   print @{ $xldata[ $row ] }\n;
   print MMSI: $xldata[ $row ][ 13 ]\t YEAR: $year\n;
   $sth-execute( $xldata[ $row ][ 13 ], $year );

   while (my $sqldata = $sth-fetchrow_arrayref) {
  $worksheetout-write_row( $count++, 0, \...@{ $sqldata } );

   }
}
$year++;
 }





Re: array problem

2010-11-15 Thread Uri Guttman
 sw == shawn wilson ag4ve...@gmail.com writes:

  swmy $worksheetout = $workbookout-add_worksheet( '$year' );

why are you quoting $year? that doesn't do what you think it does. in
fact it is a bug. you aren't checking if you get results out of that
call which is another problem.

uri

-- 
Uri Guttman  --  u...@stemsystems.com    http://www.sysarch.com --
-  Perl Code Review , Architecture, Development, Training, Support --
-  Gourmet Hot Cocoa Mix    http://bestfriendscocoa.com -

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: array problem

2010-11-15 Thread shawn wilson
On Mon, Nov 15, 2010 at 1:54 PM, Uri Guttman u...@stemsystems.com wrote:

  sw == shawn wilson ag4ve...@gmail.com writes:

  swmy $worksheetout = $workbookout-add_worksheet( '$year' );

 why are you quoting $year? that doesn't do what you think it does. in
 fact it is a bug. you aren't checking if you get results out of that
 call which is another problem.


yeah, i noticed that when Spreadsheet::WriteExcel came back and said it
couldn't  recreate the same worksheet :)

though, even posting this is sorta annoying to me since the solution was
right in front of me and had just scrolled off the screen - i didn't even
think to open up the doc to see what it had since i was just seeing errors
:(

it's all working fine now. i'm pretty much just playing around with slices
of arrays now to get only what i want:
while (my $sqldata = $sth-fetchrow_arrayref([ 1 .. -1 ]) ) {
doesn't work. nor does this:
$worksheetout-write_row( $count++, 0, \...@{ $sqldata }[1 .. $#{ $sqldata } ]
);

i'm sure there's a learnable moment in here, but i'm about to just forget
about it, label my first row as 'sql uid' and let them just hide it and call
it a day.




uri

 --
 Uri Guttman  --  u...@stemsystems.com    http://www.sysarch.com--
 -  Perl Code Review , Architecture, Development, Training, Support
 --
 -  Gourmet Hot Cocoa Mix    http://bestfriendscocoa.com-



Re: Array problem

2008-07-02 Thread Beyza
Thanks for the answers.

I have tried to use quotemeta but it did not work as expected, DBI's
quote function was exactly what I want.

Thanks again,

On Jul 1, 6:35 pm, [EMAIL PROTECTED] (Amit Saxena) wrote:
 use

 $*dbh*-*quote*($str)

 On Tue, Jul 1, 2008 at 4:59 AM, Gunnar Hjalmarsson [EMAIL PROTECTED]
 wrote:

  Beyza wrote:

  I have an array which has strings like;

  John's House
  Bla bla;
  etc,

  When I use them in an SQL query, perl gives an error. So, I need to
  put escape character for every special character. Is there any quick
  way to do it?

     perldoc -f quotemeta

  --
  Gunnar Hjalmarsson
  Email:http://www.gunnar.cc/cgi-bin/contact.pl

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


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




Re: Array problem

2008-07-01 Thread Amit Saxena
use

$*dbh*-*quote*($str)

On Tue, Jul 1, 2008 at 4:59 AM, Gunnar Hjalmarsson [EMAIL PROTECTED]
wrote:

 Beyza wrote:

 I have an array which has strings like;

 John's House
 Bla bla;
 etc,

 When I use them in an SQL query, perl gives an error. So, I need to
 put escape character for every special character. Is there any quick
 way to do it?


perldoc -f quotemeta

 --
 Gunnar Hjalmarsson
 Email: http://www.gunnar.cc/cgi-bin/contact.pl


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





Array problem

2008-06-30 Thread Beyza
Hi,

I would like to know how to insert escape character in front of
special characters in an array.

I have an array which has strings like;

John's House
Bla bla;
etc,

When I use them in an SQL query, perl gives an error. So, I need to
put escape character for every special character. Is there any quick
way to do it?

Thanks from now on,


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




Re: Array problem

2008-06-30 Thread Aruna Goke

Beyza wrote:

Hi,

I would like to know how to insert escape character in front of
special characters in an array.

I have an array which has strings like;

John's House
Bla bla;
etc,

When I use them in an SQL query, perl gives an error. So, I need to
put escape character for every special character. Is there any quick
way to do it?

Thanks from now on,



consider using placeholder in your query.

goksie

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




Re: Array problem

2008-06-30 Thread Rob Dixon
Beyza wrote:
 Hi,
 
 I would like to know how to insert escape character in front of
 special characters in an array.
 
 I have an array which has strings like;
 
 John's House
 Bla bla;
 etc,
 
 When I use them in an SQL query, perl gives an error. So, I need to
 put escape character for every special character. Is there any quick
 way to do it?

Show us the code you are using and what error you are getting. There are many
possible solutions to this depending on exactly what you are trying to achieve.

Rob

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




Re: Array problem

2008-06-30 Thread Gunnar Hjalmarsson

Beyza wrote:

I have an array which has strings like;

John's House
Bla bla;
etc,

When I use them in an SQL query, perl gives an error. So, I need to
put escape character for every special character. Is there any quick
way to do it?


perldoc -f quotemeta

--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl

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




Re: Array problem

2006-01-23 Thread Ditlev, Unix Consulting
Is this what you wan't ?

 open INPUT,$ARGV[0];
 while ($line=INPUT){
push (@array,$line);
 }

foreach $i(@array){
print $i;
   }

Andrej Kastrin [EMAIL PROTECTED] skrev i en meddelelse 
news:[EMAIL PROTECTED]
I wrote simple script, which have to concatenate multiple lines into array 
and then print each element of tihis array:

 open INPUT,$ARGV[0];
 while ($line=INPUT){
push (@array,$line);
foreach $i(@array){
print $i;
   }
 }

 Input is e.g.
 line 1
 line 2

 I don't know where is the problem, Please, help!

 Cheers, Andrej 



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




Array problem

2006-01-22 Thread Andrej Kastrin
I wrote simple script, which have to concatenate multiple lines into 
array and then print each element of tihis array:


open INPUT,$ARGV[0];
while ($line=INPUT){
   push (@array,$line);
   foreach $i(@array){
   print $i;
  }
}

Input is e.g.
line 1
line 2

I don't know where is the problem, Please, help!

Cheers, Andrej

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




RE: Array problem

2006-01-22 Thread Thomas Bätzler
Andrej Kastrin [EMAIL PROTECTED] asked:
 I wrote simple script, which have to concatenate multiple 
 lines into array and then print each element of tihis array:
 
 open INPUT,$ARGV[0];
 while ($line=INPUT){

I would instead suggest you use the  special filehandle.
This automagically opens any file whose name is passed as
a command line parameter. If @ARGV is empty, it uses STDIN
instead. Very hand indeed!

I also recommend you use strict and warnings and declare
all of your variables.

#!/usr/bin/perl -w
use strict;

my @array;

while( my $line =  ){
  push (@array,$line);
}

If you don't intend to process the lines while you're reading
them you could go ahead and slurp all of them in one go:

my @array = ;

This loop should only run after you're done reading the file.
Otherwise it'll print the parts that have been read already
again and again.

 foreach $i(@array){
 print $i;
}

HTH,
Thomas

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




Re: Array problem

2006-01-22 Thread Mazhar
Mr Andrej,

I think the following code will work for u,
open INPUT,$ARGV[0];
while (INPUT){
  @array=$_;
}

foreach $i(@array){
   print $i;
 }


Regards
Mazhar


On 1/23/06, Thomas Bätzler [EMAIL PROTECTED] wrote:

 Andrej Kastrin [EMAIL PROTECTED] asked:
  I wrote simple script, which have to concatenate multiple
  lines into array and then print each element of tihis array:
 
  open INPUT,$ARGV[0];
  while ($line=INPUT){

 I would instead suggest you use the  special filehandle.
 This automagically opens any file whose name is passed as
 a command line parameter. If @ARGV is empty, it uses STDIN
 instead. Very hand indeed!

 I also recommend you use strict and warnings and declare
 all of your variables.

 #!/usr/bin/perl -w
 use strict;

 my @array;

 while( my $line =  ){
   push (@array,$line);
 }

 If you don't intend to process the lines while you're reading
 them you could go ahead and slurp all of them in one go:

 my @array = ;

 This loop should only run after you're done reading the file.
 Otherwise it'll print the parts that have been read already
 again and again.

  foreach $i(@array){
  print $i;
 }

 HTH,
 Thomas

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





Re: Array problem

2006-01-22 Thread John Doe
Andrej Kastrin am Montag, 23. Januar 2006 07.55:
 I wrote simple script, which have to concatenate multiple lines into
 array and then print each element of tihis array:

 I don't know where is the problem, Please, help!

The basic problem is that you try to print the result within the (while) loop 
that is building the result array. What your script does:

It shows the content of the array after every step of building it.

Besides that, there are other improvements - see inline:

# Alway start with:

use strict; # forces to declare variables
use warnings; # helpful for finding (potential) errors

 open INPUT,$ARGV[0];

# missing error checking:
open (INPUT, '', $ARGV[0]) or die Can't open file: $!;

my @array;

 while ($line=INPUT){

while (my $line=INPUT){

 push (@array,$line);

 foreach $i(@array){
foreach my $i(@array){
 print $i;
}

The above foreach loop should be outside of the while loop.

When you have to declare the variables (because of 'use strict'), you have to 
think about the scope of it (@array in this case). @array is defined in the 
same scope as the array building while loop. After the while, it is built, 
and you can use it. Basically, you have the following work:

- declare array
- fill array
- use array

 }

 Input is e.g.
 line 1
 line 2


hth,
joe

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




Re: Two Dimensional Array Problem

2005-06-05 Thread Wiggins d'Anconia
Always group reply so others can help and be helped, and to avoid
getting accidentally ignored.

Because it's up-side down.
Why is that?
It makes replies harder to read.
Why not?
Please don't top-post. - Sherm Pendley, Mac OS X list

Aaron Huber wrote:
 
 On 6/3/05, Wiggins d'Anconia [EMAIL PROTECTED] wrote:
 
[EMAIL PROTECTED] wrote:

I am trying to send the output of a mysql query to a two dimensional array.

This is what I've tried using push.

while (@results = $sth-fetchrow_array ())
{
$x = $results[0];
$y = $results[1];
push (@data,[$x],[$y]);
}

However, I don't get back a two dimensional array, I get back a single
array of @data.

Thanks. -Aaron


Not sure if this is an exercise in how to build an AoA or if you are
really just trying to accomplish the goal and move on. In the latter
case, you can have DBI do it for you using 'fetchall_arrayref',

my $array_of_arrays = $sth-fetchall_arrayref;

use Data::Dumper;
print Dumper($array_of_arrays);

You should probably read the docs for the method, assuming you care
about data integrity and error handling,

http://search.cpan.org/~timb/DBI-1.48/DBI.pm#fetchall_arrayref

HTH,

http://danconia.org

 
 
 
 Dear Wiggins,

 Thank you for taking the time to reply to my post.  Actually, what I
 am trying to do here is build an array that can be used with GD::Graph
 to show the graphical representation of a MySQL query.  This module
 only takes in an AoA like:

 @data = ([1,2,3,4],[10,20,30,40]); # @arr[$x vals], [$y vals]


Currently this is an array (specifically an array of array references,
which we call an array of arrays), but actually the subroutine call
below is taking an array reference.

 and outputs a graph using this:

 my $image = $plot-plot([EMAIL PROTECTED]);


The notation above, C[EMAIL PROTECTED], means you are passing an array 
reference.
A '\' before a sigil causes a return of a reference to the structure.

perldoc perlreftut
perldoc perlref

 When I use this code with the above mentioned array hard coded in it
 works like a charm, but none of the suggestions on the message board
 gave me this type of array that I needed.  Is the above @data var an
 AoA or is it something else?


It is an array of arrays. If the other postings did not work then you
need to show us more of the code, specifically your select statement. We
are working blind at this point, we were assuming you were returning the
data in the correct way. Did you try the 'fetchall_arrayref' call?
Assuming your select is correct, and you really are getting one row of
data to plot at a time then it should be all you need. If it does not
work, then you probably need to manipulate your select differently, but
we can't tell that.

Use Data::Dumper to explore what structure you have. Try first printing
the above hard coded structure so you know what to look for. Then try
multiple things until you get it the same.

perldoc Data::Dumper

-- Sample --
use Data::Dumper;
my @aoa = ([1,2,3,4],[10,20,30,40]);

print Dumper([EMAIL PROTECTED]);

 Thanks,
 Aaron Huber


HTH, good luck,

http://danconia.org

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




Two Dimensional Array Problem

2005-06-03 Thread ahuber
I am trying to send the output of a mysql query to a two dimensional array.

This is what I've tried using push.

while (@results = $sth-fetchrow_array ())
{
$x = $results[0];
$y = $results[1];
push (@data,[$x],[$y]);
}

However, I don't get back a two dimensional array, I get back a single
array of @data.

Thanks. -Aaron

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




RE: Two Dimensional Array Problem

2005-06-03 Thread brian . barto
Looks like you're pushing a list on to another list. In effect, appending
one to the other. @data would be the first list. The second list would be
'$x, $y'. Variables in a comma delimited fashion is the same as a list or an
array.

I usually deal with multidimensional arrays this way:

$i = 0;
while (@results = $sth-fetchrow_array ())
{
$x = $results[0];
$y = $results[1];
@points = ($x, $y);
$data[$i] = [EMAIL PROTECTED];
$i++;
}

I think that will work... maybe :)

-Original Message-
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]
Sent: Friday, June 03, 2005 2:42 PM
To: beginners@perl.org
Subject: Two Dimensional Array Problem


I am trying to send the output of a mysql query to a two dimensional array.

This is what I've tried using push.

while (@results = $sth-fetchrow_array ())
{
$x = $results[0];
$y = $results[1];
push (@data,[$x],[$y]);
}

However, I don't get back a two dimensional array, I get back a single
array of @data.

Thanks. -Aaron

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




RE: Two Dimensional Array Problem

2005-06-03 Thread Wagner, David --- Senior Programmer Analyst --- WGO
[EMAIL PROTECTED] wrote:
 I am trying to send the output of a mysql query to a two dimensional
 array. 
 
 This is what I've tried using push.
 
 while (@results = $sth-fetchrow_array ())
 {
 $x = $results[0];
 $y = $results[1];
 push (@data,[$x],[$y]);

push( @data, [ $x , $y ] );
Access would be for first 0,0, 0,1, 1,0,1,1, etc

Wags ;)
 }
 
 However, I don't get back a two dimensional array, I get back a single
 array of @data.
 
 Thanks. -Aaron



***
This message contains information that is confidential
and proprietary to FedEx Freight or its affiliates.
It is intended only for the recipient named and for
the express purpose(s) described therein.
Any other use is prohibited.
***


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




Re: Two Dimensional Array Problem

2005-06-03 Thread Wiggins d'Anconia
[EMAIL PROTECTED] wrote:
 I am trying to send the output of a mysql query to a two dimensional array.
 
 This is what I've tried using push.
 
 while (@results = $sth-fetchrow_array ())
 {
 $x = $results[0];
 $y = $results[1];
 push (@data,[$x],[$y]);
 }
 
 However, I don't get back a two dimensional array, I get back a single
 array of @data.
 
 Thanks. -Aaron
 

Not sure if this is an exercise in how to build an AoA or if you are
really just trying to accomplish the goal and move on. In the latter
case, you can have DBI do it for you using 'fetchall_arrayref',

my $array_of_arrays = $sth-fetchall_arrayref;

use Data::Dumper;
print Dumper($array_of_arrays);

You should probably read the docs for the method, assuming you care
about data integrity and error handling,

http://search.cpan.org/~timb/DBI-1.48/DBI.pm#fetchall_arrayref

HTH,

http://danconia.org

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




RE: Two Dimensional Array Problem

2005-06-03 Thread brian . barto
That's much better than my method. Didn't know you could push blocks of data
like that.

Cool :)

-Original Message-
From: Wagner, David --- Senior Programmer Analyst --- WGO
[mailto:[EMAIL PROTECTED]
Sent: Friday, June 03, 2005 3:01 PM
To: [EMAIL PROTECTED]; beginners@perl.org
Subject: RE: Two Dimensional Array Problem


[EMAIL PROTECTED] wrote:
 I am trying to send the output of a mysql query to a two dimensional
 array. 
 
 This is what I've tried using push.
 
 while (@results = $sth-fetchrow_array ())
 {
 $x = $results[0];
 $y = $results[1];
 push (@data,[$x],[$y]);

push( @data, [ $x , $y ] );
Access would be for first 0,0, 0,1, 1,0,1,1, etc

Wags ;)
 }
 
 However, I don't get back a two dimensional array, I get back a single
 array of @data.
 
 Thanks. -Aaron



***
This message contains information that is confidential
and proprietary to FedEx Freight or its affiliates.
It is intended only for the recipient named and for
the express purpose(s) described therein.
Any other use is prohibited.
***


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




RE: Two Dimensional Array Problem

2005-06-03 Thread Wagner, David --- Senior Programmer Analyst --- WGO
[EMAIL PROTECTED] wrote:
 That's much better than my method. Didn't know you could push blocks
 of data like that.
 
 Cool :)

Easiest way to see is use Data::Dumper and then print Dumper ( [EMAIL 
PROTECTED] ).
Then you can see the setup.  Especially nice when you tell the Dumper to sort 
in order and you are using say a hash which has array.

Wags ;)
 
 -Original Message-
 From: Wagner, David --- Senior Programmer Analyst --- WGO
 [mailto:[EMAIL PROTECTED]
 Sent: Friday, June 03, 2005 3:01 PM
 To: [EMAIL PROTECTED]; beginners@perl.org
 Subject: RE: Two Dimensional Array Problem
 
 
 [EMAIL PROTECTED] wrote:
 I am trying to send the output of a mysql query to a two dimensional
 array. 
 
 This is what I've tried using push.
 
 while (@results = $sth-fetchrow_array ())
 {
 $x = $results[0];
 $y = $results[1];
 push (@data,[$x],[$y]);
 
   push( @data, [ $x , $y ] );
   Access would be for first 0,0, 0,1, 1,0,1,1, etc
 
 Wags ;)
 }
 
 However, I don't get back a two dimensional array, I get back a
 single array of @data. 
 
 Thanks. -Aaron
 
 
 
 ***
 This message contains information that is confidential
 and proprietary to FedEx Freight or its affiliates.
 It is intended only for the recipient named and for
 the express purpose(s) described therein.
 Any other use is prohibited.
 ***
 
 
 --
 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




Re: Two Dimensional Array Problem

2005-06-03 Thread Chris Charley

[snip]

Hi Brian,


I usually deal with multidimensional arrays this way:

$i = 0;
while (@results = $sth-fetchrow_array ())
{
   $x = $results[0];
   $y = $results[1];
   @points = ($x, $y);
   $data[$i] = [EMAIL PROTECTED];
   $i++;
}


Just a note about a possible problem with the statement:
$data[$i] = [EMAIL PROTECTED];

Everytime through this loop, the reference to @points, ([EMAIL PROTECTED]), is 
assigned to @data. But this is the same address. The result is that all the 
array refs assigned to @data are the same. So, the *last* assignment to 
@points, (x,y), will be the values for every element of @data.


A correct way to say it in your example would be:
$data[$i] = [EMAIL PROTECTED];

Another would be to declare my @points in the loop, so that you have a fresh 
ref every time through the loop. Then you could say:

$data[$i] = [EMAIL PROTECTED];

Chris 




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




Re: Concatenating line into array problem

2004-06-11 Thread John W. Krahn
Edward Wijaya wrote:
 
 Hi groups,

Hello,

 I have a file which contain many many of this line (Fasta Format):
 
  YNL331C
 CAATATGCGAGGGACCTACATGTTGA
 CATGACAATGAATTCTATTGAA
 
  YKL071W
 ATAATTATTCCTGTTTCTTTAACCTG
 GTGTACAAACACTTAAGC
 
 What I would like to do is to concatenate the line below 
 into one single string.
 Such as the output would be:
 
 CAATATGCGAGGGACCTACATGTTGAGCATGACAATGAATTCTATTGA
 ATAATTATTCCTGTTTCTTTAACCTGGTGTACAAACACTTAAGC
 
 The current code I created now seem to work but doesn't
 gie the result I want. Since it concatenates all into 1 single line.
 I thought there must be a very simple way to do this.
 But I can't seem to figure out how to achieve that.
 
 #---My Code --
 while () {
  if (/^/) {
  next;
  }
  chomp;
  $line .= $_;
 }
 push (@crseq, $line);
 print join(\n, @crseq), \n;

This should do what you want:

$/ = '';
while (  ) {
next unless s/\s+\S.*//;
chomp;   
tr/\n//d;
print $_\n;
}



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




Re: Concatenating line into array problem

2004-06-11 Thread John W. Krahn
John W. Krahn wrote:
 
 This should do what you want:
 
 $/ = '';
 while (  ) {
 next unless s/\s+\S.*//;
 chomp;
 tr/\n//d;
 print $_\n;
 }

After seeing your data file change that to:

$/ = '';
while (  ) {
next unless s/\S+.*\n//;
chomp;
tr/\n//d;
print $_\n;
}



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




Re: Concatenating line into array problem

2004-06-11 Thread Zeus Odin
This works:

---BEGIN CODE---
#!/usr/bin/perl
use warnings;
use strict;

$/ = '';
while (DATA) {
  s/(.*?\n.*?)\n/$1/s;
  print;
}

__DATA__
 YNL331C
CAATATGCGAGGGACCTACATGTTGA
CATGACAATGAATTCTATTGAA

 YKL071W
ATAATTATTCCTGTTTCTTTAACCTG
GTGTACAAACACTTAAGC
---END CODE---

Please check your data for the first line:

my line:   CAATATGCGAGGGACCTACATGTTGACATGACAATGAATTCTATTGAA
your line: CAATATGCGAGGGACCTACATGTTGAGCATGACAATGAATTCTATTGA
 ^
An extra G has been inserted into your output would be line denoted by the
^ above and an A deleted from the end of the line. I think my line is
correct but will not swear to it.
:-)

-ZO



Edward Wijaya [EMAIL PROTECTED] wrote in message
news:[EMAIL PROTECTED]
 Hi groups,

 I have a file which contain many many of this line (Fasta Format):

  YNL331C
 CAATATGCGAGGGACCTACATGTTGA
 CATGACAATGAATTCTATTGAA

  YKL071W
 ATAATTATTCCTGTTTCTTTAACCTG
 GTGTACAAACACTTAAGC

 What I would like to do is to concatenate the line below 
 into one single string.
 Such as the output would be:

 CAATATGCGAGGGACCTACATGTTGAGCATGACAATGAATTCTATTGA
 ATAATTATTCCTGTTTCTTTAACCTGGTGTACAAACACTTAAGC



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




Concatenating line into array problem

2004-06-10 Thread Edward Wijaya
Hi groups,
I have a file which contain many many of this line (Fasta Format):
YNL331C	
CAATATGCGAGGGACCTACATGTTGA
CATGACAATGAATTCTATTGAA
YKL071W	
ATAATTATTCCTGTTTCTTTAACCTG
GTGTACAAACACTTAAGC
What I would like to do is to concatenate the line below 
into one single string.
Such as the output would be:
CAATATGCGAGGGACCTACATGTTGAGCATGACAATGAATTCTATTGA
ATAATTATTCCTGTTTCTTTAACCTGGTGTACAAACACTTAAGC
The current code I created now seem to work but doesn't
gie the result I want. Since it concatenates all into 1 single line.
I thought there must be a very simple way to do this.
But I can't seem to figure out how to achieve that.
Your advice is very much appreciated.
Thanks so much for your time.
--
Regards,
Edward WIJAYA
SINGAPORE
#---My Code --
while () {
if (/^/) {
next;
}
chomp;
$line .= $_;
}
push (@crseq, $line);
print join(\n, @crseq), \n;
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response



RE: Concatenating line into array problem

2004-06-10 Thread Tim Johnson

This might be closer to what you want.  Just push the line onto the
array every time you come to the '' character.  You'll get one empty
line at the beginning, that's why I put the shift line in.



while () {
 if (/^/) {
 push (@crseq, $line);
 next;
 }
 chomp;
 $line .= $_;
}
shift @crseq;
print join(\n, @crseq), \n; 



-Original Message-
From: Edward Wijaya [mailto:[EMAIL PROTECTED] 
Sent: Thursday, June 10, 2004 9:09 PM
To: [EMAIL PROTECTED]
Subject: Concatenating line into array problem

snip

What I would like to do is to concatenate the line below  into one
single string.
Such as the output would be:

CAATATGCGAGGGACCTACATGTTGAGCATGACAATGAATTCTATTGA
ATAATTATTCCTGTTTCTTTAACCTGGTGTACAAACACTTAAGC

snip

#---My Code --
while () {
 if (/^/) {
 next;
 }
 chomp;
 $line .= $_;
}
push (@crseq, $line);
print join(\n, @crseq), \n;


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




Re: Concatenating line into array problem

2004-06-10 Thread Edward Wijaya
On Thu, 10 Jun 2004 21:19:17 -0700, Tim Johnson [EMAIL PROTECTED] 
wrote:

while () {
 if (/^/) {
 push (@crseq, $line);
 next;
 }
 chomp;
 $line .= $_;
}
shift @crseq;
print join(\n, @crseq), \n;

Thanks so much for your reply Tim.
But the outoput it gives is
CAATATGCGAGGGACCTACATGTTGACATGACAATGAATTCTATTGAA
instead of:
CAATATGCGAGGGACCTACATGTTGACATGACAATGAATTCTATTGAA
and
ATAATTATTCCTGTTTCTTTAACCTGGTGTACAAACACTTAAGC
So it missed out second '' part of the fasta file.
Any clue?
Thanks again before hand.
Regards
Edward WIJAYA
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response



RE: Concatenating line into array problem

2004-06-10 Thread Charles K. Clarkson
From: Edward Wijaya mailto:[EMAIL PROTECTED] wrote:

: #---My Code --
: while () {
:  if (/^/) {
:  next;
:  }
:  chomp;
:  $line .= $_;
: }
: push (@crseq, $line);
: print join(\n, @crseq), \n;


How about:

my @crseq;
while (  ) {
next unless/^[ACGT]/;
chomp;
push @crseq, $_ . scalar ;
}
print @crseq;


HTH,

Charles K. Clarkson
-- 
Mobile Homes Specialist
254 968-8328


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




Re: Concatenating line into array problem

2004-06-10 Thread Edward Wijaya
How about:
my @crseq;
while (  ) {
next unless/^[ACGT]/;
chomp;
push @crseq, $_ . scalar ;
}
print @crseq;
Hi Charles,
Thanks for your reply.
Your code works for my example in email, but not the file
with more lines, (please see attached file).
So sorry if I didn't give precise example.
Regards,
Edward WIJAYA


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


RE: Concatenating line into array problem

2004-06-10 Thread Charles K. Clarkson
From: Edward Wijaya mailto:[EMAIL PROTECTED] wrote:

:: How about:
:: 
:: my @crseq;
:: while (  ) {
:: next unless/^[ACGT]/;
:: chomp;
:: push @crseq, $_ . scalar ;
:: }
:: print @crseq;
:: 
: 
: Hi Charles,
: 
: Thanks for your reply.
: 
: Your code works for my example in email, but not the file
: with more lines, (please see attached file).
: 
: So sorry if I didn't give precise example.

Well, be that way!

my @crseq;
while (  ) {
# start new line
push @crseq, '' if /^/;

# kill the line ending
chomp;

# concatenate current line
# to the last array item
$crseq[-1] .= $_
}
print $_\n foreach @crseq;

HTH,

Charles K. Clarkson
-- 
Mobile Homes Specialist
254 968-8328


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




Re: Array problem, I think

2002-11-16 Thread badchoice

 0 @F1@ FAM
 1 HUSB @I13@
 1 WIFE @I14@
 1 CHIL @I8@
 0 @F2@ FAM
 1 HUSB @I10@
 1 WIFE @I8@
 1 CHIL @I11@
 1 CHIL @I12@
 etc.

$/ = undef;
for (split /\n0/, ) {
($key) = /\@(..)/;
$hash{$key} = [ /\@(\w+)\@$/gm ];
}


 $individuals{F1}[0] = I13;
 $individuals{F1}[1] = I14;
 $individuals{F1)[2] = I8;
 $individuals{F2)[0] = I10;
 $individuals{F2)[1] = I8;
 $individuals{F2)[2] = I11;
 $individuals{F2)[3] = I12;


untested.


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Re: Array problem, I think

2002-11-16 Thread Paul Johnson
On Mon, Nov 11, 2002 at 06:17:58PM -0500, Cacialli, Doug wrote:

 I've got oodles of data.  It looks like this:
 
 0 @F1@ FAM
 1 HUSB @I13@
 1 WIFE @I14@
 1 CHIL @I8@
 0 @F2@ FAM
 1 HUSB @I10@
 1 WIFE @I8@
 1 CHIL @I11@
 1 CHIL @I12@
 etc.

[ snip problem ]

 I'm familiar with substr, split, m//, s///, etc.; I'm just not sure how to
 programmatically create the data structure.  Any help or suggestions to
 point me in a direction would be appreciated.  Thank you.

I'd suggest heading off to CPAN and picking up Gedcom.pm.

http://search.cpan.org/author/PJCJ/Gedcom-1.11/

But then, I'm biased ;-)

-- 
Paul Johnson - [EMAIL PROTECTED]
http://www.pjcj.net

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Array problem, I think

2002-11-11 Thread Cacialli, Doug
Y'all,

I'm new to programming in perl, and relatively new to programming at all, so
I apologize if this is a little hard to follow.

I've got oodles of data.  It looks like this:

0 @F1@ FAM
1 HUSB @I13@
1 WIFE @I14@
1 CHIL @I8@
0 @F2@ FAM
1 HUSB @I10@
1 WIFE @I8@
1 CHIL @I11@
1 CHIL @I12@
etc.

The first numeric portion (either 0 or 1) is irrelevant, the second portion
either a family number (@F1@, @F2@, etc.) OR relationship (HUSB, WIFE, or
CHIL), and the third portion is an ID number (@I13@, @I14@, @I8@, etc.).

What I need to do is create a series of unnamed arrays and reference them
hash elements.  In other words, I need to do the equivalent to this:

$individuals{F1}[0] = I13;
$individuals{F1}[1] = I14;
$individuals{F1)[2] = I8;
$individuals{F2)[0] = I10;
$individuals{F2)[1] = I8;
$individuals{F2)[2] = I11;
$individuals{F2)[3] = I12;

I'm familiar with substr, split, m//, s///, etc.; I'm just not sure how to
programmatically create the data structure.  Any help or suggestions to
point me in a direction would be appreciated.  Thank you.

Regards,

Doug Cacialli

---
Douglas Cacialli - Data Manager / Data Analyst
Sleep and Depression Research Laboratory
University of Rochester Medical Center
300 Crittenden Blvd. - Box PSYCH
Rochester, New York 14642
Phone: (585)273-3309  Fax: (585)506-0287
   NOTE NEW FAX NUMBER   
---

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Re: Array problem, I think

2002-11-11 Thread Cacialli, Doug
One additional thing:

The data exists in an array, where each line of raw data is a scalar string
within the array.

-Original Message-
From: Cacialli, Doug 
Sent: Monday, November 11, 2002 6:18 PM
To: '[EMAIL PROTECTED]'
Subject: Array problem, I think

Y'all,

I'm new to programming in perl, and relatively new to programming at all, so
I apologize if this is a little hard to follow.

I've got oodles of data.  It looks like this:

0 @F1@ FAM
1 HUSB @I13@
1 WIFE @I14@
1 CHIL @I8@
0 @F2@ FAM
1 HUSB @I10@
1 WIFE @I8@
1 CHIL @I11@
1 CHIL @I12@
etc.

The first numeric portion (either 0 or 1) is irrelevant, the second portion
either a family number (@F1@, @F2@, etc.) OR relationship (HUSB, WIFE, or
CHIL), and the third portion is an ID number (@I13@, @I14@, @I8@, etc.).

What I need to do is create a series of unnamed arrays and reference them
hash elements.  In other words, I need to do the equivalent to this:

$individuals{F1}[0] = I13;
$individuals{F1}[1] = I14;
$individuals{F1)[2] = I8;
$individuals{F2)[0] = I10;
$individuals{F2)[1] = I8;
$individuals{F2)[2] = I11;
$individuals{F2)[3] = I12;

I'm familiar with substr, split, m//, s///, etc.; I'm just not sure how to
programmatically create the data structure.  Any help or suggestions to
point me in a direction would be appreciated.  Thank you.

Regards,

Doug Cacialli

---
Douglas Cacialli - Data Manager / Data Analyst
Sleep and Depression Research Laboratory
University of Rochester Medical Center
300 Crittenden Blvd. - Box PSYCH
Rochester, New York 14642
Phone: (585)273-3309  Fax: (585)506-0287
   NOTE NEW FAX NUMBER   
---

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Re: Array problem, I think

2002-11-11 Thread Jason Tiller
Hi, Doug, :)

On Mon, 11 Nov 2002, Cacialli, Doug wrote:

 I'm new to programming in perl, and relatively new to programming at
 all, so I apologize if this is a little hard to follow.

Wasn't hard at all!  You described the problem very succinctly.

 I've got oodles of data.  It looks like this:

 0 @F1@ FAM
 1 HUSB @I13@
 1 WIFE @I14@
 1 CHIL @I8@
 0 @F2@ FAM
 1 HUSB @I10@
 1 WIFE @I8@
 1 CHIL @I11@
 1 CHIL @I12@

 The first numeric portion (either 0 or 1) is irrelevant, the second
 portion either a family number (@F1@, @F2@, etc.) OR relationship
 (HUSB, WIFE, or CHIL), and the third portion is an ID number (@I13@,
 @I14@, @I8@, etc.).

 What I need to do is create a series of unnamed arrays and reference
 them hash elements.  In other words, I need to do the equivalent to
 this:

 $individuals{F1}[0] = I13;
 $individuals{F1}[1] = I14;
 $individuals{F1)[2] = I8;
 $individuals{F2)[0] = I10;
 $individuals{F2)[1] = I8;
 $individuals{F2)[2] = I11;
 $individuals{F2)[3] = I12;

Is this what you *really* want to do?  I notice that you lose the
familial relationship when you simply push all the members of a
family onto an array.  Don't you care about which of the [0], [1], or
[2] is the HUSB, WIFE, or CHIL? ;)  You could easily keep that data as
well, if you wanted to.

If we do solve it the way you indicate, then you asking to treat the
value for the hash key F1 (family) as an array reference.  Then you
simply push() all of the family IDs onto the array as you find them.

Here's what I came up with to do this:

#!/usr/bin/perl

use strict;
use warnings;

my $data =
'0 @F1@ FAM
1 HUSB @I13@
1 WIFE @I14@
1 CHIL @I8@
0 @F2@ FAM
1 HUSB @I10@
1 WIFE @I8@
1 CHIL @I11@
1 CHIL @I12@
';

my @lines = split /\n/, $data;

my %individuals = ();

my $curr_fam;
foreach( @lines ) {
   s/@//g;
   my ($placeholder, $relation, $id) = split  ;

   # $id eq FAM indicates the start of a new family, with the second
   # field ($relation) holding the family ID.
   $curr_fam = $relation, next if $id eq FAM;

   # Line must be an individual.  Push the ID on to the array for the
   # current family.
   push @{ $individuals{$curr_fam} }, $id;
}

I hope that makes sense.  The last line is the only one that's really
interesting.  I do exactly what I described above - use the *value* in
%individuals associated with the key $curr_fam and treat the value as
an array reference, hence the @{ stuff that precedes it.

Here's the code to print out the hash:

foreach my $fam ( keys %individuals ) {
   foreach my $ind ( 0 .. $#{ $individuals{$fam} } ) {
  print \$individuals{$fam}[$ind] = \, $individuals{$fam}[$ind],
 \\n;
   }
}

You know, it might make more sense if you organized your structure
like this:

$individuals{F1}{HUSB} = I10;
$individuals{F1}{WIFE} = I8;
$individuals{F1}{CHILD} = (I11, I12);

That way you retain the information on the relationships between the
various family members.  Ooh, ooh, ooh, I get to say it:

I'll leave that as an exercise to the reader.

I hope that helps,

---Jason


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Re: Array problem, I think

2002-11-11 Thread Wiggins d'Anconia
This solution works well and is clean, if you are curious about some of 
the *magic* he is performing in his foreach I would suggest reading up 
on the special variable $_ for those of us experienced in perl it isn't 
as daunting to just throw a foreach (@array) in the code and know that 
it is going to work on $_ so that something like s/regex/replace/g; 
which appears to just hang in space isn't skipped, but is again working 
on that $_ that mysteriously jumped into the code.  I prefer explicitly 
giving the temp variable a name so that I know (and more importantly the 
people after me know) what the hell I was doing and to what, but to each 
his own.

http://danconia.org


Jason Tiller wrote:
Hi, Doug, :)

On Mon, 11 Nov 2002, Cacialli, Doug wrote:



I'm new to programming in perl, and relatively new to programming at
all, so I apologize if this is a little hard to follow.



Wasn't hard at all!  You described the problem very succinctly.



I've got oodles of data.  It looks like this:




0 @F1@ FAM
1 HUSB @I13@
1 WIFE @I14@
1 CHIL @I8@
0 @F2@ FAM
1 HUSB @I10@
1 WIFE @I8@
1 CHIL @I11@
1 CHIL @I12@




The first numeric portion (either 0 or 1) is irrelevant, the second
portion either a family number (@F1@, @F2@, etc.) OR relationship
(HUSB, WIFE, or CHIL), and the third portion is an ID number (@I13@,
@I14@, @I8@, etc.).




What I need to do is create a series of unnamed arrays and reference
them hash elements.  In other words, I need to do the equivalent to
this:




$individuals{F1}[0] = I13;
$individuals{F1}[1] = I14;
$individuals{F1)[2] = I8;
$individuals{F2)[0] = I10;
$individuals{F2)[1] = I8;
$individuals{F2)[2] = I11;
$individuals{F2)[3] = I12;



Is this what you *really* want to do?  I notice that you lose the
familial relationship when you simply push all the members of a
family onto an array.  Don't you care about which of the [0], [1], or
[2] is the HUSB, WIFE, or CHIL? ;)  You could easily keep that data as
well, if you wanted to.

If we do solve it the way you indicate, then you asking to treat the
value for the hash key F1 (family) as an array reference.  Then you
simply push() all of the family IDs onto the array as you find them.

Here's what I came up with to do this:

#!/usr/bin/perl

use strict;
use warnings;

my $data =
'0 @F1@ FAM
1 HUSB @I13@
1 WIFE @I14@
1 CHIL @I8@
0 @F2@ FAM
1 HUSB @I10@
1 WIFE @I8@
1 CHIL @I11@
1 CHIL @I12@
';

my @lines = split /\n/, $data;

my %individuals = ();

my $curr_fam;
foreach( @lines ) {
   s/@//g;
   my ($placeholder, $relation, $id) = split  ;

   # $id eq FAM indicates the start of a new family, with the second
   # field ($relation) holding the family ID.
   $curr_fam = $relation, next if $id eq FAM;

   # Line must be an individual.  Push the ID on to the array for the
   # current family.
   push @{ $individuals{$curr_fam} }, $id;
}

I hope that makes sense.  The last line is the only one that's really
interesting.  I do exactly what I described above - use the *value* in
%individuals associated with the key $curr_fam and treat the value as
an array reference, hence the @{ stuff that precedes it.

Here's the code to print out the hash:

foreach my $fam ( keys %individuals ) {
   foreach my $ind ( 0 .. $#{ $individuals{$fam} } ) {
  print \$individuals{$fam}[$ind] = \, $individuals{$fam}[$ind],
 \\n;
   }
}

You know, it might make more sense if you organized your structure
like this:

$individuals{F1}{HUSB} = I10;
$individuals{F1}{WIFE} = I8;
$individuals{F1}{CHILD} = (I11, I12);

That way you retain the information on the relationships between the
various family members.  Ooh, ooh, ooh, I get to say it:

I'll leave that as an exercise to the reader.

I hope that helps,

---Jason





--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Re: Array problem, I think

2002-11-11 Thread Jason Tiller
Hi, Wiggins, :)

On Mon, 11 Nov 2002, Wiggins d'Anconia wrote:

 This solution works well and is clean, if you are curious about some
 of the *magic* he is performing in his foreach I would suggest
 reading up on the special variable $_ for those of us experienced in
 perl it isn't as daunting to just throw a foreach (@array) in the
 code and know that it is going to work on $_ so that something like
 s/regex/replace/g; which appears to just hang in space isn't
 skipped, but is again working on that $_ that mysteriously jumped
 into the code.  I prefer explicitly giving the temp variable a name
 so that I know (and more importantly the people after me know) what
 the hell I was doing and to what, but to each his own.

Good call, dude.  Sorry about that, Doug!  I'm normally pretty anal
about using descriptive variable names and obvious grammar/punctuation
('m_' anyone?).  Wiggins is right - one of the frustrating things
about learning Perl is that there are so many shortcuts and seemingly
non-intuitive things (like, what does '$!' mean?) that reading the
code of an expert can be daunting, and I don't by *any* *means*
consider myself an expert.  My background and training has always been
geared towards programs that are expressive and immediately
understandable as opposed to elegant but terse.

Then again, there are some Perl idioms that are just too useful to
leave on the cutting room floor.  While these can be easily abused, I
think they have their place, too.  When used judiciously, they can
actually *clear* *out* some of the line-noise and extraneous text that
sometimes inhibits understanding in other languages.  Fine line,
though.

---Jason


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Re: Array problem, I think

2002-11-11 Thread Wiggins d'Anconia
No need to apologize.  Agreed.

http://danconia.org

Jason Tiller wrote:

Hi, Wiggins, :)

On Mon, 11 Nov 2002, Wiggins d'Anconia wrote:



This solution works well and is clean, if you are curious about some
of the *magic* he is performing in his foreach I would suggest
reading up on the special variable $_ for those of us experienced in
perl it isn't as daunting to just throw a foreach (@array) in the
code and know that it is going to work on $_ so that something like
s/regex/replace/g; which appears to just hang in space isn't
skipped, but is again working on that $_ that mysteriously jumped
into the code.  I prefer explicitly giving the temp variable a name
so that I know (and more importantly the people after me know) what
the hell I was doing and to what, but to each his own.



Good call, dude.  Sorry about that, Doug!  I'm normally pretty anal
about using descriptive variable names and obvious grammar/punctuation
('m_' anyone?).  Wiggins is right - one of the frustrating things
about learning Perl is that there are so many shortcuts and seemingly
non-intuitive things (like, what does '$!' mean?) that reading the
code of an expert can be daunting, and I don't by *any* *means*
consider myself an expert.  My background and training has always been
geared towards programs that are expressive and immediately
understandable as opposed to elegant but terse.

Then again, there are some Perl idioms that are just too useful to
leave on the cutting room floor.  While these can be easily abused, I
think they have their place, too.  When used judiciously, they can
actually *clear* *out* some of the line-noise and extraneous text that
sometimes inhibits understanding in other languages.  Fine line,
though.

---Jason





--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Re: Array Problem

2002-01-21 Thread maureen

Thanks so much for your help on this. I tried this suggestion, but
unfortunately, the array @indata does not seem to contain the usernames
from the file pwdata.txt.

I've been looking at this for hours. I hope someone can help me figure
out what I am missing here. The objectives for this code and the revised
code follow:

Code Objectives:
1)Accept username and password from an HTML page
2)Open a text file and store the username and passwords listed there in
an array
3)Compare the username and password in the array to the username and
password entered on the HTML page.
4)If username and password match, direct the user to another web page.
5) If username and password do not match or fields are left blank on the
HTML form, direct user to an error page.

Revised code:
#!/usr/local/bin/perl  
require cgi-lib.pl; 
#process incoming form data  
ReadParse; 
#open the database in read-only mode  
open(FILE,pwdata.txt) || die Can't find database\n; 
#store database contents in an array and close file  
@indata = FILE;  
close(FILE); 
foreach $i (@indata)   
{ 
#remove hard return character from each record  
chomp($i); 
#split fields on pipe character   
#assign a variable name to each of the fields  
($username,$password) = split(/\|/,$i);
if ($username ne /$in{username}/) 
{ 
#invalid password--create error message and exit  
print PrintHeader; 
print PrintTag;  
HTML  
HEAD  
TITLEError!/TITLE  
/HEAD  
BODY BGCOLOR=white TEXT=black  
H1Authorization Required/H1  
BLOCKQUOTE  
You do not have authorization to enter this website. Please click a
href=http://www.worldwidewebstrategies.com;here/a
to return to the WWWS web site.
/BLOCKQUOTE 
BLOCKQUOTE  
If you feel you have received this message in error, please return to
the
login screen and try to enter your username and password again.  
 /BLOCKQUOTE  
/BODY  
/HTML  
PrintTag
exit(0);  
} 
#check for blank form fields  
if ($in{'username'}eq || $in{'password'}eq)  
{ #invalid password--create error message and exit  
print PrintHeader; 
print PrintTag;  
HTML  
HEAD  
TITLEError!/TITLE  
/HEAD  
BODY BGCOLOR=white TEXT=black  
H1Authorization Required/H1  
BLOCKQUOTE  
You do not have authorization to enter this website. Please click a
href=http://www.worldwidewebstrategies.com;here/a
to return to the WWWS web site.
/BLOCKQUOTE 
BLOCKQUOTE  
If you feel you have received this message in error, please return to
the
login screen and try to enter your username and password again.  
 /BLOCKQUOTE  
/BODY  
/HTML  
PrintTag
exit(0);  
}; 
#check for existence of lock file  
if (-e lock.fil)   
{ 
#lock file exists! print message  shut down   
print PrintHeader;
print PrintTag;
HTML  
HEAD  
TITLEFile in use/TITLE  
/HEAD  
BODY BGCOLOR=white TEXT=black  
H1Try again!/H1  
BLOCKQUOTE  
The database is in use. Please try again later.  
/BLOCKQUOTE  
/BODY  
/HTML  
PrintTag
exit(0);
}
#everything is okay. Create lock file.  
open(LOCK_FILE, lock.fil); 
#open, append record, and close database  
open(FILE,data.txt) || die Can't find database\n;  
print FILE
$in{'username'}|$in{'password'}\n;
close(FILE); 
#close lock file  
close(LOCK_FILE); 
#delete lock file  
unlink(lock.fil);
#print database contents  
print Location:http://www.worldwidewebstrategies.com\n\n;;
};

Leon wrote:
 
 - Original Message -
 From: maureen [EMAIL PROTECTED]
 To: [EMAIL PROTECTED]
 
  Currently, the array seems to only be picking up the last name listed in
  the text file.
 
  @indata = FILE;
  close(FILE);
  foreach $i (@indata)
  {
  #remove hard return character from each record
  chomp($i);
  #split fields on pipe character
  #assign a variable name to each of the fields
  ($username,$password) = split(/\|/,$i);
  }
 snip off
  #check for proper password
  if ($username!=~/$in{'username'}/)
  {
  #invalid password--create error message and exit
  print PrintHeader;
 
 In the foreach loop, after iteration, $username,$password received the last
 line of the file. What you really want is to check
 $in{'username'} against every line of the file, to do this, you must check
 within the foreach loop like this :-
 
 foreach $i (@indata){
  chomp $i;
  ($username,$password) = split(/\|/,$i);
  if ($username !~ /$in{username}/) {
 # I would prefer to use ne instead of !~
 #invalid password--create error message and exit
 print PrintHeader;
 ...
  };
 };
 
 _
 Do You Yahoo!?
 Get your free @yahoo.com address at http://mail.yahoo.com
 
 --
 To unsubscribe, e-mail: [EMAIL PROTECTED]
 For additional commands, e-mail: [EMAIL PROTECTED]

-- 
Be the change you want to see in the World- Mahatma Ghandi

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Re: Array Problem

2002-01-21 Thread Leon

- Original Message -
From: maureen [EMAIL PROTECTED]
To: Leon [EMAIL PROTECTED]
Cc: [EMAIL PROTECTED]
Sent: Monday, January 21, 2002 8:39 AM
Subject: Re: Array Problem

 if ($username ne /$in{username}/)
 {

Anything in between the forward slash are usually used as a regular
expression such as ~s/$/ or m/.../ whereas things like ne, eq, lt are
straight forward matching operators that dont require forward slash.

Try changing the above to the following and see if it works :-
if ($username ne $in{username}) {.};

 end of my msg ###

 Thanks so much for your help on this. I tried this suggestion, but
 unfortunately, the array @indata does not seem to contain the usernames
 from the file pwdata.txt.

 I've been looking at this for hours. I hope someone can help me figure
 out what I am missing here. The objectives for this code and the revised
 code follow:

 Code Objectives:
 1)Accept username and password from an HTML page
 2)Open a text file and store the username and passwords listed there in
 an array
 3)Compare the username and password in the array to the username and
 password entered on the HTML page.
 4)If username and password match, direct the user to another web page.
 5) If username and password do not match or fields are left blank on the
 HTML form, direct user to an error page.

 Revised code:
 #!/usr/local/bin/perl
 require cgi-lib.pl;
 #process incoming form data
 ReadParse;
 #open the database in read-only mode
 open(FILE,pwdata.txt) || die Can't find database\n;
 #store database contents in an array and close file
 @indata = FILE;
 close(FILE);
 foreach $i (@indata)
 {
 #remove hard return character from each record
 chomp($i);
 #split fields on pipe character
 #assign a variable name to each of the fields
 ($username,$password) = split(/\|/,$i);
 if ($username ne /$in{username}/)
 {
 #invalid password--create error message and exit
 print PrintHeader;
 print PrintTag;
 HTML
 HEAD
 TITLEError!/TITLE
 /HEAD
 BODY BGCOLOR=white TEXT=black
 H1Authorization Required/H1
 BLOCKQUOTE
 You do not have authorization to enter this website. Please click a
 href=http://www.worldwidewebstrategies.com;here/a
 to return to the WWWS web site.
 /BLOCKQUOTE
 BLOCKQUOTE
 If you feel you have received this message in error, please return to
 the
 login screen and try to enter your username and password again.
  /BLOCKQUOTE
 /BODY
 /HTML
 PrintTag
 exit(0);
 }
 #check for blank form fields
 if ($in{'username'}eq || $in{'password'}eq)
 { #invalid password--create error message and exit
 print PrintHeader;
 print PrintTag;
 HTML
 HEAD
 TITLEError!/TITLE
 /HEAD
 BODY BGCOLOR=white TEXT=black
 H1Authorization Required/H1
 BLOCKQUOTE
 You do not have authorization to enter this website. Please click a
 href=http://www.worldwidewebstrategies.com;here/a
 to return to the WWWS web site.
 /BLOCKQUOTE
 BLOCKQUOTE
 If you feel you have received this message in error, please return to
 the
 login screen and try to enter your username and password again.
  /BLOCKQUOTE
 /BODY
 /HTML
 PrintTag
 exit(0);
 };
 #check for existence of lock file
 if (-e lock.fil)
 {
 #lock file exists! print message  shut down
 print PrintHeader;
 print PrintTag;
 HTML
 HEAD
 TITLEFile in use/TITLE
 /HEAD
 BODY BGCOLOR=white TEXT=black
 H1Try again!/H1
 BLOCKQUOTE
 The database is in use. Please try again later.
 /BLOCKQUOTE
 /BODY
 /HTML
 PrintTag
 exit(0);
 }
 #everything is okay. Create lock file.
 open(LOCK_FILE, lock.fil);
 #open, append record, and close database
 open(FILE,data.txt) || die Can't find database\n;
 print FILE
 $in{'username'}|$in{'password'}\n;
 close(FILE);
 #close lock file
 close(LOCK_FILE);
 #delete lock file
 unlink(lock.fil);
 #print database contents
 print Location:http://www.worldwidewebstrategies.com\n\n;;
 };




_
Do You Yahoo!?
Get your free @yahoo.com address at http://mail.yahoo.com


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Re: Array Problem

2002-01-16 Thread Leon

- Original Message -
From: maureen [EMAIL PROTECTED]
To: [EMAIL PROTECTED]

 Currently, the array seems to only be picking up the last name listed in
 the text file.

 @indata = FILE;
 close(FILE);
 foreach $i (@indata)
 {
 #remove hard return character from each record
 chomp($i);
 #split fields on pipe character
 #assign a variable name to each of the fields
 ($username,$password) = split(/\|/,$i);
 }
snip off
 #check for proper password
 if ($username!=~/$in{'username'}/)
 {
 #invalid password--create error message and exit
 print PrintHeader;

In the foreach loop, after iteration, $username,$password received the last
line of the file. What you really want is to check
$in{'username'} against every line of the file, to do this, you must check
within the foreach loop like this :-

foreach $i (@indata){
 chomp $i;
 ($username,$password) = split(/\|/,$i);
 if ($username !~ /$in{username}/) {
# I would prefer to use ne instead of !~
#invalid password--create error message and exit
print PrintHeader;
...
 };
};







_
Do You Yahoo!?
Get your free @yahoo.com address at http://mail.yahoo.com


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Array Problem

2002-01-15 Thread maureen

Hello! I hope someone can help me.  

I am working on the following code, written to accomplish these tasks:

1)Accept username and password from an HTML page
2)Open a text file and store the username and passwords listed there in
an array
3)Compare the username and password in the array to the username and
password entered on the HTML page.
4)If username and password match, direct the user to another web page.
5) If username and password do not match or fields are left blank on the
HTML form, direct user to an error page.

Currently, the array seems to only be picking up the last name listed in
the text file.  

Would you please take a look at my code to help me see what I have done
wrong?

Thanks, Maureen

#!/usr/local/bin/perl  
require cgi-lib.pl; 
#process incoming form data  
ReadParse; 
#open the database in read-only mode  
open(FILE,pwdata.txt) || die Can't find database\n; 
#store database contents in an array and close file  
@indata = FILE;  
close(FILE); 
foreach $i (@indata)   
{ 
#remove hard return character from each record  
chomp($i); 
#split fields on pipe character   
#assign a variable name to each of the fields  
($username,$password) = split(/\|/,$i);
} 
#check for blank form fields  
if ($in{'username'}eq || $in{'password'}eq)  
{ 
#set content type 
} 

#check for proper password  
if ($username!=~/$in{'username'}/) 
{ 
#invalid password--create error message and exit  
print PrintHeader; 
print PrintTag;  
HTML  
HEAD  
TITLEError!/TITLE  
/HEAD  
BODY BGCOLOR=white TEXT=black  
H1Authorization Required/H1  
BLOCKQUOTE  
You do not have authorization to enter this website. Please click a
href=http://www.worldwidewebstrategies.com;here/a
to return to the WWWS web site.
/BLOCKQUOTE 
BLOCKQUOTE  
If you feel you have received this message in error, please return to
the
login screen and try to enter your username and password again.  
 /BLOCKQUOTE  
/BODY  
/HTML  
PrintTag
exit(0);  
} 

#check for existence of lock file  
if (-e lock.fil)   
{ 
#lock file exists! print message  shut down   
print PrintHeader;
print PrintTag;
HTML  
HEAD  
TITLEFile in use/TITLE  
/HEAD  
BODY BGCOLOR=white TEXT=black  
H1Try again!/H1  
BLOCKQUOTE  
The database is in use. Please try again later.  
/BLOCKQUOTE  
/BODY  
/HTML  
PrintTag
exit(0);
} 
#everything is okay. Create lock file.  
open(LOCK_FILE, lock.fil); 
#open, append record, and close database  
open(FILE,data.txt) || die Can't find database\n;  
print FILE
$in{'username'}|$in{'password'}\n;
close(FILE); 
#close lock file  
close(LOCK_FILE); 
#delete lock file  
unlink(lock.fil);
#print database contents  
print Location:http://www.worldwidewebstrategies.com\n\n;;

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Array Problem.

2001-12-10 Thread Andre` Niel Cameron

Hi,

I have a prob:)  I need to search threw an array and remove an item based on
its name.  I was thinking about maybie a for each loop but I am not sure how
to go about it.  Heres what I need to do:

say $object= sword;
I have an array @AllObjects('beer', 'nuts', 'sword', 'and more stuff')
Now sword may or may not ever be in the same location of the array so a
simple shift will not work here.  I need to find a way to pull sword out of
that array.  Any help is as always greatly appreciated:)


Regards,
Andre` C.
Technical Support
ԿԬ

-
Visit our support manual at http://supportmanual.com/


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Re: Array Problem.

2001-12-10 Thread Curtis Poe

--- Andre` Niel Cameron [EMAIL PROTECTED] wrote:
 Hi,
 
 I have a prob:)  I need to search threw an array and remove an item based on
 its name.  I was thinking about maybie a for each loop but I am not sure how
 to go about it.  Heres what I need to do:
 
 say $object= sword;
 I have an array @AllObjects('beer', 'nuts', 'sword', 'and more stuff')
 Now sword may or may not ever be in the same location of the array so a
 simple shift will not work here.  I need to find a way to pull sword out of
 that array.  Any help is as always greatly appreciated:)
 
 
 Regards,
 Andre` C.
 Technical Support
 ԿԬ

@AllObjects = grep { $_ ne 'sword' } @AllObjects;

Or, if you're not sure about the case:

@AllObjects = grep { $_ !~ /^sword$/i } @AllObjects;

See 'perldoc -f grep'

Cheers,
Curtis Ovid Poe

=
Senior Programmer
Onsite! Technology (http://www.onsitetech.com/)
Ovid on http://www.perlmonks.org/

__
Do You Yahoo!?
Check out Yahoo! Shopping and Yahoo! Auctions for all of
your unique holiday gifts! Buy at http://shopping.yahoo.com
or bid at http://auctions.yahoo.com

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]