[12340] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 5940 Volume: 8

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Jun 10 00:07:27 1999

Date: Wed, 9 Jun 99 21:00:17 -0700
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Wed, 9 Jun 1999     Volume: 8 Number: 5940

Today's topics:
        "System" function delays output <thomas@shurflo.com>
    Re: ActivePerl Win98 CGI Problem <chongsun@krdl.org.sg>
    Re: ANSWER: Re: uninitialized value? what am i doing wr (Larry Rosler)
    Re: cookie-monster.pl, a cookie scrambler. (Ronald J Kimball)
        Emailing Binary Files rad91@my-deja.com
        How do I sort files in a dir by last modified time? <aef@pangea.ca>
        How to display background picture in cgi? <chongsun@krdl.org.sg>
    Re: How to write TO a socket? (client/server socket stu (Ronald J Kimball)
        New to this - Help <kath_m@2hotmail.com>
    Re: Problems sorting. I'm stupid and I'll die (Ronald J Kimball)
        Problems with 2GB RAM on Linux and libc's sbrk edk1@my-deja.com
    Re: Regexpr for loop to handle e-address list dalehend@flash.net
        run .exe on Win32 jbell@263.net
    Re: Separating array into alphabetical array of arrays (Larry Rosler)
    Re: Separating array into alphabetical array of arrays (Matthew Bafford)
    Re: Sequently adding data to a hash with $x[x..x]??? (Larry Rosler)
    Re: Sequently adding data to a hash with $x[x..x]??? <uri@sysarch.com>
    Re: Sequently adding data to a hash with $x[x..x]??? (Tad McClellan)
    Re: Setting cookies with CGI.pm (Ronald J Kimball)
    Re: size of a subdirectory without readdir? (William Herrera)
        System command <technology@workmail.com>
        Special: Digest Administrivia (Last modified: 12 Dec 98 (Perl-Users-Digest Admin)

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

Date: Wed, 09 Jun 1999 20:16:13 -0700
From: Thomas/Shurflo <thomas@shurflo.com>
Subject: "System" function delays output
Message-Id: <375F2DFD.E3772DB0@shurflo.com>

I'm using the system function to collect data from files. I'd like to
display dynamic data after each file is processed, but for some reason
the "system" function delays STDOUT until the script is completed.
Anyone have any ideas why?

--
Shurflo does not accept responsibility for any views expressed or
implied
in the text or graphics of this email response/inquiry. I don't either.

Thomas/Shurflo




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

Date: Thu, 10 Jun 1999 11:37:09 +0800
From: "CacheBoy" <chongsun@krdl.org.sg>
Subject: Re: ActivePerl Win98 CGI Problem
Message-Id: <7jnc4v$p6u$2@godzilla.krdl.org.sg>

Have you tried Apache win32?
And it is free! (at least for the time being)
I installed Apache win32 and ActiveState's perl and ran my cgi at no problem
at all. except for those that needs to send mail.




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

Date: Wed, 9 Jun 1999 18:53:12 -0700
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: ANSWER: Re: uninitialized value? what am i doing wrong?
Message-Id: <MPG.11c8ba5c8350a071989ba5@nntp.hpl.hp.com>

In article <199906100138.TAA14738@asarian-host.org> on Thu, 10 Jun 1999 
03:37:56 +0200, Mark <admin@asarian-host.org> says...
> Bastiaan S van den Berg <office@asc.nl> wrote in message
> news:7j5sfp$l4k$1@zonnetje.NL.net...
 ...
> > to check if a variable is defined :
> >
> > print "Car exists !\n" if defined $car;
> 
> Or simply:
> 
> .. if ($car);
'
That has different semantics.  Consider the 'defined' values 0 or '0'.

> Sometimes life is hard; not today. :)

I don't know about that, for sure!

-- 
(Just Another Larry) Rosler
Hewlett-Packard Company
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com


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

Date: Wed, 9 Jun 1999 22:45:40 -0400
From: rjk@linguist.dartmouth.edu (Ronald J Kimball)
Subject: Re: cookie-monster.pl, a cookie scrambler.
Message-Id: <1dt5ibh.1q01adbcdgpb2N@p90.tc5.metro.ma.tiac.com>

Omri Schwarz <ocschwar@MIT.EDU> wrote:

> #!/usr/athena/bin/perl

I think you should distribute your code with a more standard path to
perl.


You're missing -w and use strict.  They would definitely have found
errors in this script.


> # cookie monster: a utility for scrambling the
> # cookies of annoying websites.

Cute name.  :)


