[17090] in Perl-Users-Digest
Perl-Users Digest, Issue: 4502 Volume: 9
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Oct 3 06:05:30 2000
Date: Tue, 3 Oct 2000 03:05:09 -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: <970567509-v9-i4502@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Tue, 3 Oct 2000 Volume: 9 Number: 4502
Today's topics:
Re: ?? wait for a browser response <anders@wall.alweb.dk>
Re: [Q] Greedy matching across multiples lines. <lr@hpl.hp.com>
Re: Add on kily@my-deja.com
Archive::Tar woes <johnno@nospam.casebook.org>
Automatically creating new virtual hosts using this scr suzbik@btinternet.com
Re: Automatically screwing up new virtual hosts using t <godzilla@stomp.stomp.tokyo>
Re: benefits of arrays over hashes(associative arrays) (Martien Verbruggen)
Re: benefits of arrays over hashes(associative arrays) <bart.lateur@skynet.be>
Re: Comparing Timestamps <lr@hpl.hp.com>
Re: converting \codes (Mark-Jason Dominus)
Re: converting \codes <elephant@squirrelgroup.com>
Re: converting \codes <lr@hpl.hp.com>
Re: Cookies <elephant@squirrelgroup.com>
Re: error in mapping array slice <r28629@email.sps.mot.com>
Re: Get the MAC address from an IP <metcher@spider.herston.uq.edu.au>
Hash of Arrays oddness? <pearce@aw.sgi.com>
Re: Hash of Arrays oddness? <anders@wall.alweb.dk>
Re: HELP method POST <kenneth@nospam.com>
Installing CPAN module on UNIX paul_a_long@my-deja.com
Integrating perl & C - newbie silverjets@my-deja.com
Re: Integrating perl & C - newbie (Brian Ingerson)
Re: Is this is Regexp bug? <glynFOOdwr@FSCKdeleteEmeD.co.uk>
Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Tue, 3 Oct 2000 09:23:11 +0200
From: Anders Lund <anders@wall.alweb.dk>
Subject: Re: ?? wait for a browser response
Message-Id: <zQfC5.2561$Qu1.168958@news000.worldonline.dk>
Steve A. wrote:
> Hi,
> The question is simple;
> " how do I make a perl CGI program wait for input from the
> browser, to take it's next action , prior to program termination"
> ?
> From a console I/O run application it's pretty simple;
> " $input = <STDIN>; # wait for keyboard input "
> " do something($input); # next line of code; "
>
> program waits for <stdin> input.
>
>
> Scenario:
> 1) browser calls " ...com/cgi-bin/Programme.pl ", using a standard
> "POST" method, sending user's login info,
>
> 2) " cgi-bin/Programme.pl " executes, sending response back to
> browser proper header and HTML code,
>
> 3) " cgi-bin/Programme.pl " goes into a "wait loop", waiting
> for next input from browser.
>
> Problem:
> a) I/O buffer does not flush.
> b) Browser does not get updated info before "wait loop" times-out
> and "Programme.pl" terminates.
> c) On "Programme.pl" termination I/O buffer is flushed, but,
> it's too late, ,, "Programme.pl" is dead.
>
> Solution ??
>
> Thanks,
> Steve A.
>
You need to search basic information on http and CGI.
This is how it works (using CGI, but you get the idear):
use CGI;
$q = new CGI;
print $q->header, $q->starthtml(-title=>'test');
# See if we got some input, do something if so
if ($q->param('peter') {
print "hello peter";
} else {
#otherwise, provide means to get some
print $q->startform, $q->submit(-name=>'peter', -value=>'hello'),
$q->endform;
}
print $q->endhtml;
-anders
--
[ the word wall - and the trailing dot - in my email address
is my _fire_wall - protecting me from the criminals abusing usenet]
------------------------------
Date: Mon, 2 Oct 2000 23:36:37 -0700
From: Larry Rosler <lr@hpl.hp.com>
Subject: Re: [Q] Greedy matching across multiples lines.
Message-Id: <MPG.14431e5184816d5c98adf9@nntp.hpl.hp.com>
In article <x7g0me64k7.fsf@home.sysarch.com>, uri@sysarch.com says...
> >>>>> "AP" == Anshuman Pandey <apandey@u.washington.edu> writes:
>
> AP> {\mac apple banana orange pear guava kiwi grape{a} mango pear}
> AP> {\mac apple banana orange pear guava kiwi grape{a} mango
> AP> pear}
...
> when reading with <> you only get one line at a time so you have to
> figure out that you need to read in the next line and append it to $_.
>
> that can be done many ways but you have to specify how you detect short
> lines so you can read the next one.
In all likelihood, the easiest solution here is to set
{ local $/ = "}\n";
to read the records, and then to make sure that any regex that includes
'.' has the /s modifier set, to match across any embedded newlines.
But those 'grape{a}' things had better not be followed immediately by
newlines.
--
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com
------------------------------
Date: Tue, 03 Oct 2000 08:14:57 GMT
From: kily@my-deja.com
Subject: Re: Add on
Message-Id: <8rc4i0$95r$1@nnrp1.deja.com>
In article <u9aecngnrk.fsf@wcl-l.bham.ac.uk>,
nobull@mail.com wrote:
> kily@my-deja.com writes:
>
> > Subject: Add on
>
> Huh? Nonsense subject line!
>
> > I'm wondering for a script which can read a file
> > containing two columns seperated by unknown number of tabulation or
> > space, then delete the first column (which is a complete name of
> > unsers). The second column is the user-ID as: 008253A,
008256X,...etc.
> > I want script to be able to delete the first two charecters and
> > transform majuscule (A, X, B,...etc) to minuscules ones.
>
> perl -pe 's/.*\s+..(.*)/\L$1/' <infile >outfile
>
> > PS: I'm workong under Windows NT Server 4.
>
> Oh, then command line may not work:
>
> #!perl -p
> s/.*\s+..(.*)/\L$1/
>
Thank you all for helps, I'm testing the line:
perl -pe 's/.*\s+..(.*)/\L$1/' <infile >outfile
it works fine. But how I can put it in file in which I put in and out
files.
Thanks and excuse me!
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: Tue, 3 Oct 2000 19:43:09 +1000
From: "Johnno" <johnno@nospam.casebook.org>
Subject: Archive::Tar woes
Message-Id: <39d99c8c$0$12441$7f31c96c@news01.syd.optusnet.com.au>
I am experiencing what seems to be a problem (or perhaps an oversight on my
part) with the Archive::Tar module.
I am hoping someone here has used Archive::Tar and may be able to explain the
problem I am seeing, or correct my oversight -- whichever applies.
In the code I have written below, I am rolling my home directory (and
everything contained therein) into a tarball.
In other words, I am doing "tar -cvpf /tmp/johnno.tar /home/johnno/".
#!/usr/bin/perl -w
use strict;
use Archive::Tar;
my $backup = '/tmp/johnno.tar';
my @files = qw(/home/johnno/);
my $tarball = Archive::Tar->new();
$tarball->create_archive($backup, 9, @files);
$tarball->add_files(@files);
$tarball->write($backup);
The problem seems to be in the processing of @files. The tarball was
created, but not as I would have expected:
$ tar -tf /tmp/johnno.tar
tar: Record size = 3 blocks
/home/johnno
tar: Unexpected EOF in archive
tar: Error is not recoverable: exiting now
In the next code snippet, I have changed the contents of @files so that it
contains two specific files rather than a "directory".
#!/usr/bin/perl -w
use strict;
use Archive::Tar;
my $backup = '/tmp/johnno.tar';
my @files = qw(/home/johnno/.bashrc /etc/passwd);
my $tarball = Archive::Tar->new();
$tarball->create_archive($backup, 9, @files);
$tarball->add_files(@files);
$tarball->write($backup);
In this case, the two files in @files are added to the tarball successfully:
$ tar -tf /tmp/johnno.tar
tar: Record size = 6 blocks
/home/johnno/.bashrc
/etc/passwd
I also changed @files so that it contained a directory and a regular file:
my @files = qw(/home/johnno/ /etc/passwd);
No luck there either:
$ tar -tf johnno.tar
tar: Record size = 5 blocks
/home/johnno/
tar: Unexpected EOF in archive
tar: Error is not recoverable: exiting now
It appears that directory names stored in @files pose as a problem.
Archive::Tar seemingly does not behave the way tar itself would behave when
run as "tar -cvpf /home/johnno".
Has anyone experienced this before?
Am I missing something, or is this a genuine problem with Archive::Tar?
I am running Perl 5.00503 and Archive::Tar 0.22.
--
Johnno (johnno@nospam.casebook.org)
http://johnno.casebook.org
------------------------------
Date: Tue, 03 Oct 2000 06:42:20 GMT
From: suzbik@btinternet.com
Subject: Automatically creating new virtual hosts using this script?
Message-Id: <8rbv4c$4m8$1@nnrp1.deja.com>
Hi,
I have set up Apache and all the rest on my computer and it is working
fine. I decided I would try and write a script that would enable me to
automatically add new virtual domains. However it doesnt work. If i
check the error log it says: [Mon Oct 02 18:52:05 2000] [error] [client
127.0.0.1] (2)No such file or directory: couldn't spawn child process:
c:/phpdev/www/cgi-bin/virtual.pl
can someone have a look and tell me whats wrong?
thanks a lot
Ben Periton
Here is the code:
#!c:/phpdev/perl/perl.exe
# Path to the windows file (again, no trailing slash!)
$hdd = "C:/win98";
# The URL that the script will be run from
$url = "http://www.cystrix.co.uk/cgi-bin/virtual.pl";
########################################################################
########
# Do not edit below this line!! (unless you know wot u
doin!) #
########################################################################
########
read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
@pairs = split(/&/,$buffer);
foreach $pair(@pairs) {
($name, $value) = split(/=/,$pair);
$value =~ tr/+/ /;
$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
$FORM{$name} = $value;
}
$command = $FORM{'command'};
$domain = $FORM{'domain'};
$server = $FORM{'server'};
$ip = $FORM{'ip'};
if($command eq "create"){
&record;
}
sub virtual{
open (VIRTUAL, ">>C:/phpdev/apache/conf/httpd.conf") || die "Whoopsy
Doodle! I can't open the file: $!";
print VIRTUAL "<VirtualHost $ip>\n";
print VIRTUAL "ServerName $server.$domain\n";
print VIRTUAL "DocumentRoot $base/$server\n";
print VIRTUAL "</VirtualHost>\n\n";
close(VIRTUAL);
&hosts;
}
sub hosts{
open(HOSTS, ">>$hdd/hosts") || die "Whoopsy Doodle! I can't open the
file: $!";
print HOSTS "$ip\t$server.$domain\n";
close(HOSTS);
&directory;
}
sub directory{
mkdir("C:/phpdev/www/$server") || die "Whoopsy Doodle! I can't make the
dir: $!";
&record;
}
sub record{
open (LIST, ">>C:/phpdev/apache/virtual.list") || die "Whoopsy Doodle!
I can't open the file: $!";
print LIST "<tr>\n";
print LIST "<td><font face="Arial" size="2"
color="#800000">$ip</font></td>\n"; print LIST "<td><font face="Arial"
size="2" color="#800000">$server</font></td>\n"; print LIST "<td><font
face="Arial" size="2" color="#800000">$domain</font></td>\n"; print
LIST "<td><font face="Arial" size="2" color="#800000">$base/
$server/</font></td>\n"; print LIST "</tr>\n";
close(LIST);
&complete;
}
sub complete{
print qq~
<html>
<head>
<title>Proggie to add new virtual hosts</title>
</head>
<body>
<font face="Arial" size="2">
The following has been added:<br><br>
$server $domain $ip $base/$server
</font>
</body>
</html>
~;
}
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: Tue, 03 Oct 2000 02:09:46 -0700
From: "Godzilla!" <godzilla@stomp.stomp.tokyo>
Subject: Re: Automatically screwing up new virtual hosts using this script?
Message-Id: <39D9A25A.F68B4DD8@stomp.stomp.tokyo>
suzbik@btinternet.com wrote:
(snippage)
Did you know btinternet is amongst the top
providers servicing the worst of spammers?
After I finished with their server, they
made dog gone sure our family mailbox never
receives another piece of porno mail, or any
mail, from them or any of their subsidiaries.
I was technologically less than kind being
annoyed by their ignoring my first few firm
but fair requests to stop their clients from
spamming our family with porno mail.
> ... check the error log it says:
> [Mon Oct 02 18:52:05 2000] [FUBAR] [CRASH & BURN]
If I give you two hints will you stop posting
this question, repeatedly?
This is a major hint:
> Do not edit below this line!! (unless you know wot u doin!)
This is a minor hint:
> sub virtual
Godzilla!
--
Dr. Kiralynne Schilitubi ¦ Cooling Fan Specialist
UofD: University of Duh! ¦ ENIAC Hard Wiring Pro
BumScrew, South of Egypt ¦ HTML Programming Class
------------------------------
Date: Tue, 3 Oct 2000 16:10:30 +1100
From: mgjv@tradingpost.com.au (Martien Verbruggen)
Subject: Re: benefits of arrays over hashes(associative arrays) and vice versa
Message-Id: <slrn8tiqi6.jr6.mgjv@martien.heliotrope.home>
On 2 Oct 2000 20:54:00 -0500,
Logan Shaw <logan@cs.utexas.edu> wrote:
> In article <slrn8tia3g.jr6.mgjv@martien.heliotrope.home>,
> Martien Verbruggen <mgjv@tradingpost.com.au> wrote:
> >On 2 Oct 2000 17:52:54 -0500,
> > Logan Shaw <logan@cs.utexas.edu> wrote:
> >>
> >> However, it takes more memory, more gymnastics, and more cheating.
> >> (Cheating because if the indices to the array weren't guaranteed to be
> >> between 0 and 255, I could end up using *lots* of memory, or I might
> >
> >$ perldoc perlunicode
>
> I did, but it didn't say anything about anyone writing HTML in
> Unicode.
>
> Plus, I said I was cheating, didn't I?
Yes, you did :)
My point was more that the indeices of your array are _not_ guaranteed
to be between 0 and 255, even though they will be in most cases. Of
course, it is possible that you meant that in the first place with the
cheating, and were aware of this, and I am still just misreading it.
If so, ignore me.
Martien
--
Martien Verbruggen |
Interactive Media Division | The world is complex; sendmail.cf
Commercial Dynamics Pty. Ltd. | reflects this.
NSW, Australia |
------------------------------
Date: Tue, 03 Oct 2000 09:46:07 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: benefits of arrays over hashes(associative arrays) and vice versa
Message-Id: <skajtsoud4qp2vu9ereg37uhe9m4af4jp6@4ax.com>
Logan Shaw wrote:
>If it needs to be more efficient, I can re-write it pretty easily to do
>a binary search instead of a linear search.
Now imagine an object that not only keeps the data, but does the lookup
transparently for you, for example through binary search. Gee, I think
I've just given the definition for a hash.
--
Bart.
------------------------------
Date: Mon, 2 Oct 2000 23:26:03 -0700
From: Larry Rosler <lr@hpl.hp.com>
Subject: Re: Comparing Timestamps
Message-Id: <MPG.14431bd044d2b3bc98adf8@nntp.hpl.hp.com>
In article <8rb7oa$j17$1@nnrp1.deja.com>, rathmore@tierceron.com says...
> My problem:
>
> I want to search a directory for files that are more than 7 days old
> and do somthing to them.
>
> The code I wrote to do this is completely wrong which shows how lost I
> am on this one, but it is worth looking at to get a better feel for
> where I left the path of good Perl programming so I'll include it below.
>
> Any suggestions/help would be greatly appreciated!
Martien Verbruggen has posted a thorough presentation of an approach to
this problem. I would just point out that simply removing five
characters from your solution would produce working code!
> use strict;
This is good, but enabling warnings would actually have pointed out the
real problem.
If 'strict' is really in effect, how do you get away with all these
undeclared variables?
> $dirname = 'c:/Documents/LA/';
> $SECONDS_PER_DAY = 60 * 60 * 24;
> $today = localtime;
That is the bug. The function 'localtime' in scalar context converts
the current epoch time into a string. What you want here is just 'time'
-- five characters fewer.
> opendir (DIR,$dirname) or die "can't opendir $dirname: $!";
>
> foreach $sourcefile (@sourcefile) {
> ($modify) = (stat($sourcefile))[9];
> my $compare = ($modify + (7 * $SECONDS_PER_DAY));
> if ($compare <= $today) {
Above is where the warning would have shown up.
> # Do something here
> }
> }
--
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com
------------------------------
Date: Tue, 03 Oct 2000 03:56:01 GMT
From: mjd@plover.com (Mark-Jason Dominus)
Subject: Re: converting \codes
Message-Id: <39d97e19.2b52$3e1@news.op.net>
In article <8rbeef$nss$1@samba.rahul.net>,
Lloyd Lim <Lloyd_Lim@mail.limunltd.com> wrote:
>I'd like to be able to process \t, \n, \r, ..., \033, \x1B, \c[
>in a string and substitute the appropriate characters just like
>Perl does. I'd also prefer avoiding eval, if possible.
>
>I could easily do the tab, newline, etc. substitutions with
>individual s/// statements,
That's pretty much what you'regoing to have to do.
>I couldn't figure out a way to do the octal, hex, and control
>substitutions without tons of code.
You might want something like this:
s/\\c(.)/chr(ord($1) ^ 64)/ge; # control characters
s/\\x([0-9A-Fa-f]{1,2})/chr(hex($1))/ge; # hex escapes
s/\\([0-7]+)/chr(oct($1))/ge; # octal escapes
Now, this isn't quite right for several reasons. Probably the most
important is that it performs multiple passes, so that if you're translating
'\x5CcT'
it first replaces \x5C with \ to get '\cT' and then turns \cT into
control-T. But Perl would have produced he three-character string
'\cT', not a control-T. But it does show a decent first approximation
that does not use 'tons of code'.
>I tried using the qq operator to do the interpolation but that
>didn't work.
No, because qq does only *one* level of interpolation, so that if $foo
contains '\cT', qq{$foo} becomes '\cT'.
There really should be a built-in 'interpolate' function, that
evaluates its argument *as if* it were being interpolated into a
double-quoted string.
------------------------------
Date: Tue, 3 Oct 2000 17:37:53 +1000
From: jason <elephant@squirrelgroup.com>
Subject: Re: converting \codes
Message-Id: <MPG.144437d9d6b504f49897e5@localhost>
Lloyd Lim wrote ..
>I'd like to be able to process \t, \n, \r, ..., \033, \x1B, \c[
>in a string and substitute the appropriate characters just like
>Perl does. I'd also prefer avoiding eval, if possible.
>
>I could easily do the tab, newline, etc. substitutions with
>individual s/// statements, but I couldn't figure out a way
>to do the octal, hex, and control substitutions without tons
>of code.
I'm not sure why you want to avoid eval .. but if it's for safety
(because you're unsure of your inputs here) then the following are safe
(although they still use a type of eval)
s/\\(\d{3})/chr(oct($1))/e; # octal
s/\\x([0-9a-f]{2})/chr(hex($1))/e; # hex
now for control characters .. I really don't know
>I tried using the qq operator to do the interpolation but that
>didn't work.
qq will not work without the eval
--
jason -- elephant@squirrelgroup.com --
------------------------------
Date: Tue, 3 Oct 2000 00:51:56 -0700
From: Larry Rosler <lr@hpl.hp.com>
Subject: Re: converting \codes
Message-Id: <MPG.14432ff39f89110098adfa@nntp.hpl.hp.com>
In article <8rbeef$nss$1@samba.rahul.net>, Lloyd_Lim@mail.limunltd.com
says...
> I'd like to be able to process \t, \n, \r, ..., \033, \x1B, \c[
> in a string and substitute the appropriate characters just like
> Perl does. I'd also prefer avoiding eval, if possible.
OK, except for a fancy initialization that could be done explicitly
without it.
> I could easily do the tab, newline, etc. substitutions with
> individual s/// statements, but I couldn't figure out a way
> to do the octal, hex, and control substitutions without tons
> of code.
Hardly. See below.
> I tried using the qq operator to do the interpolation but that
> didn't work.
It works for me.
#!/usr/bin/perl -wl
use strict;
$_ = '\t \n \r \033 \x1B \c[';
my %escapes = map { $_ => eval qq("\\$_") } qw( a e f n r t );
s{\\( 0[0-7]{0,3} | x([\da-fA-F]{1,2}) | c(.) | [aefnrt] ) }
{ my $x = substr $1, 0, 1;
$x eq '0' ? chr oct $1 :
$x eq 'x' ? chr hex $2 :
$x eq 'c' ? chr ord $3 & "\x1F" :
$escapes{$1} }egx;
print unpack 'H*' => $_;
--
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com
------------------------------
Date: Tue, 3 Oct 2000 15:31:36 +1000
From: jason <elephant@squirrelgroup.com>
Subject: Re: Cookies
Message-Id: <MPG.14441a44e2deec139897e4@localhost>
malatov@my-deja.com wrote ..
>I am attempting to post data to a form in perl.
>Every time I sucessfully post the data, I get an
>error page that says "It appears that cookies
>have been turned off on your browswer, please
>change your broswer to allow cookies, and try
>again once you are done." How can I change my
>script to allow the cookie to be acepted once I
>have posted the data?? I atempted to add some
>cookie stuff in there, but I failed :(
cookies rely on the user's client to work .. if the user wants to they
can configure their client not to allow cookies to work .. there's
nothing that you can do in Perl to override this (thank God)
--
jason -- elephant@squirrelgroup.com --
------------------------------
Date: Tue, 03 Oct 2000 15:21:16 +0800
From: Tk Soh <r28629@email.sps.mot.com>
Subject: Re: error in mapping array slice
Message-Id: <39D988EC.FBF51F64@email.sps.mot.com>
array slicing with non-existing subscripts produces list of undef's. Why
puzzles me is why it bombed when this list (of undef's ) was passed to
map {$_}, since it simply pass on the value (i.e. undef) as is, with no
attempt to modify it. Unless there are undocument feature that I am not
aware of, or missed. The fact that $_ is reference to the array elements
doesn't justify for that error, IMHO.
-TK
Jim Mauldin wrote:
>
> Tk Soh wrote:
> >
> > Just run into something strange about array slice. Wonder if anyone can
> > point out where/what I am missing here.
> >
> > try.pl:
> > -------
> > @a = 1..5; # line 1
> > @b = map {$_} @a[-10 .. -1]; # line 2
> >
> > The error msg:
> > -------------
> > Modification of non-creatable array value attempted, subscript -10 at
> > try.pl line 2.
> >
>
> From "Programming Perl", Chapter 33: Diagnostic Messages
>
> You tried to make an array value spring into existence,
> and the subscript was probably negative, even counting
> from the end of the array backward.
>
> Fairly obvious, I should think.
>
> -- Jim
------------------------------
Date: Tue, 03 Oct 2000 17:40:39 +1000
From: Jaime Metcher <metcher@spider.herston.uq.edu.au>
Subject: Re: Get the MAC address from an IP
Message-Id: <39D98D77.8172CB71@spider.herston.uq.edu.au>
In Windows you can do
print `nbtstat -A 203.46.53.70` =~ /MAC Address = ([0-9A-F\-]*)/;
Jaime Metcher
Malcolm Dew-Jones wrote:
>
> Mike Mesarch (mmesarch@wcom.net) wrote:
> : Is their a way to get a MAC address associated with an IP address?
> : -Mike
>
> arp - I have no idea if there's a perl module to do this.
>
> --
------------------------------
Date: Tue, 03 Oct 2000 02:36:27 -0400
From: Andrew Pearce <pearce@aw.sgi.com>
Subject: Hash of Arrays oddness?
Message-Id: <39D97E6A.5E7C1C31@aw.sgi.com>
--------------FED30AC2ADA2225E66D960F3
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
Didn't see this in the FAQ, and can't find a mention in any reference,
so I appologize if it is painfully obvious.
I have a hash and one element is to be an array. As I construct it, I'm using
the push() call as recommended;
# NOTE: exists( $hash{$key}) == 0
@array = makeArrayFunc();
foreach $ae (@array) {
push (@{$hash{$key}}, $ae);
}
Which mostly works, but it is dropping the first element. If I do the following,
it works:
# length( $hash{$key}) == 0, i.e. it does not yet exist
@array = makeArray();
foreach $ae (@array) {
push (@{$hash{$key}}, $ae);
if ($ae eq $array[0]) {
push (@{$hash{$key}}, $ae);
}
}
The first push is creating the array reference, but it is not placing the value
$ae in the array
as it would if the first argument to push were a non-existant array. Have I
encountered a bug
with the PERL implementation I have or am I missing something obvious here?
Thanks for your
time.
--
| Andrew Pearce |
| Alias|Wavefront | pearce@aw.sgi.com appearce@yahoo.com |
| Watch your computer's dreams: www.aliaswavefront.com/screensaver |
--------------FED30AC2ADA2225E66D960F3
Content-Type: text/html; charset=us-ascii
Content-Transfer-Encoding: 7bit
<!doctype html public "-//w3c//dtd html 4.0 transitional//en">
<html>
Didn't see this in the FAQ, and can't find a mention in any reference,
<br>so I appologize if it is painfully obvious.
<p>I have a hash and one element is to be an array. As I construct it,
I'm using
<br>the push() call as recommended;
<p>
# NOTE: exists( $hash{$key}) == 0
<br>
@array = makeArrayFunc();
<br>
foreach $ae (@array) {
<br>
push (@{$hash{$key}}, $ae);
<br>
}
<p>Which mostly works, but it is dropping the first element. If I do the
following, it works:
<p>
# length( $hash{$key}) == 0, i.e. it does not yet exist
<br>
@array = makeArray();
<br>
foreach $ae (@array) {
<br>
push (@{$hash{$key}}, $ae);
<br>
if ($ae eq $array[0]) {
<br>
push (@{$hash{$key}}, $ae);
<br>
}
<br>
}
<p>The first push is creating the array reference, but it is not placing
the value $ae in the array
<br>as it would if the first argument to push were a non-existant array.
Have I encountered a bug
<br>with the PERL implementation I have or am I missing something
obvious here? Thanks for your
<br>time.
<pre>--
| Andrew Pearce |
| Alias|Wavefront | pearce@aw.sgi.com appearce@yahoo.com |
| Watch your computer's dreams: www.aliaswavefront.com/screensaver |</pre>
</html>
--------------FED30AC2ADA2225E66D960F3--
------------------------------
Date: Tue, 3 Oct 2000 09:32:51 +0200
From: Anders Lund <anders@wall.alweb.dk>
Subject: Re: Hash of Arrays oddness?
Message-Id: <EZfC5.735$QP.59588@news010.worldonline.dk>
Andrew Pearce wrote:
> Didn't see this in the FAQ, and can't find a mention in any reference,
> so I appologize if it is painfully obvious.
>
> I have a hash and one element is to be an array. As I construct it, I'm
> using the push() call as recommended;
>
> # NOTE: exists( $hash{$key}) == 0
> @array = makeArrayFunc();
> foreach $ae (@array) {
> push (@{$hash{$key}}, $ae);
> }
>
> Which mostly works, but it is dropping the first element. If I do the
> following, it works:
>
> # length( $hash{$key}) == 0, i.e. it does not yet exist
> @array = makeArray();
> foreach $ae (@array) {
> push (@{$hash{$key}}, $ae);
> if ($ae eq $array[0]) {
> push (@{$hash{$key}}, $ae);
> }
> }
>
> The first push is creating the array reference, but it is not placing the
> value $ae in the array
> as it would if the first argument to push were a non-existant array. Have
> I encountered a bug
> with the PERL implementation I have or am I missing something obvious
> here? Thanks for your
> time.
>
@ary = (1,2,3);
$hash{somekey} = \@ary;
read perldoc perlref
-anders
--
[ the word wall - and the trailing dot - in my email address
is my _fire_wall - protecting me from the criminals abusing usenet]
------------------------------
Date: Tue, 03 Oct 2000 06:45:10 GMT
From: "uboat man" <kenneth@nospam.com>
Subject: Re: HELP method POST
Message-Id: <WffC5.27204$g6.11634827@news2.rdc2.tx.home.com>
About a month ago someone wrote about having trouble posting to eBay, his
code seemed correct, but he was getting a 501 Not Implemented error back
from eBay. I'm trying to do the same thing, and running into th same
problem. Does anyone have any clue how to do this? Thanks!
Kenneth
PS I can repost the original message if necessary
<tmac@transport.com> wrote in message
news:39D904F2.D26B5D1B@transport.com...
> Sounds like a perl question to me:-). Maybe http, but not html.
>
> Here is an example of what I would do. If you don't have LWP installed
> get it!
>
> use LWP::UserAgent;
>
> $body = 'var1=$val1&var2=$val2"';
> $ua = new LWP::UserAgent;
> $header = new HTTP::Headers(Content-type =>
> 'application/x-www-form-urlencoded');
> $url = new URI::URL('www.url.com/cgi-bin/myprog.cgi');
> $request = new HTTP::Request('POST', $url, $header, $body);
> $response = $ua->request($request);
> if ($response->is_success) {
> $response_content = $response->content;
> }
> else {
> $error_message = $response->message;
> }
> exit;
>
> Peace,
> Tim McIntyre
>
> cmf2000@my-deja.com wrote:
>
> > How i can call any URL from a script and pass variables.
> >
> > For example in method GET
> >
> > print "location:www.domain.com/script.pl?var=content&var2=content2
> >
> > but in method POST?
> >
> > Thank
> >
> > Pardon my poor english
> >
> > Sent via Deja.com http://www.deja.com/
> > Before you buy.
>
>
>
------------------------------
Date: Tue, 03 Oct 2000 09:01:29 GMT
From: paul_a_long@my-deja.com
Subject: Installing CPAN module on UNIX
Message-Id: <8rc797$arp$1@nnrp1.deja.com>
Hi,
I have run into a little problem with the development of my Perl server
application. I am writing it on my own machine (Win32) and I
periodically upload the latest version to my Web Hosting server
somewhere out there on the Internet.
However, I came across a problem with the Date::Calc module. This
requires some 'C' libraries to be installed on the UNIX machine I am
uploading to, therefore the installation isn't immediately straight
forward (at least for me!)
I understand that I must install this module in my own local area. No
problem. I have a couple of faithful O'Reilly books and access to the
module documentation and obviously www.perl.com.
After uploading the Date-Calc-4.3.tar.gz file to a particular directory
on the UNIX server, I then carry out the follow operations from the
directory created after running 'gzip' and 'tar':
% perl Makefile.PL PREFIX=/usr/home99/myhomename/modules
% make
% make test
Each of these operations work fine. Unfortunately, the last line I
execute fails:
% make install
It returns a 'You do not have permissions to install into
/usr/local/bin...' message.
Now, I certainly believe that I do not have privileges to install in the
directories it lists but how can I change any particular part of the
installation process to ensure that the module gets installed in the
correct location - my allocated area?
I thought the PREFIX statement was all I needed. Is there anything else?
Unfortunately, my UNIX skills are a little rusty. Any help would be much
appreciated.
Thanks,
Paul Long.
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: Tue, 03 Oct 2000 03:55:34 GMT
From: silverjets@my-deja.com
Subject: Integrating perl & C - newbie
Message-Id: <8rblbl$tli$1@nnrp1.deja.com>
I have the camel book and read the chapter on extending and embedding
Perl. Perhaps I missed something, and if I did could someone point me
to the relavent docs in the faq or the book. I am wondering about the
ability to pass data structures back and forth. For instance if I had a
perl program that is used to access a C program, could I pass a hash or
array from the perl program to the C program, work on it, and then pass
the structure back? Can this be done by simply passing the structure
itself, or do I need an intermediary step like writing the hash data out
to a file then reading that in with C? Or is this what an XSUB is for?
Any help in sorting this out is greatly appreciated.
John
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: 3 Oct 2000 08:48:26 +0200
From: brian@ingerson.com (Brian Ingerson)
Subject: Re: Integrating perl & C - newbie
Message-Id: <39D98178.24C96358@ingerson.com>
There's more than one way to do it. Since you're a newbie I'd suggest
giving Inline.pm a try. It's the fastest and most painless way to get
started in mixing Perl w/ C. You start with the examples and build from
there.
> I have the camel book and read the chapter on extending and embedding
> Perl. Perhaps I missed something, and if I did could someone point me
> to the relavent docs in the faq or the book.
Unfortunately, Inline postdates Camel 3.
> I am wondering about the
> ability to pass data structures back and forth. For instance if I had a
> perl program that is used to access a C program, could I pass a hash or
> array from the perl program to the C program, work on it, and then pass
> the structure back?
Example #7 in the Inline::C::Tutorial doc, shows how to pass a hash ref
to a C function and operate on it. You're going to need to know the Perl
internal api. See 'perldoc perlapi' (in v5.6.0+) Once you learn the api
its pretty simple.
http://search.cpan.org/doc/INGY/Inline-0.26/lib/Inline/C/Tutorial.pod
--
Brian Ingerson
INGY@cpan.org
perl -le 'print jaxh("Perl");use Inline C=>q|SV*jaxh(char*x){return
newSVpvf("Just Another %s Hacker",x);}|'
--
Posted from doyle.epixtech.com [205.163.221.7]
via Mailgate.ORG Server - http://www.Mailgate.ORG
------------------------------
Date: Tue, 3 Oct 2000 08:33:11 +0100
From: "Glyndwr" <glynFOOdwr@FSCKdeleteEmeD.co.uk>
Subject: Re: Is this is Regexp bug?
Message-Id: <0XfC5.10109$uq5.187916@news6-win.server.ntlworld.com>
<johnclyman@my-deja.com> wrote in message
news:8rasr7$9bg$1@nnrp1.deja.com...
> It seems as if the '\-' in the character class is
> causing your particular interpreter to choke.
> When I need to include a hyphen in a character
> class I always make it the first entry; you might
> try something like this and see if it works:
>
> [-a-zA-Z0-9.]
I'll try that, thanks.
> Also, you should be aware that this regex will
> reject some perfectly legal e-mail addresses such
> as those including underscores (in my experience
> firstname_lastname@company.com is a fairly common
> address format). There are probably other
> legitimate characters as well -- you might want
> to check the appropriate RFC to be sure.
Whoopsie; good point. Thanks again!
--
-=G=-
print join " ",reverse split /\s+/,'hacker. Perl another Just',"\n";
Web: http://www.fscked.co.uk ICQ: 66545073
------------------------------
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 4502
**************************************