[16321] in Perl-Users-Digest

home help back first fref pref prev next nref lref last post

Perl-Users Digest, Issue: 3733 Volume: 9

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Jul 18 11:23:20 2000

Date: Tue, 18 Jul 2000 08:23:08 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <963933788-v9-i3733@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Tue, 18 Jul 2000     Volume: 9 Number: 3733

Today's topics:
    Re: Trying to use an array as a hash value (Tad McClellan)
    Re: Trying to use an array as a hash value (Ted)
    Re: Trying to use an array as a hash value (Abigail)
    Re: UDP / ICMP checksum generation - 1's complement sum (Ingmar)
    Re: Unable to append <jaurangNOjaSPAM@crosswinds.net.invalid>
    Re: Unable to append (Taurean)
    Re: Unable to append (Taurean)
    Re: Unable to append (Abigail)
    Re: Understanding the regex in "commify" (perlfaq5) (Andrew Johnson)
        Unflattening a multi-dimensional array (Matthew Stoker)
    Re: Unflattening a multi-dimensional array (Randal L. Schwartz)
    Re: Unflattening a multi-dimensional array (Neil Kandalgaonkar)
    Re: Unflattening a multi-dimensional array (Neil Kandalgaonkar)
    Re: Unflattening a multi-dimensional array (Abigail)
    Re: untainting insecure dependancy? (Abigail)
    Re: Upper-to-lower case problem (Alan Page)
    Re: Upper-to-lower case problem (Ilmari Karonen)
        URL Redirection script (EM)
        Using fcntl in perl (Chien Yang)
    Re: Using fcntl in perl (Abigail)
        using HttpSniffer/PubMed (John Hunter)
        Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)

----------------------------------------------------------------------

Date: 15 Jul 2000 21:50:02 GMT
From: tadmc@metronet.com.bbs@openbazaar.net (Tad McClellan)
Subject: Re: Trying to use an array as a hash value
Message-Id: <3bPlTR$UaR@openbazaar.net>

On Sat, 15 Jul 2000 15:01:07 -0400, Ted <fedya@banet.net> wrote:
>
>Keith Calvert Ivey wrote:
>
>> doglovers@rocketmail.com wrote:
>>
>> >$arrayref = \(a,b,c,d), then you put the reference into the the hash:
>>
>> You need to reread the documentation on references.  The \
>> distributes over the list,

>>    $arrayref = \@array;
                  ^
                  ^

There is an example of how to take a reference to a named array.


>I think I'm having the same exact problem.

>Right now, I've got arrays like the following:
>
>@abe =( 133 , "Abe Julia"  , 2303.1 , 11 , -13 , 2336.6 , 0.5 , 2309.3 );
>@abram =( 466 , "Abram Agnieszka"  , 1814.3 , 1 , -2 , 2127.5 , 6 , 2039.1
>);

>and I was going to try to create the following hash

>I want to make certain the players remain
>in alphabetical order)


Sorting is easy in Perl.

Sort them alphabetically when you need them sorted alphabetically.


>%alphabetical=( 1 => @abe ,


> 2 => @abram ,
> [...]
> 30 => @auer ,
> 31 => @augustus );
>
>From what I've read in this thread, what I've just tried clearly isn't
>going to work, and that I have to reference the array names somehow.
                                                             ^^^^^^^
                                                             ^^^^^^^

As shown above.


>I've
>read perlref, but that only serves to confuse me even more.


You should read a "tutorial" before you read a "reference".


   perldoc perlreftut