> #
> # (C) Omri Schwarz
> #
> # Motive: a site that was configured to retry cookie requests that are
> refused.

That line is too long.  :P


> $arg_check=@ARGV;
> zsrand;

What is zsrand?


> @poschars_hex=("a","b","c","d","e","f","1","2","3",
>                "4","5","6","7","8","9","0");
> @poschars_b64=("1","2","3","4","5","6","7","8","9","0","=","/",
>                "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",
                                                               ^^^

Your array does not have as many elements as you might have hoped.  :)


>                "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");

Any reason you didn't use the range operator instead?

@poschars_hex=("a" .. "f","1" .. "0");
@poschars_b64=("1" .. "0", "=", "/", "a" .. "z", "A" .. "Z");


> $site_file="$ENV{HOME}/.netscape/cookies.victims";
> #Going through the subroutines.
> #
> for ($look_at=0; $look_at<=$arg_check; $look_at++){
>     $argument = @ARGV[$look_at];
>     if ($look_at < $arg_check){
>         $new_site=$ARGV[$look_at+1 ];
>     }
>     if ($look_at < $arg_check-1){
>         $last_arg=$ARGV[$look_at+2 ];
>     }
> 
>     if ($argument eq "-a") {
>         append_site($new_site,$site_file,$last_arg);

Note arguments in subroutine call...


>     } ;
> 
>     if ($argument eq "-d") {
>         delete_site($site_file,$new_site);
>     }
>     if ($argument eq "-f") {
>         $site_file=@ARGV[$look_at +1 ];

One-element array slice in scalar context.


>     } 
>     if ($argument eq "-s") {
>         scramble_cookies($site_file);
>     } 
>     if ($argument eq "-l") {
>         list_victims($site_file);
>     }
> 
> #    print "---\n";
> }

So...  Do you have something against the Getopt modules?  They handle
processing of command line arguments conveniently _and_ correctly.


> sub append_site {

 ...Note subroutine ignores arguments.


>     open(SITEFILE,">>$site_file") || 
>         open(SITEFILE,">$site_file") || 
>             die "Sorry, your site list $site_file is a nono.\n";

Why is it a nono?  $! would tell you.


>     print SITEFILE "$new_site $last_arg\n";
>     print "Adding $new_site to your victims.\n";
>     close(SITEFILE);
> }
> 
> sub delete_site {
>     $tempfile= $site_file;
>     $tempfile .= ".temp";

Why not do that in one line?

$tempfile = $sitefile . '.temp';


>     print "hmm $new_site\n";

Very informative message.


>     open(SITEFILE,$site_file) || 
>         die "Sorry, your site list $site_file is AWOL.\n";

See above.  $!.


>     open(TEMPFILE,">$tempfile") || 
>         die "Sorry, no room for temp file. ";

Er...  Now you're making up error messages.  Use $!.  Really.


>     while(<SITEFILE>) {
>         s/$new_site//g;

So $new_site will never contain regex metacharacters??

s/\Q$new_site//g;


>         if (length($_) > 1 ) {
>             print TEMPFILE $_;
>         }

What exactly is the format of the site file?  This code and the code to
add to it are just odd.


>     }
>     close(SITEFILE);
>     close(TEMPFILE);
>     system "mv -f $tempfile $site_file";

Something wrong the builtin function rename()?


> }
> sub list_victims {
>     open(SITEFILE,$site_file) || 
>         die "Sorry, your site list $site_file is AWOL.\n";

See above.  $!.


>     while(<SITEFILE>) {
>         print STDOUT $_;
>     }
>     if ($argument eq "-l") {
>         list_victims($site_file);
>     }

Ah...  Isn't this a bit recursive?  When does it stop?


> #    print "---\n";
> }
> 
> sub scramble_cookies {
>     open(SITEFILE,$site_file) || 
>         die "Sorry, your site list $site_file is AWOL.\n";

See above.  $!.


>     chomp(@sites = <SITEFILE>);
>     close(SITEFILE);
>     open(TEMPFILE, ">$ENV{HOME}/.netscape/cookies.scrambled");

Always check the return value of open().

>     open(COOKIEFILE,"$ENV{HOME}/.netscape/cookies") ||
>         die "Sorry, your cookie file is missing.\n";

See above.  $!.


>     while(<COOKIEFILE>) {
>         $outgoing=$_;
>         $scramble_method="hex_eq";
>         @cookie = split /\s+/,$outgoing ;

Why not
@cookie = split ' ', $outgoing;
?


>         $cookie_site=$cookie[0];
> #       print "\n   $cookie_site . ";
>         foreach $site_entry (@sites) {
>             $sitename = $site_entry;
>             @entries = split $site_entry;
>             if ($#entries>1){

Why do you require at least 3 elements when you only want 2?


>                 $sitename = $entries[0];
>                 $scramble_method = $entry[1];

Where did the @entry array come from??


>             } 
> #           print " $sitename,";
> 
>             if ($sitename eq $cookie_site){
> 
>                 if ($scramble_method eq "hex_eq") {
> 
>                     scramble_hex_eq_mode($sitename,@cookie,$outgoing);
>                 } elsif ($scramble_method eq "b64_eq") {
>                     scramble_b64_eq_mode($sitename,@cookie,$outgoing);
>                 } elsif ($scramble_method eq "hex") {
>                     scramble_hex_mode($sitename,@cookie,$outgoing);
> 
> #
> # add elsifs for other cookie modes as you see fit.
> #  -Omri
> #
>                 } else {
> #                   print "baz!! ";

By the time you're ready to release your code, you should have a
debugging mode available with _useful_ diagnostic messages.  Or you
should at least delete all these silly unwanted print statements.


>                     scramble_hex_eq_mode($sitename,@cookie,$outgoing);
>             
>                 }
> 
>             }
>         }
>         print TEMPFILE "$outgoing\n";
> 
> 
>     }
>     close(COOKIEFILE);
>     close(TEMPFILE);
>    system "mv -f $ENV{HOME}/.netscape/cookies.scrambled
> $ENV{HOME}/.netscape/cookies";

Again, something wrong with rename()?


> }
> 

> [other functions that are servicable enough]


Why is it that you insist on passing arguments to all your subroutines,
and yet you _never_ use them?  Instead, each one of your subroutines
ignores its arguments and uses global variables instead; extremely poor
design.  You sorely need to read perlsub, and perlvar for the definition
of @_.


Some of the bugs noted above make me question how thoroughly this code
was tested.


-- 
 _ / '  _      /       - aka -
( /)//)//)(//)/(   Ronald J Kimball      rjk@linguist.dartmouth.edu
    /                                http://www.tiac.net/users/chipmunk/
        "It's funny 'cause it's true ... and vice versa."


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

Date: Thu, 10 Jun 1999 00:49:13 GMT
From: rad91@my-deja.com
Subject: Emailing Binary Files
Message-Id: <7jn227$3mf$1@nnrp1.deja.com>

I'm interested in a module/technique I can use to email binary files.
I assume that I would first have to encode the file to base64.  Is that
correct?  How would I do that?  Your help would really be appreciated.

Email:  radiaz@us.oracle.com


Sent via Deja.com http://www.deja.com/
Share what you know. Learn what you don't.


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

Date: Wed, 9 Jun 1999 22:41:12 -0500
From: "AEF" <aef@pangea.ca>
Subject: How do I sort files in a dir by last modified time?
Message-Id: <7jnc3j$o1d$1@pumpkin.pangea.ca>

How do I sort files in a directory, on the last modified time, and print
that time out in a formated month, day , year?

Thanks.




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

Date: Thu, 10 Jun 1999 11:33:11 +0800
From: "CacheBoy" <chongsun@krdl.org.sg>
Subject: How to display background picture in cgi?
Message-Id: <7jnc4v$p6u$1@godzilla.krdl.org.sg>

I tried to generate a web page from my perl program but the background which
is a gif file did not show.
The path is correct




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

Date: Wed, 9 Jun 1999 22:45:43 -0400
From: rjk@linguist.dartmouth.edu (Ronald J Kimball)
Subject: Re: How to write TO a socket? (client/server socket stuff)
Message-Id: <1dt5k1u.175ijfw1jlwp7xN@p90.tc5.metro.ma.tiac.com>

RikTAIT <riktait@aol.com> wrote:

> Can someone give me some quick and dirty code, two programs:
> 1) server code that accepts connections on a port and then basically
>    prints to stdout out anything that is sent to it via the port? 
> 2) client code that connects to said port and writes a sentence to
>    that port and then exits
> 