>(Personal
>observation -- all those documents at the Perl.com site like perldoc,
>perlref, perlfaq, and so on are IMHO rather overcomplicated and not very
>well organized for someone like me who's trying to learn Perl.)


They are not _designed_ for someone trying to learn Perl, so
that shouldn't be too surprising.

They are nearly all reference documentation.

If you need tutorial information (other than the 4 perl.*tut.pod files),
you need to look elsewhere.

A good book for Programmers wanting to learn Perl is

   "Learning Perl"

A good book for non-programmers wanting to learn programming
(and Perl) is:

   "Elements of Programming with Perl"


>Should I just be creating an anonymous hash on the order of


There is no need for anonymity, you can name your hash if you like.

There is no need for the numerical keys.

There is even no need for the named arrays...


>and then come up with some subroutine to get the appropriate array that
>goes with each number?  I'm not even certain how to get the values out of
>the arrays if I create an anonymous hash.  If I were to create a loop like
>the following:
>
>while (1) {
>$i=1;
>if $i then print "<tr>";


syntax error.


   print '<tr>' if $i;

But since $i is set true on the line right before this,
it is pointless to test its truth anyway, so you might as well:

   print '<tr>';


>for ($x=0; $x <= 7; $x++) {


Whenever you find yourself explicitly indexing an array, you
should pause for a moment to make sure that you are not
writing C (where you have to manage the indexing yourself)
in Perl (where you can use Perl's list functions and have
Perl do the indexing for you).


>print "<td>${$alphabetical}[$i][$x]<\/td>"
>};
>print "<\/tr>";
         ^
         ^ useless character
>$i++;
>else print "<\/table>";
              ^
              ^ useless character
>};


That code is formatted too horribly to be looked upon.

Format your code sensibly if you expect people to read it.


>would that print out at the very least the values in @abe ?

No. It won't do much of anything if it cannot compile.



>Apologies if I'm supposed to be
>escaping the < and > with a \ as well.


Eh?

You only need to escape characters that have a special meaning.

< and > do not have any special meaning in a string, so it
would be *bad* if you did escape them.

It is bad that you have escaped the slash, which is also not
special in a string.

It is bad that you have used a double quoted string where
a single quoted string will do.



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

# make a HoL
my %players = (
   abram => [466 , "Abram Agnieszka"  , 1814.3 , 1 , -2 , 2127.5 , 6 , 2039.1],
   abe => [133 , "Abe Julia"  , 2303.1 , 11 , -13 , 2336.6 , 0.5 , 2309.3],
);

# show them in alphabetical order
foreach my $player ( sort keys %players ) {
   foreach my $index ( 0 .. $#{$players{$player}} ) {
      print "$index: $players{$player}[$index]\n";
   }
   print "-----------\n";
}
 ------------------------------


--
    Tad McClellan                          SGML Consulting
    tadmc@metronet.com                     Perl programming
    Fort Worth, Texas


------------------------------

Date: 15 Jul 2000 18:50:05 GMT
From: fedya@banet.net.bbs@openbazaar.net (Ted)
Subject: Re: Trying to use an array as a hash value
Message-Id: <3bPgiT$WLz@openbazaar.net>

Keith Calvert Ivey wrote:

> doglovers@rocketmail.com wrote:
>
> >$arrayref = \(a,b,c,d), then you put the reference into the the hash:
>
> You need to reread the documentation on references.  The \
> distributes over the list, so you get a list of scalar
> references, not an array reference.  To use \ here you would
> need to assign to an array variable first.
>
>    @array = qw( a b c d );
>    $arrayref = \@array;
>
> >Message => $arrayref,
> >
> >which you then dereference with @$arrayref when
> >you need it. Or you can put in an anonymous array with:
> >
> >Message => [a,b,c,d]
>
> That's the better way to do it.

I think I'm having the same exact problem.  My site is going to have a
bunch of information on players' records on the WTA Tour, and I'm using
arrays to store that information for individual players (so that I can
access a player's stats for the page that will have her matches listed).
However, I'd also like to use the information to create an alpahbetical
ranking table.  Right now, I've got arrays like the following:

@abe =( 133 , "Abe Julia"  , 2303.1 , 11 , -13 , 2336.6 , 0.5 , 2309.3 );
@abram =( 466 , "Abram Agnieszka"  , 1814.3 , 1 , -2 , 2127.5 , 6 , 2039.1
);
[...]
@auer =( 382 , "Auer Bettina"  , 1919.5 , 0 , -1 , 2318.6 , 0 , 1919.5 );
@augustus =( 362 , "Augustus Amanda" , 1938.2 , 0 , -1 , 2337.3 , 0 ,
1938.2 );

and I was going to try to create the following hash so that I could have a
loop of some sort (probably something using an if statement to stop once
an undefined value is reached since the exact number of players changes
slightly from week to week and I want to make certain the players remain
in alphabetical order) print out each scalar in each array in a separate
<td>:

%alphabetical=( 1 => @abe ,
 2 => @abram ,
 [...]
 30 => @auer ,
 31 => @augustus );

From what I've read in this thread, what I've just tried clearly isn't
going to work, and that I have to reference the array names somehow.  I've
read perlref, but that only serves to confuse me even more.  (Personal
observation -- all those documents at the Perl.com site like perldoc,
perlref, perlfaq, and so on are IMHO rather overcomplicated and not very
well organized for someone like me who's trying to learn Perl.)

Should I just be creating an anonymous hash on the order of

$alphabetical={ 1 => @abe ,
 2 => @abram ,
 [...]
 30 => @auer ,
 31 => @augustus };

and then come up with some subroutine to get the appropriate array that
goes with each number?  I'm not even certain how to get the values out of
the arrays if I create an anonymous hash.  If I were to create a loop like
the following:

while (1) {
$i=1;
if $i then print "<tr>";
for ($x=0; $x <= 7; $x++) {
print "<td>${$alphabetical}[$i][$x]<\/td>"
};
print "<\/tr>";
$i++;
else print "<\/table>";
};

would that print out at the very least the values in @abe ?  I know that
the for loop with $x probably ought to be in a subroutine to make things
clearer.  (BTW: I already have the part of the document with the
print "Content-type:text/html\n\n";
and the start of the table encoded.)  Apologies if I'm supposed to be
escaping the < and > with a \ as well.


--Ted                 I have always challenged the "psychoses." Why don't
fedya@banet.net       you have a right to say you are Jesus? And why isn't

                      the proper response to that congratulations?
                      Thomas Szasz, "Reason" Magazine, July 2000


------------------------------

Date: 17 Jul 2000 19:40:05 GMT
From: abigail@delanet.com.bbs@openbazaar.net (Abigail)
Subject: Re: Trying to use an array as a hash value
Message-Id: <3bRNBD$WK7@openbazaar.net>

doglovers@rocketmail.com (doglovers@rocketmail.com) wrote on MMDX
September MCMXCIII in <URL:news:396fc8f2.58675416@news.erols.com>:
`` I'm a little weak on references, but my understanding is that you
`` can't have an array as a hash value, but you can have a reference to
`` an array as a hash value. So if you create the reference to an array:
``
`` $arrayref = \(a,b,c,d), then you put the reference into the the hash:

But that doesn't create a reference to an array. It will make $arrayref
a reference to `d'.

``
`` Message => $arrayref,
``
`` which you then dereference with @$arrayref when
`` you need it. Or you can put in an anonymous array with:
``
`` Message => [a,b,c,d]
``
`` which would work also. I think.


*That* will work, yes.

And so will:

    @message = ('a', 'b', 'c', 'd');
    %hash    = {Message => \@message};



Abigail
--
echo "==== ======= ==== ======"|perl -pes/=/J/|perl -pes/==/us/|perl -pes/=/t/\
 |perl -pes/=/A/|perl -pes/=/n/|perl -pes/=/o/|perl -pes/==/th/|perl -pes/=/e/\
 |perl -pes/=/r/|perl -pes/=/P/|perl -pes/=/e/|perl -pes/==/rl/|perl -pes/=/H/\
 |perl -pes/=/a/|perl -pes/=/c/|perl -pes/=/k/|perl -pes/==/er/|perl -pes/=/./;


------------------------------

Date: 14 Jul 2000 06:40:01 GMT
From: wizard_oz@gmx.net.bbs@openbazaar.net (Ingmar)
Subject: Re: UDP / ICMP checksum generation - 1's complement sum
Message-Id: <3bOYK1$W5r@openbazaar.net>

Thanks to all,

I already figured it out .... here's my perl code - not very complicated
after all

============================================================================
==============
$cor = 0x0000FFFF; # THIS WILL BE USED LATER TO GET RID OF FFFFs
@data=(0x030d,0x0000,0x4500,0x0030,0x03a7,0x4000,0x7e06,0x62a9,0xa9c5,0x0a2a
,0xa9c5,0x38c3,0x0492,0x0018,0x20ec,0xac2e);

# ADD ALL WORDs TOGETHER AND AUTOMATICALLY ACCUMULATE THE CARRY OVER BIT
for (@data)
 { $sum = $sum + $_ }

$carryover = ($sum & 0xFFFF0000) / 0xFFFF;
$word = $sum & 0x0000FFFF;

print "CHECKSUM: ";

# ADD CARRY OVER BIT TO THE SUM
$checksum = $word + $carryover;
# INVERT (COMPLEMENT) FINAL SUM AND REMOVE TRAILING FFFFs
$checksum = ~$checksum & $cor;

print sprintf "%lx", $checksum;
============================================================================
==============

Ingmar.

"Ingmar Koecher" <wizard_oz@gmx.net> wrote in message
news:smsnr08qnd6150@corp.supernews.com...
> I am trying to send out UDP and ICMP packets manually and therefor need to
> calculate the checksum for those packets manually. I am using RawIP perl
> module on LINUX.
>
> I already looked into the RFC 1071 that explains the generation and the
> algorithm, but I still can't make it work. One problem is that I don't
know
> exactly how I calculate a 1's complement sum of hex values. One source I
> have explains it like this:
>
> 1. Treat the data as a stream of 16-bit words
> 2. Compute the 1's complement sum of the 16-bit words
> 3. Take the 1's complement of the computed sum
>
> I have a source code in C (at the bottom), but that doesn't help me either
> since I can't program C.
>
> What I tried:
>
> I calculated the 1's complement like: $a_compl = ~$a;
> I added all 16-bit words complements
> I added the carry-over bit to the sum
> I created the 1's complement of the previously generated sum
>
> However, it doesn't work. I also tried not complementing the first value,
> but no success, my calculation never matches the correct one (I know
because
> I'm using a sniffer).
>
> Well, I'm at the end. I've tried for appr. 2 days now, installed linux in
a
> 4day session just for this reason and here I fail, sitting on a table with
> papers full of hex code.
>
>
> If anybody out there can help me I would be very happy.
>
> Below the C code,
>
> many thanks,
>
> Ingmar.
>
> ====================== C - code ====================================
> unsigned short in_cksum( void *addr, int len ) {
>  long sum = 0;
>  unsigned short *ip = (unsigned short *) addr;
>
>  while ( len > 1 ) {
>   sum += *((unsigned short *) ip)++;
>   if (sum & 0x80000000)  /* if high-order bit
> set, fold */
>    sum = (sum &0xFFFF) + (sum >> 16);
>   len -= 2;
>  }
>
>  if ( len ) sum += (unsigned short) *(unsigned char *) ip;
>
>  while ( sum >> 16 ) sum = ( sum & 0xFFFF ) + ( sum >> 16 );
>
>  return ~sum;
> }
> ====================== C - code ====================================
>
>


------------------------------

Date: Tue, 18 Jul 2000 03:08:26 -0700
From: Taurean <jaurangNOjaSPAM@crosswinds.net.invalid>
Subject: Re: Unable to append
Message-Id: <2ade2679.a8f07319@usw-ex0108-061.remarq.com>

Still no joy!


* Sent from AltaVista http://www.altavista.com Where you can also find related Web Pages, Images, Audios, Videos, News, and Shopping.  Smart is Beautiful


------------------------------

Date: 18 Jul 2000 02:50:03 GMT
From: jaurangNOjaSPAM@crosswinds.net.invalid.bbs@openbazaar.net (Taurean)
Subject: Re: Unable to append
Message-Id: <3bRYKU$Wrz@openbazaar.net>

When I add the following line:

use strict;

I get an error message:

'somepath\advert_add.pl' script produced no output

How do I solve this problem?



* Sent from AltaVista http://www.altavista.com Where you can also find related Web Pages, Images, Audios, Videos, News, and Shopping.  Smart is Beautiful


------------------------------

Date: 18 Jul 2000 03:10:02 GMT
From: jaurangNOjaSPAM@crosswinds.net.invalid.bbs@openbazaar.net (Taurean)
Subject: Re: Unable to append
Message-Id: <3bRYjQ$W1c@openbazaar.net>

Still no joy!

The problem is unable to append. I've checked the text
file. No database is used. When I run advert_pl, the
records are displayed correctly. I think the problem lies
with advert_add.pl.

When I add the -T switch or the use strict line, I get the
following message:

'somepath\advert_add.pl' script produced no output

I hope you can help me with this problem.


* Sent from AltaVista http://www.altavista.com Where you can also find related Web Pages, Images, Audios, Videos, News, and Shopping.  Smart is Beautiful


------------------------------

Date: 18 Jul 2000 03:30:04 GMT
From: abigail@delanet.com.bbs@openbazaar.net (Abigail)
Subject: Re: Unable to append
Message-Id: <3bRZMV$Xjf@openbazaar.net>

Taurean (jaurangNOjaSPAM@crosswinds.net.invalid) wrote on MMDXIII
September MCMXCIII in <URL:news:176f8e61.3226a73d@usw-ex0108-061.remarq.com>:
'' When I add the following line:
''
'' use strict;
''
'' I get an error message:
''
'' 'somepath\advert_add.pl' script produced no output
''
'' How do I solve this problem?


Add the following at the top of your program:

    BEGIN {print "Output!\n"}

HTH. HAND.


Abigail
--
BEGIN {$^H {join "" => ("a" .. "z") [8, 13, 19, 4, 6, 4, 17]} = sub
           {["", "Just ", "another ", "Perl ", "Hacker\n"] -> [shift]};
       $^H = hex join "" => reverse map {int ($_ / 2)} 0 .. 4}
print 1, 2, 3, 4;


------------------------------

Date: 16 Jul 2000 19:30:19 GMT
From: andrew-johnson@home.com.bbs@openbazaar.net (Andrew Johnson)
Subject: Re: Understanding the regex in "commify" (perlfaq5)
Message-Id: <3bQXMh$TuM@openbazaar.net>

In article <39711E25.8FA76108@netstorm.net>,
 Jim Mauldin <mauldin@netstorm.net> wrote:

[snip]
 
> Then it starts over with the while loop, with ([-+]?\d+) matching
> everything up to the comma on the first pass, and then working backward
> as before.
>
> Is that what's going on, or is it something else?

Yes, that is what is going on -- you can even see the re itself in
action using: use re 'debug'; in recent versions. Try this, for
example:

#!/usr/bin/perl -w
use strict;
use re 'debug';
$_ = '12345678';
1 while s/^([-+]?\d+)(\d{3})/$1,$2/;
print;

This will show you the steps the re engine takes to successfully
match on the first and second while loop tests, and then fail on
the third.

andrew

--
Andrew L. Johnson   http://members.home.net/andrew-johnson/
      It may be that your sole purpose in life is simply to
      serve as a warning to others.
 


------------------------------

Date: 18 Jul 2000 01:50:01 GMT
From: matt.stoker@motorola.com.bbs@openbazaar.net (Matthew Stoker)
Subject: Unflattening a multi-dimensional array
Message-Id: <3bRWfP$VqD@openbazaar.net>

I appologize if I overlooked this in a FAQ somewhere, but I have the
following problem.

I have an array (@data_set) that is read from a file. I need to parse
this large flat array into a multidimensional array (a list of lists in
perlspeak). Anyway, what makes it tricky is that I don't know beforehand
how many dimensions the multidimensional array should have or the number
of elements in each dimension.  These are also read from the file into a
second array @dim. Therefore:

@dim      = the desired number of dimensions
$dim[0]   = the number of elements in the 1st dimension
$dim[1]   = the number of elements in the 2nd dimension
 
 
 
$dim[$#dim]= the number of elements in the last dimension

If I knew the number of dimensions beforehand, it would be easy to use a
series of nested "for" loops as follows:

#!/usr/local/bin/perl -w
#
# example for creating a 3d array
#

use strict;
my ($i, $j, @data_set, @dim, @multi_array);

open(INP, "input_file.inp") or die "Can't open input_file.inp";
@dim = split (" ",<INP>);
while (<INP>)
{
  push @data_set, split;
}

for $i (0..$dim[2]-1)
{
  for $j (0..$dim[1]-1)
  {
    $multi_array[$i][$j] = [splice (@data_set,0,$dim[0])];
  }
}

# Now print out the results:
for $i (0..$dim[2]-1)
{
  print "ith dimension: $i\n";
  for $j (0..$dim[1]-1)
  {
    print "jth = $j  @{$multi_array[$i][$j]} \n";
  }
}

But since I don't know how many dimensions, I don't know how many nested
loops to put in the code.  Any suggestions?

thanks

--
/------------------------------------------------------------------\
| Matt Stoker                |     email: matt.stoker@motorola.com |
| Unit Process Modeling      | Mail Drop: M360                     |
| DigitalDNA(TM) Laboratories|     Phone: (480)655-3301            |
| Motorola, SPS              |       Fax: (480)655-5013            |
| 2200 W Broadway Road       |     Pager: (888)699-8803            |
| Mesa, AZ 85202             |                                     |
\------------------------------------------------------------------/


------------------------------

Date: 18 Jul 2000 02:20:03 GMT
From: merlyn@stonehenge.com.bbs@openbazaar.net (Randal L. Schwartz)
Subject: Re: Unflattening a multi-dimensional array
Message-Id: <3bRXV3$WXa@openbazaar.net>

>>>>> "Matthew" == Matthew Stoker <matt.stoker@motorola.com> writes:

Matthew> @dim      = the desired number of dimensions
Matthew> $dim[0]   = the number of elements in the 1st dimension
Matthew> $dim[1]   = the number of elements in the 2nd dimension
Matthew> .
Matthew> .
Matthew> .
Matthew> $dim[$#dim]= the number of elements in the last dimension

Well, the array can be defined recursively fairly easily, so a recursive
subroutine would be the most straightforward way to me to built it.

    @data = (1..30);
    @dims = (5,2,3);
    my @result = reformat(@dims);

    sub reformat {
      my $count = shift;
      if (@_) { # more recursion needed
        map { [reformat(@_)] } 1..$count;
      } else {
        splice(@data, 0, $count);
      }
    }

    use Data::Dumper;
    print Dumper(\@result);

There are probably far more efficient solutions, but if you're not
doing this every 5 seconds, who cares? :) I didn't do any error
checking to ensure that @dims conforms to the original size of @data,
so beware.

print map $_, "Just another Perl hacker,"

--
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!


------------------------------

Date: 18 Jul 2000 03:30:04 GMT
From: neil@brevity.org.bbs@openbazaar.net (Neil Kandalgaonkar)
Subject: Re: Unflattening a multi-dimensional array
Message-Id: <3bRZMT$Xbh@openbazaar.net>

In article <3973B2B4.F68CB68A@motorola.com>,
Matthew Stoker  <matt.stoker@motorola.com> wrote:
>I appologize if I overlooked this in a FAQ somewhere, but I have the
>following problem.
>
>I have an array (@data_set) that is read from a file. I need to parse
>this large flat array into a multidimensional array (a list of lists in
>perlspeak). Anyway, what makes it tricky is that I don't know beforehand
>how many dimensions the multidimensional array should have or the number
>of elements in each dimension.  These are also read from the file into a
>second array @dim. Therefore:
>
>@dim      = the desired number of dimensions
>$dim[0]   = the number of elements in the 1st dimension
>$dim[1]   = the number of elements in the 2nd dimension
>.
>.
>.
>$dim[$#dim]= the number of elements in the last dimension
>
>If I knew the number of dimensions beforehand, it would be easy to use a
>series of nested "for" loops as follows:
>
>#!/usr/local/bin/perl -w
>#
># example for creating a 3d array
>#
>
>use strict;
>my ($i, $j, @data_set, @dim, @multi_array);
>
>open(INP, "input_file.inp") or die "Can't open input_file.inp";
>@dim = split (" ",<INP>);
>while (<INP>)
>{
>  push @data_set, split;
>}
>
>for $i (0..$dim[2]-1)
>{
>  for $j (0..$dim[1]-1)
>  {
>    $multi_array[$i][$j] = [splice (@data_set,0,$dim[0])];
>  }
>}
>
># Now print out the results:
>for $i (0..$dim[2]-1)
>{
>  print "ith dimension: $i\n";
>  for $j (0..$dim[1]-1)
>  {
>    print "jth = $j  @{$multi_array[$i][$j]} \n";
>  }
>}
>
>But since I don't know how many dimensions, I don't know how many nested
>loops to put in the code.  Any suggestions?
>
>thanks
>
>--
>/------------------------------------------------------------------\
>| Matt Stoker                |     email: matt.stoker@motorola.com |
>| Unit Process Modeling      | Mail Drop: M360                     |
>| DigitalDNA(TM) Laboratories|     Phone: (480)655-3301            |
>| Motorola, SPS              |       Fax: (480)655-5013            |
>| 2200 W Broadway Road       |     Pager: (888)699-8803            |
>| Mesa, AZ 85202             |                                     |
>\------------------------------------------------------------------/


--
Neil Kandalgaonkar <neil@brevity.org>


------------------------------

Date: 18 Jul 2000 03:30:04 GMT
From: neil@brevity.org.bbs@openbazaar.net (Neil Kandalgaonkar)
Subject: Re: Unflattening a multi-dimensional array
Message-Id: <3bRZMX$VSF@openbazaar.net>

Sorry for the posting... for some reason I still can't cancel my
own posts. Will investigate.

Anyway, my answer was basically the same as Randal's (no really, here
it is:)


#!/usr/bin/perl -w

use strict;

use Data::Dumper;

my $input = "input_file.inp";


# open(INP, "< $input") or die "Can't open $input: $!";
*INP = *DATA;   # just for this example.


my (@data_set, @dim);


# the first line tells us what the structure is;
# 4 2 3 means, take (4 sets of (2 sets of (3 items)))

@dim = split " " , <INP>;


# make @data_set a lonnng array of the rest of the stuff in the file.

while (<INP>) {
  push @data_set, split;
}


my @results;
while (@data_set) {
  push @results, deep_lol (\@data_set, @dim);
}
print (Dumper \@results);


sub deep_lol {
 
  my ($data_set, @dim) = @_;
  my $n = shift @dim;      # here's how many thingies we need.
 
  if (@dim) {              # if there are any @dim left we should...
                           # get N deep_lol's with the structure
			   # of the lexical @dim
 
    my @temp;
    for (1..$n) {
      push @temp, deep_lol( $data_set, @dim );
    }
    return \@temp;        # and return the array ref
 
  } else {                # otherwise, we are at the last @dim item...
                          # shift off N dataset items,
                          # and return that arrayref
 
    return [ splice (@$data_set, 0, $n) ];
 
  }
}

__DATA__
2 1 3 4
a b c d e f g h i j k l m n o p q r s t u v w x y z
a b c d e f g h i j k l m n o p q r s t u v w x y z
a b c d e f g h i j k l m n o p q r s t u v w x y z






--
Neil Kandalgaonkar <neil@brevity.org>


------------------------------

Date: 18 Jul 2000 05:20:04 GMT
From: abigail@delanet.com.bbs@openbazaar.net (Abigail)
Subject: Re: Unflattening a multi-dimensional array
Message-Id: <3bRcG3$UT_@openbazaar.net>

Matthew Stoker (matt.stoker@motorola.com) wrote on MMDXIII September
MCMXCIII in <URL:news:3973B2B4.F68CB68A@motorola.com>:
$$ I appologize if I overlooked this in a FAQ somewhere, but I have the
$$ following problem.
$$
$$ I have an array (@data_set) that is read from a file. I need to parse
$$ this large flat array into a multidimensional array (a list of lists in
$$ perlspeak). Anyway, what makes it tricky is that I don't know beforehand
$$ how many dimensions the multidimensional array should have or the number
$$ of elements in each dimension.  These are also read from the file into a
$$ second array @dim. Therefore:
$$
$$ @dim      = the desired number of dimensions
$$ $dim[0]   = the number of elements in the 1st dimension
$$ $dim[1]   = the number of elements in the 2nd dimension
$$ .
$$ .
$$ .
$$ $dim[$#dim]= the number of elements in the last dimension
$$
$$ If I knew the number of dimensions beforehand, it would be easy to use a
$$ series of nested "for" loops as follows:
$$
$$ But since I don't know how many dimensions, I don't know how many nested
$$ loops to put in the code.  Any suggestions?


my    @dim  =               split " " => <INP>;
my    @data = do {local $/; split " " => <INP>};

my    $code = $multi = shift @data;';
map  {$code =~ s/\$multi/\$multi [\$x$_]/;
      $code = "for my \$x$_ (0 .. $dim[$_] - 1) {$code}";}
       reverse 0 .. $#dim;
eval  $code;


Golf, anyone?


Abigail
--
print v74.117.115.116.32, v97.110.111.116.104.101.114.32,
      v80.101.114.108.32, v72.97.99.107.101.114.10;


------------------------------

Date: 17 Jul 2000 19:40:04 GMT
From: abigail@delanet.com.bbs@openbazaar.net (Abigail)
Subject: Re: untainting insecure dependancy?
Message-Id: <3bRNBB$WC1@openbazaar.net>

pkey@sghms.ac.uk (pkey@sghms.ac.uk) wrote on MMDIX September MCMXCIII in
<URL:news:396ee8e5.7888928@news.sghms.ac.uk>:
$$ Solaris
$$
$$ I have a perl program which I pass a parameter using @ARGV.
$$
$$ The program runs something like this:
$$
$$ $test_user = $ARGV[0];
$$
$$ $quota1 = `quota -v $test_user`;
$$
$$ I then get the following taint error:
$$
$$ Insecure dependency in `` while running with -T switch (referring to
$$ the quota system call.
$$
$$ I know why I'm getting the taint error - how can I untaint the error
$$ so that my program runs?


Eh, if you are going to trust whatever input your program is getting,
why bother with tainting?



Abigail
--
BEGIN {my $x = "Knuth heals rare project\n";
       $^H {integer} = sub {my $y = shift; $_ = substr $x => $y & 0x1F, 1;
       $y > 32 ? uc : lc}; $^H = hex join "" => 2, 1, 1, 0, 0}
print 52,2,10,23,16,8,1,19,3,6,15,12,5,49,21,14,9,11,36,13,22,32,7,18,24;


------------------------------

Date: 14 Jul 2000 07:00:01 GMT
From: alandpage@aol.comnospam.bbs@openbazaar.net (Alan Page)
Subject: Re: Upper-to-lower case problem
Message-Id: <3bOYj3$Y00@openbazaar.net>

>ok .. well the lc will probably not help you then (there was nothing
>wrong with your tr/// code - assuming that you're using an english
>locale - the default) .. show more code - like where else you're using
>$batch

Jason,

Here's the whole script; there's not much to it. It runs fine without the
case-change piece; when  a visitor inputs a batch number (a-f) and a photo
number (759 - 999), the script redirects them to a web page of the same name.

For example, the user puts in "b" and "811"; the script returns
http://www.sizzlinsummer.com/sf/pages/b811.htm

I'm just trying to eliminate them putting in "B" instead of "b"

Thanks,
Alan

Code follows:

#!/usr/bin/perl54


##Script to find the SF Music Festival participants' photos##

##Data submitted:
	#batch
	#photo

##Read posted data##
&ReadParse(*input);

#Get batch number (a,b,c,d,e,f)
$batch =  $input{'batch'};

#Convert to lowercase
$batch =~ tr/A-Z/a-z/;

#Get photo number (759 - 999)
$photo =  $input{'photo'};

##See whether user left any fields blank##
if (($batch eq "") || ($photo eq ""))
{
	$message = qq|Sorry, your form was not complete. <BR> Please fill out all the
fields and try again.|;
	$valid = 0;
}
else {
	$valid = 1;
}

##Concatenate photo page's name (a759.htm, a760.htm, etc)
$page  = $batch . $photo . ".htm";

##Check to see if their photo exists
if (-e "../public_html/sf/pages/$page") {
      print qq|Location: http://www.sizzlinsummer.com/sf/pages/$page\n\n|;
}
else {
      print "Content-type: text/plain", "\n\n";
      print "Didn't find it: $page", "\n";
}



exit(0);




#######SUBS #####

sub ReadParse
{
#call: "&ReadParse(*input)", passes byref "%input" with multiple values
separated by "\0"


  local (*in) = @_ if @_;
  local ($i, $key, $val,$safety);

  # Read in text
  if ($ENV{'REQUEST_METHOD'} eq "GET")
  {
    $in = $ENV{'QUERY_STRING'};
  }
  elsif ($ENV{'REQUEST_METHOD'} eq "POST")
  {
    read(STDIN,$in,$ENV{'CONTENT_LENGTH'});
  }

  @in = split(/&/,$in);

  foreach $i (0 .. $#in)
  {
    # Convert plus's to spaces
    $in[$i] =~ s/\+/ /g;

    # Split into key and value.
    ($key, $val) = split(/=/,$in[$i],2); # splits on the first =.

    # Convert %XX from hex numbers to alphanumeric
    $key =~ s/%(..)/pack("c",hex($1))/ge;
    $val =~ s/%(..)/pack("c",hex($1))/ge;

    # Associate key and value
    $in{$key} .= "-" if (defined($in{$key})); # \0 is the multiple separator
    $in{$key} .= $val;
  }
  	return length($in);
}


------------------------------

Date: 17 Jul 2000 07:40:02 GMT
From: iltzu@sci.invalid.bbs@openbazaar.net (Ilmari Karonen)
Subject: Re: Upper-to-lower case problem
Message-Id: <3bR4N2$UaP@openbazaar.net>

In article <hjnumsoj1bcg4rkcfd4u3nl6fgrcrnp7dp@4ax.com>, Bart Lateur wrote:
>Taint check:
>
>	$valid = 1;   # assumed, for now
>	if($input{'batch'} =~ /^([a-fA-F)$/) {
>	    $batch = lc $1;
>	} else {
>	    &error("Not a valid batch");
>	    $valid = 0;
>	}

I think you should've taint-checked that code too:

  /^([a-fA-F)$/: unmatched [] in regexp at - line 2.

--
Ilmari Karonen - http://www.sci.fi/~iltzu/
"The screwdriver *is* the portable method."  -- Abigail
Please ignore Godzilla and its pseudonyms - do not feed the troll.


------------------------------

Date: 17 Jul 2000 03:10:10 GMT
From: me@privacy.net.bbs@openbazaar.net (EM)
Subject: URL Redirection script
Message-Id: <3bQjLY$Vu2@openbazaar.net>

I want to run a subdomain redirection service
my problem is how can I do path forwarding
I tried using the 404 error in the .htaccess but it only works in netscape
and ie4 but not ie5
How can I do this possibly without using mod/rewrite because I do not have
the module installed

Eric


------------------------------

Date: 18 Jul 2000 04:50:03 GMT
From: csyang@cisco.com.bbs@openbazaar.net (Chien Yang)
Subject: Using fcntl in perl
Message-Id: <3bRbQQ$X5z@openbazaar.net>

Hello,

I am new to this newsgroup.  I would like to know how use the function
"fcntl()" to lock a file for writing.   Also, please tell me what do I
pass into the third parameter of "fcntl()"?


Thanks.


Chien


------------------------------

Date: 18 Jul 2000 05:30:03 GMT
From: abigail@delanet.com.bbs@openbazaar.net (Abigail)
Subject: Re: Using fcntl in perl
Message-Id: <3bRcSR$Xzt@openbazaar.net>

Chien Yang (csyang@cisco.com) wrote on MMDXIII September MCMXCIII in
<URL:news:3973E1B3.CD741CC7@cisco.com>:
() Hello,
()
() I am new to this newsgroup.  I would like to know how use the function
() "fcntl()" to lock a file for writing.   Also, please tell me what do I
() pass into the third parameter of "fcntl()"?


That question cannot be answered. 'fcntl' gives you access to your
systems 'fcntl'. So, see your systems manpage about 'fcntl'.

If you want to lock files the Perl way instead of your systems way,
use flock.



Abigail
--
perl -Mstrict -we '$_ = "goto X.print chop;\n=rekcaH lreP rehtona tsuJ";X1:eval'


------------------------------

Date: 17 Jul 2000 17:00:02 GMT
From: jdhunter@nitace.bsd.uchicago.edu.bbs@openbazaar.net (John Hunter)
Subject: using HttpSniffer/PubMed
Message-Id: <3bRJ32$Wjx@openbazaar.net>

I am using the WWW::Search::PubMed to search the PubMed.  I am trying
to figure out how to request the articles in MEDLINE format instead of
the default Summary format.

I wanted to figure out what was happening when I clicked on the
Display button with the MEDLINE option chosen, ie what kind of request
was being sent so perhaps I could hack PubMed.pm to send the kind of
request I want.

So I tried using HttpSniffer with
HttpSniffer -r http://www.ncbi.nlm.nih.gov
and directing my http address to http://localhost:8080/PubMed but I
can't interact with the buttons and drop down menus in this way.

So my questions are: is there a way to get the information I want with
HttpSniffer?  Is there some other way to monitor all the traffic
between the web browser and server, ie a proxy app which just logs and
transmits all requests to a from a browser?


Thanks,
John Hunter


------------------------------

Date: 16 Sep 99 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 16 Sep 99)
Message-Id: <null>


Administrivia:

The Perl-Users Digest is a retransmission of the USENET newsgroup
comp.lang.perl.misc.  For subscription or unsubscription requests, send
the single line:

	subscribe perl-users
or:
	unsubscribe perl-users

to almanac@ruby.oce.orst.edu.  

| NOTE: The mail to news gateway, and thus the ability to submit articles
| through this service to the newsgroup, has been removed. I do not have
| time to individually vet each article to make sure that someone isn't
| abusing the service, and I no longer have any desire to waste my time
| dealing with the campus admins when some fool complains to them about an
| article that has come through the gateway instead of complaining
| to the source.

To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.

To request back copies (available for a week or so), send your request
to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
where x is the volume number and y is the issue number.

For other requests pertaining to the digest, send mail to
perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
sending perl questions to the -request address, I don't have time to
answer them even if I did know the answer.


------------------------------
End of Perl-Users Digest V9 Issue 3733
**************************************


home help back first fref pref prev next nref lref last post