#!/usr/local/bin/perl -w

# server.pl

use strict;

use IO::Socket;

my $port = $ARGV[0] || 12345;
my $sock =
    IO::Socket::INET->new(Listen => 1,
                          LocalPort => $port, Proto => 'tcp')
    or die "socket: $!\n";

my $client = $sock->accept();

while (<$client>) {
  print $_;
}

__END__


#!/usr/local/bin/perl -w

# client.pl

use IO::Socket;

my $port = $ARGV[0] || 12345;
my $sock = IO::Socket::INET->new("localhost:$port")
    or die "socket: $!\n";

print $sock "Hello world!\n";

__END__


-- 
 _ / '  _      /       - aka -
( /)//)//)(//)/(   Ronald J Kimball      rjk@linguist.dartmouth.edu
    /                                http://www.tiac.net/users/chipmunk/
        "It's funny 'cause it's true ... and vice versa."


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

Date: Thu, 10 Jun 1999 14:43:12 +1200
From: "Kath" <kath_m@2hotmail.com>
Subject: New to this - Help
Message-Id: <7jn8po$3d9fn$1@titan.xtra.co.nz>

I am running Apache Server 1.3 on Win NT using ActivePerl. I managed to get
Apache to give me the "it works" page and get some example cgi scripts
working. I have installed the DBI module but don't really know how is works.

How do I set up the ODBC drivers to use MS Foxpro databases?

Where can I find examples of code using databases?

How do I test to see if it is working?

Thanks
Kath
kath_m@hotmail.com





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

Date: Wed, 9 Jun 1999 22:45:44 -0400
From: rjk@linguist.dartmouth.edu (Ronald J Kimball)
Subject: Re: Problems sorting. I'm stupid and I'll die
Message-Id: <1dt5l1m.1rg5jma12nodlgN@p90.tc5.metro.ma.tiac.com>

Don Roby <droby@copyright.com> wrote:

> In article <MPG.11c8132ed2c30288989b9e@nntp.hpl.hp.com>,
>   lr@hpl.hp.com (Larry Rosler) wrote:
> >
> > The following Orcish-Maneuver sort works with Perl 4, which doesn't
> seem
> > to have an 'lc' function, or a 'split' function that I can make work,
> or
> > lots of other goodies in regexes that we take for granted.  Hence the
> > ugliness in the sortkey extraction.
> >
> 
> Odd.  I'm almost certain I used split & join in Perl 4.036 to deal with
> "records" stored as comma-separated values in a hash tied to a DBM file
> with good-old dbmopen.

perl4 has split() and join().  I bet Larry R. simply forgot the
parentheses around the arguments, which were not optional until perl5.

perl4 also has \U, \L, \u, and \l, but not uc(), lc(), ucfirst() or
lcfirst().  Go figure.

-- 
 _ / '  _      /       - aka -
( /)//)//)(//)/(   Ronald J Kimball      rjk@linguist.dartmouth.edu
    /                                http://www.tiac.net/users/chipmunk/
        perl -le 'print "Just another \u$^X hacker"'


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

Date: Thu, 10 Jun 1999 02:22:20 GMT
From: edk1@my-deja.com
Subject: Problems with 2GB RAM on Linux and libc's sbrk
Message-Id: <7jn7gj$5gk$1@nnrp1.deja.com>

Hi All,

I have a machine with kernel 2.2.7 compiled with PAGE_OFFSET set to
0x80000000 (in order to see 2GB RAM).  The problem is any 2.2.x kernel
compiled with this PAGE_OFFSET breaks sbrk, which is used by Perl to do
memory allocation.  In fact it craps out at about  580MB compared to the
970MB attainable with the stock PAGE_OFFSET.  I need it to be able to
come at least close to 2GB.  Standard C programs with malloc will use
the entire 2GB's.  My question is, is this a libc bug or a Kernel bug??
Does libc expect some kind of information that the kernel can't give
it?  Or is it just that libc's sbrk doesn't know what to do when there
is that much memory available in a Linux Kernel??  Has anyone got a fix
or a workaround for this?

Thanks, and please help, I have a perl program that will require a lot
of memory in order to do a time-sensitive task quickly.

Ed Kwon


Sent via Deja.com http://www.deja.com/
Share what you know. Learn what you don't.


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

Date: Thu, 10 Jun 1999 02:45:26 GMT
From: dalehend@flash.net
Subject: Re: Regexpr for loop to handle e-address list
Message-Id: <375f26d1.38627413@news.flash.net>



The Backslash acts as a delimiter to assign the quoted list to a
variable. The variable is for WebBBS.

On Wed, 9 Jun 1999 17:27:13 -0700, Tom Phoenix <rootbeer@redcat.com>
wrote:

>On Thu, 10 Jun 1999 dalehend@flash.net wrote:
>
>> Thanks for your feedback Tom. I did look at Mail::Address, but I do
>> not think it can handle the backslash delimiter that must be present
>> in each email address as a part of the list.
>
>This one?
>
>> >> $emaillist = "younme\@work.com shenhim\@work.com";
>
>There's no backslash in there. :-)  You _could_ have a backslash in a
>valid address, but I don't think that's what you meant.
>
>> I did find a regexpr that can parse the backslash delimiter leaving
>> just the email address and hope to find a happy medium somewhere.
>
>Does it correctly parse <"fred\\barney"@redcat.com>? And a few other
>variations on that... :-)
>
>-- 
>Tom Phoenix       Perl Training and Hacking       Esperanto
>Randal Schwartz Case:     http://www.rahul.net/jeffrey/ovs/
>



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

Date: Thu, 10 Jun 1999 02:34:38 GMT
From: jbell@263.net
Subject: run .exe on Win32
Message-Id: <7jn87u$5nf$1@nnrp1.deja.com>

Hi, all,

I'm trying to run a .exe program(a C program) from perl
with the "system" function.
This programs reads input from a data file in the same
directory.  Now I have two questions,
1. The perl program can be run only when it's in the same
   direcotry with the .exe program and the data file.
   How can I run the perl program from a different dir.
2. This program prints output to the screen.  In the perl
   program how can I store the output in a string or array?
3. Is there a more effective way to call this c program
   other than using "system"?

Thanks a lot!

---
Jim


Sent via Deja.com http://www.deja.com/
Share what you know. Learn what you don't.


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

Date: Wed, 9 Jun 1999 18:46:36 -0700
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: Separating array into alphabetical array of arrays
Message-Id: <MPG.11c8b8cf5efe9f5e989ba4@nntp.hpl.hp.com>

In article <slrn7ltqhu.bdg.dragons@dragons.duesouth.net> on Wed, 09 Jun 
1999 22:37:45 GMT, Matthew Bafford <dragons@dragons.duesouth.net> 
says...
 ...
> If it's sorted, just do something like ('like', in this case, meaning I
> didn't test it):

I'll say you didn't!

> my $last_letter = '';
> 
> for ( @lines ) {
>     next unless /^([a-zA-Z])/;
>     
>     if ( lc $1 ne $last_letter ) {
>         open OUT, "my_dir/$1" or
>             die "Couldn't open my_dir/$1: $!\n";          
>     }

It might be nicer to open the file for output or appending.
And to set $last_letter so this doesn't happen on every line.

>     print OUT;
> }    

 ...

-- 
(Just Another Larry) Rosler
Hewlett-Packard Company
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com


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

Date: Thu, 10 Jun 1999 03:37:48 GMT
From: dragons@dragons.duesouth.net (Matthew Bafford)
Subject: Re: Separating array into alphabetical array of arrays
Message-Id: <slrn7lubra.c38.dragons@dragons.duesouth.net>

On Wed, 9 Jun 1999 18:46:36 -0700, Larry Rosler <lr@hpl.hp.com>
posted the following after running a magnifying glass over every message:
: It might be nicer to open the file for output or appending.
: And to set $last_letter so this doesn't happen on every line.

Awwww, that's no fun.

--Matthew


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

Date: Wed, 9 Jun 1999 18:31:41 -0700
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: Sequently adding data to a hash with $x[x..x]???
Message-Id: <MPG.11c8b53a682c42c8989ba3@nntp.hpl.hp.com>

In article <7jmrh6$jau@cypress.nwnet.net> on 9 Jun 1999 15:57:42 -0700, 
Dean Hudson <deanh@nwnet.net> says...
 ...
>     /^[^,]+,[^,]+/g; 			# step past 1 & 2
>     while ( /([^,]+),([^,]+)/g ) {      # grab a pair
>         $hsh{$1} = $2;  		# assign to %hsh
>     }
 ...
> Note that it's stepping past the first two values with the first regex 
> and it's using /g to stay in the right spot on each line.

That is somewhat surprising.  I thought that every 'm//g' expression had 
its own value for the position iterator.  But evidently *identical* 
expressions share an interator, which means they are compiled into 
references to the same pattern.  (Though these aren't even identical, in 
that one is anchored and the other isn't, and one captures while the 
other doesn't.)

I can't find any documentation of this behavior in perlop or perlre.  Is 
my understanding correct, and is this the way one would expect it to 
work?

-- 
(Just Another Larry) Rosler
Hewlett-Packard Company
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com


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

Date: 09 Jun 1999 22:49:35 -0400
From: Uri Guttman <uri@sysarch.com>
Subject: Re: Sequently adding data to a hash with $x[x..x]???
Message-Id: <x7n1y84vnk.fsf@home.sysarch.com>

>>>>> "LR" == Larry Rosler <lr@hpl.hp.com> writes:

  >> Note that it's stepping past the first two values with the first regex 
  >> and it's using /g to stay in the right spot on each line.

  LR> That is somewhat surprising.  I thought that every 'm//g' expression had 
  LR> its own value for the position iterator.  But evidently *identical* 
  LR> expressions share an interator, which means they are compiled into 
  LR> references to the same pattern.  (Though these aren't even identical, in 
  LR> that one is anchored and the other isn't, and one captures while the 
  LR> other doesn't.)

the /g memory used to be tied to the regex (perl4) and in perl5 was
changed to be tied to the string being matched for this reason.

  LR> I can't find any documentation of this behavior in perlop or perlre.  Is 
  LR> my understanding correct, and is this the way one would expect it to 
  LR> work?

i found note in MRE, page 307, note 253 that verifies this. it should be
noted in the perldocs somewhere.

it is implied by the pos operator. since it can change where the /g will
match in a string, that attribute must be attached to the string and not
the regex. it should be made much clearer.

item pos

Returns the offset of where the last C<m//g> search left off for the variable
is in question ($_ is used when the variable is not specified).  May be
modified to change that offset.  Such modification will also influence
the C<\G> zero-width assertion in regular expressions.  See L<perlre> and
L<perlop>

uri, the researcher

-- 
Uri Guttman  -----------------  SYStems ARCHitecture and Software Engineering
uri@sysarch.com  ---------------------------  Perl, Internet, UNIX Consulting
Have Perl, Will Travel  -----------------------------  http://www.sysarch.com
The Best Search Engine on the Net -------------  http://www.northernlight.com


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

Date: Wed, 9 Jun 1999 17:24:12 -0400
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: Sequently adding data to a hash with $x[x..x]???
Message-Id: <s1mmj7.7n3.ln@magna.metronet.com>

Mats Pettersson (mats.pettersson@falukuriren.se) wrote:
: Tad McClellan wrote:
: > 
: > Mats Pettersson (mats.pettersson@falukuriren.se) wrote:
: > : Any ideas?
: > 
: >    What are your keys?
: > 
: >    What are your values?

: I have a file with several lines of data. Each line has numeric (integer) values separated by comma, as follows...

: vv,ll,kk,dd,kk,dd,kk,dd....(...and so on)

: ....where vv= some number (always first on the line),
:          ll = length of data (number of pairs of keys and values)
:          kk = key
:          dd = value

: The first two values of each line should NOT get in the %hash.

: Since there are several lines of data, i want to build a %hash and add data to it as i loop through the lines.

: Now, the problem is; if i (after an apropriate split, of course) do a "%hash = @line[2..5]", the previus line of data gets "lost" at each iteration through the loop.

: So, after the loop i end up with just the last line in the file, not a complete %hash of all the keys and values in the file put together.

: Is there somekind of operator like "+=" (tried it, doesn't work) i can use, or do i have to build a @scalar first and assign it to the %hash afterwards?

: Like i have it now, i use a for() loop to insert the keys and values, but it would be neat if there was a simpler way.


   Now I see. You _do_ want alternating key/value pairs.

   I didn't think that was it since you had an odd number of them.

   I see you now have an even number of them...



   You can put them into a temporary hash, and then use a 
   "hash slice" to copy them into the primary hash.

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

my %hash;
while (<DATA>) {
   chomp;
   my %tmp;
   (undef, undef, %tmp) = split /,/;
   @hash{keys %tmp} = values %tmp;
}

foreach (sort keys %hash) {
   print "$_  ==>  $hash{$_}\n";
}

__DATA__
vv,ll,k1,d1,k2,d2
vv,ll,k3,d3,k4,d4,k5,d5
-----------------------

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


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

Date: Wed, 9 Jun 1999 22:45:45 -0400
From: rjk@linguist.dartmouth.edu (Ronald J Kimball)
Subject: Re: Setting cookies with CGI.pm
Message-Id: <1dt5l94.8jw1hjpt8whfN@p90.tc5.metro.ma.tiac.com>

Paul Rubenis <paulr@tc.umn.edu> wrote:

>   You get the idea.  I can get the first set of keys, but nothing beyond
> this.  I have found no reference in the CGI.pm docs about limitations of
> the datastructures passed in as cookie values.  If anyone sees a glaring
> mistake on my part, I'd appreciate some feedback.  Thanks.

You cannot use nested data structures (i.e. array of arrays, hash of
hashes, etc.) as values for cookies with CGI.pm.  Only the first level
of the data structure will be encoded in the cookie.


-- 
 _ / '  _      /       - aka -
( /)//)//)(//)/(   Ronald J Kimball      rjk@linguist.dartmouth.edu
    /                                http://www.tiac.net/users/chipmunk/
        "It's funny 'cause it's true ... and vice versa."


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

Date: Thu, 10 Jun 1999 02:22:50 GMT
From: posting.account@lynxview.com (William Herrera)
Subject: Re: size of a subdirectory without readdir?
Message-Id: <375f203d.71532916@news.rmi.net>

On Wed, 9 Jun 1999 09:25:35 -0700, Tom Phoenix <rootbeer@redcat.com>
wrote:

>On Wed, 9 Jun 1999, William Herrera wrote:
>
>> Is there a better/faster way in Perl to count how many files are in a
>> subdirectory?

>I don't think there's a better/faster way anywhere, whether you're using
>Perl or some other language. 

so, it is just I/O bound, as almost always :(. 

I hope that people out there are working on faster file systems for
things like Linux. Linux, as you likely know, has been getting
thrashed in the network drive hosting benchmarks by the likes of
Solaris and NT lately.

I was hoping that there was a back door someone had put into a module,
something like an undocumented way of using seekdir/telldir...


---
The above from: address is spamblocked. Use wherrera (at) lynxview (dot) com for the reply address.


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

Date: Wed, 09 Jun 1999 19:43:27 -0700
From: Raj <technology@workmail.com>
Subject: System command
Message-Id: <375F264F.4054EE7@workmail.com>

Hi, I have another CGI/Perl issue.
In my CGI Script,

System("cp $file1 tmp.ext");

is not working for a valid $file1.permissions, dir, extensions are ok.
Its able to delete that file thru unlink but not a copy thru System
command. Any help please...!!? TIA,
Raj




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

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


Administrivia:

Well, after 6 months, here's the answer to the quiz: what do we do about
comp.lang.perl.moderated. Answer: nothing. 

]From: Russ Allbery <rra@stanford.edu>
]Date: 21 Sep 1998 19:53:43 -0700
]Subject: comp.lang.perl.moderated available via e-mail
]
]It is possible to subscribe to comp.lang.perl.moderated as a mailing list.
]To do so, send mail to majordomo@eyrie.org with "subscribe clpm" in the
]body.  Majordomo will then send you instructions on how to confirm your
]subscription.  This is provided as a general service for those people who
]cannot receive the newsgroup for whatever reason or who just prefer to
]receive messages via e-mail.

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.  

To submit articles to comp.lang.perl.misc (and this Digest), send your
article to perl-users@ruby.oce.orst.edu.

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.

The Meta-FAQ, an article containing information about the FAQ, is
available by requesting "send perl-users meta-faq". The real FAQ, as it
appeared last in the newsgroup, can be retrieved with the request "send
perl-users FAQ". Due to their sizes, neither the Meta-FAQ nor the FAQ
are included in the digest.

The "mini-FAQ", which is an updated version of the Meta-FAQ, is
available by requesting "send perl-users mini-faq". It appears twice
weekly in the group, but is not distributed in the digest.

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 V8 Issue 5940
**************************************

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