[17044] in Perl-Users-Digest
Perl-Users Digest, Issue: 4456 Volume: 9
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Sep 28 09:05:34 2000
Date: Thu, 28 Sep 2000 06:05:15 -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: <970146314-v9-i4456@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Thu, 28 Sep 2000 Volume: 9 Number: 4456
Today's topics:
Re: [IGNORE - OFF TOPIC] Re: Controlling line length re <nico@monnet.to>
[Q] Sorting an array of arrays of references (Wolfgang Schauer)
Re: accessing global variables in another perl module <jasoniversen@my-deja.com>
Re: accessing global variables in another perl module (Garry Williams)
Re: ASAP: How $SCALAR = $LIST nobull@mail.com
attachment not in body of email <hugo@fractalgraphics.com.au>
Re: Candidate for the top ten perl mistakes list <bart.lateur@skynet.be>
Re: Candidate for the top ten perl mistakes list mexicanmeatballs@my-deja.com
CGI to CGI question <Seiu@DesertLINC.com>
Controlling a Serial Port korthner@inf.furukawa.co.jp
Re: Controlling a Serial Port <ebohlman@enteract.com>
Re: Controlling a Serial Port korthner@inf.furukawa.co.jp
Re: dereferencing an array from within a hash value nobull@mail.com
Re: File::Find problem nobull@mail.com
Re: foreach two elements at a time? <bart.lateur@skynet.be>
Hash of Hashes Problem kevin_mcfarlane@my-deja.com
Re: Hash of Hashes Problem ebohlman@omsdev.com
Re: Hash of Hashes Problem ebohlman@omsdev.com
Help needed to copy files <janekj@online.ee>
Re: How can I combine regular expressions? (Philip Lees)
Re: How can I combine regular expressions? (Philip Lees)
Re: how to share vars at runtime from a safe comparteme nobull@mail.com
HTTP::Response when client dies <jwollner@earthlink.net>
Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Thu, 28 Sep 2000 10:43:40 +0100
From: "Nicolas MONNET" <nico@monnet.to>
Subject: Re: [IGNORE - OFF TOPIC] Re: Controlling line length read by <>
Message-Id: <zDDA5.132$S3.4631@tengri.easynet.fr>
What the fuck was Uri Guttman <uri@sysarch.com> trying to say:
> so go away already. how many times do you have to be told?
Please, please, please ... Could we start a gun-control thread
instead? Oh wait, even better: an abortion thread.
--
perl -e 'print `echo Just a Lame Perl Luser | gzip -9 | cat | gzip -cd`'
------------------------------
Date: 28 Sep 2000 12:52:51 GMT
From: w-s@gmx.de (Wolfgang Schauer)
Subject: [Q] Sorting an array of arrays of references
Message-Id: <8qvev3$gfpe9$1@fu-berlin.de>
Hi there,
as you might know the DBI-method fetchall_arrayref returns
a reference to an array of arrays of references to each row
of data.
The example below prints all data from an SQL statement
row by row.
I fruitlessly tried to sort the rows numerically ascending
depending on a specific field like
@array = sort {$a <=> $b} $table->[2];
which I hoped would sort the rows depending on the third column,
but didn't do so.
Any help on how to do this is highly appreciated.
Regards,
Wolfgang
------------- snip -------------
my $table = $sth->fetchall_arrayref
or die "$sth->errstr\n";
my($i, $j);
for $i ( 0 .. $#{$table} ) {
for $j ( 0 .. $#{$table->[$i]} ) {
print "$table->[$i][$j]\t";
}
print "\n";
}
------------- snap -------------
(from MySQL Reference Manual)
------------------------------
Date: Thu, 28 Sep 2000 07:07:19 GMT
From: jason iversen <jasoniversen@my-deja.com>
Subject: Re: accessing global variables in another perl module
Message-Id: <8quqn5$esr$1@nnrp1.deja.com>
thank you very much for your reply - it's in the morning that i'll
globalizing like crazy.
--
jason iversen
technical director
digital domain
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: Thu, 28 Sep 2000 07:53:12 GMT
From: garry@ifr.zvolve.net (Garry Williams)
Subject: Re: accessing global variables in another perl module
Message-Id: <INCA5.159$UA3.7971@eagle.america.net>
On Thu, 28 Sep 2000 04:22:19 GMT, jason iversen
<jasoniversen@my-deja.com> wrote:
...
>in real life, i have
>
>util::debugmessage() which uses a passed message and a verbosity level.
>many differnt routines call debugmessage() and i dont want to pass the
>debug level every time. i just want to define in main() and be done..
>
>the equivalent of what i want to in C is..
>
>file A
>....
>
>int myglobal;
>void main()
>{
>b()
>}
>
>.....
>file B
>....
>extern int myglobal;
>void b()
>{
>//we can see and modify myglobal here
>}
>
>is this not possible in PERL?
Yes, it is and Jason's post shows one way. If I take your requirement
to `define in main()' a little loosely, TMTOWTDI:
$ cat Thing
#!/usr/local/bin/perl -w
use strict;
use util;
use Thing_h;
use Getopt::Std;
use vars qw( $opt_v );
getopts('v:');
$Thing_h::VERBOSITY_LEVEL = $opt_v || 0;
# ...
util::debugmessage("$0: warning message\n", 3);
# ...
util::debugmessage("$0: severe error\n", 1);
# ...
util::debugmessage("$0: we are crashing\n", 0);
$
-------------------------------------------
$ cat Thing_h.pm
package Thing_h;
use strict;
our ( @ISA, @EXPORT, $VERBOSITY_LEVEL );
use Exporter;
@ISA = qw( Exporter );
@EXPORT = qw( VERBOSITY );
$VERBOSITY_LEVEL = 0;
sub VERBOSITY () { $VERBOSITY_LEVEL; }
1;
$
-------------------------------------------
$ cat util.pm
package util;
use Thing_h;
sub debugmessage {
return if $_[1] > VERBOSITY;
print $_[0];
}
1;
$
-------------------------------------------
$ perl Thing
Thing: we are crashing
$ perl Thing -v1
Thing: severe error
Thing: we are crashing
$ perl Thing -v2
Thing: severe error
Thing: we are crashing
$ perl Thing -v3
Thing: warning message
Thing: severe error
Thing: we are crashing
$
Now you just have to `use Thing_h;' everywhere you need one of its
"globals". If it exports something that is a constant, then you have
only one place to change it. Sort of like you might do it in C with a
"header" file.
--
Garry Williams
------------------------------
Date: 28 Sep 2000 12:26:26 +0100
From: nobull@mail.com
Subject: Re: ASAP: How $SCALAR = $LIST
Message-Id: <u9og1892ql.fsf@wcl-l.bham.ac.uk>
stdenton@my-deja.com writes:
> $count = @array->[$index];
Please note, the above is bogus syntax and should[1] throw a syntax
error, however due to and interpreter bug it will be interpreted as:
$count = $array[$index];
[1] IMNSHO... IIRC Abigail disagrees.
--
\\ ( )
. _\\__[oo
.__/ \\ /\@
. l___\\
# ll l\\
###LL LL\\
------------------------------
Date: Thu, 28 Sep 2000 17:09:36 +0800
From: Hugo Bouckaert <hugo@fractalgraphics.com.au>
Subject: attachment not in body of email
Message-Id: <39D30AD0.F1C76E03@fractalgraphics.com.au>
Hi
In reply to Gwyn's email (who I cannot email directly, it seems)
I am going to write some more terrible things. By the way, thanks for
the example Gwyn.
Anyway, after receiving Gwyn's code, I tried to duplicate it as much as
possible in my script, and I am
finding it still does not work, thatis, I cannot get attachments NOT to
reside in the body of the email.
This is how my code looked like (as much as possible like Gwyn's code
which works):
At the crucial lines where Gwyn's code has:
$msg->attach(Type => 'image/gif',
Data => $data,
Filename => 'userfriendly.gif'
);
I had to put:
$msg->attach(Type => 'text/html',
#Data => $body,
#Filename => $att
FH => $att
);
Because I am getting a path + filename from an upload button (as
multipart/form-data) in a html file. Using Filename didn't work - only
the FH and Path options, it seems. Note that I tried to upload both a
gif image as well as text changing to Type 'text/html' Type 'image/gif'
when appropriate - but the type shouldn't matter surely.
I have the full script pasted in here. If anyone knows why the
attachments still appear in the body of the email, please let me know
(they shouldn't).
Any help much appreciated.
Thanks
Hugo
#!/usr/sbin/perl
#----------------------------------------------------------------------------
# User variables
#----------------------------------------------------------------------------
use Email;
use CGI;
#use CGI qw(:standard);
$query = new CGI;
require Exporter;
use MIME::Lite;
$emailaddress='hugo@fractalgraphics.com.au';
$thankyoupage='http://www.fractalgraphics.com.au/fracviewer/thanks.html';
# Test if the forms have been filled in.
if (!$query->param('Email')) {
&print_page_start;
&write_form;
&print_page_end;
}
else {
&print_page_start;
&write_file;
&print_page_end;
&print_refer;
}
sub print_page_start {
print $query->header;
print "<html><head><title>Data Conversion
Page</title>\n</head>\n<body>\n";
print "<h1>Data Conversion page</h1>";
}
sub print_page_end {
print "</body></html>"
}
sub write_form {
print "<FORM METHOD=\"POST\" ENCTYPE=\"multipart/form-data\"
ACTION=\"http://www.fractalgraphics.com.au/cgi-bin/upload3.pl\">\n";
print "<p>Email Address\n";
print "<INPUT TYPE=\"TEXT\" NAME=\"Email\" SIZE=\"30\"></p>\n";
print "<p>Name\n";
print "<INPUT TYPE=\"TEXT\" NAME=\"Name\" SIZE=\"30\"></p>\n";
print "<p>Company\n";
print "<INPUT TYPE=\"TEXT\" NAME=\"Company\"
SIZE=\"30\"></p>\n";
print "<p>File to upload\n";
print "<INPUT TYPE=\"FILE\" NAME=\"Mdata\" SIZE=\"30\"></p>\n";
print "<p>Submit\n";
print "<INPUT TYPE=\"SUBMIT\" VALUE=\"Submit\"></p>";
print "</FORM><br><br>\n";
}
sub write_file {
$email= $query->param('Email');
$name = $query->param('Name');
$company = $query->param('Company');
$att = $query->param('Mdata');
$body = <<MESSAGE_TO_USER;
----------------------------------------------------------------------
These details were submitted using the WWW Form
on the Fractal Graphics FracViewer webpage
----------------------------------------------------------------------
Please send information about the requested product to the client's
email address:
Sender's Email: $email
Name: $name
Company: $company
----------------------------------------------------------------------
MESSAGE_TO_USER
my $msg = MIME::Lite->new(
From => 'info@fractalgraphics.com.au',
To => 'hugo@fractalgraphics.com.au',
Subject => 'A new userfriendly image!',
Type => 'multipart/mixed'
);
$msg->attach(Type => 'TEXT',
Data => "Attached please find the latest image\n",
);
$msg->attach(Type => 'text/html',
#Data => $body,
#Filename => $att
FH => $att
);
#----------------------------------------------------------------------------
# Generate reply for user
# Send the thankyou page to the submitter ...
print "Location: $thankyoupage\n\n";
}
exit;
Gwyn Judd wrote:
>
> I was shocked! How could Hugo Bouckaert <hugo@fractalgraphics.com.au>
> say such a terrible thing:
> >Hi
> >
> >I have been trying forever now to have a perl script that sends email
> >with attachments not displayed in the body of the email. It just does
> >not want to work!! This is very frustrating.
>
> >This is virtually identical to what is in perldoc Lite
> >
> >BUT IT DOES NOT WORK! The mail and attachment(s) are sent, but all
> >attachments, including the image, are in the body of the email
>
> Beats me. Yours looks like it should work to my limited knowledge. Are
> you sure it's not a MUA issue? Some mailers will display any attachments
> that they know about.
>
> >As I said, an actual working perl script would be most welcome, then I
> >can compare a working version with mine and see what goes wrong. I
> >really don't seem to get this one.
>
> Here is a "works for me" script that attaches a gif downloaded from a
> site on the internet into a document:
>
> #!/usr/bin/perl -w
> # get a userfriendly image and mail it
>
> use LWP::Simple;
> use MIME::Lite;
> use strict;
>
> my $arg = shift;
> my $debug = 0;
>
> if (defined $arg && $arg eq '-d')
> {
> print "setting debug option\n";
> $debug = 1;
> }
>
> select STDOUT; $| = 1; # make unbuffered
> select STDERR; $| = 1;
>
> sub print_mess
> {
> my $mess = shift or return;
>
> print $mess if $debug;
> }
>
> # get a file
> sub http_get_file
> {
> my $file = shift;
>
> my $data = get $file or die "Could not get $file: $!\n";
>
> $data;
> }
>
> # You can change these according to the image that you want to grab
> my $document = 'http://www.userfriendly.org/static/index.html';
> my $mail_addr = 'gwyn@thislove.dyndns.org';
>
> my $page = &http_get_file($document);
>
> # this is the section that parses out the correct URL
> my @link = split /ALT="Latest Strip"/, $page;
> my @getlink = split />/, $link[1];
> my @findlink = split /SRC="/, $getlink[0];
> my @pullend = split /">/, $findlink[1];
> $pullend[0] =~ s/"//;
> my $the_file = $pullend[0];
>
> &print_mess("file to get looks like $the_file\n");
>
> my $data = &http_get_file($the_file);
>
> my $msg = MIME::Lite->new(
> From => 'userf@localhost',
> To => $mail_addr,
> Subject => 'A new userfriendly image!',
> Type => 'multipart/mixed'
> );
>
> $msg->attach(Type => 'TEXT',
> Data => "Attached please find the latest userfriendly cartoon\n",
> );
>
> $msg->attach(Type => 'image/gif',
> Data => $data,
> Filename => 'userfriendly.gif'
> );
>
> $msg->send;
>
> --
> Gwyn Judd (print `echo 'tjla@guvfybir.qlaqaf.bet' | rot13`)
> About all some men accomplish in life is to send a son to Harvard.
--
Dr Hugo Bouckaert
R&D Support Engineer, Fractal Graphics
39 Fairway, Nedlands Western Australia 6009
Tel: 9284 8442
Email:hugo@fractalgraphics.com.au
Web: http://www.fractalgraphics.com.au
------------------------------
Date: Thu, 28 Sep 2000 07:32:08 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: Candidate for the top ten perl mistakes list
Message-Id: <sts5tsgutoj7hv26hhhe6saiqofnv2ui3t@4ax.com>
Ren Maddox wrote:
>It seems that splice() should be an l-value.
Heh, you're right. It seems like
@a = qw(a b c d);
splice @a, 1, 2 = (1 .. 4);
should work, resulting in
print "@a\n";
-->
a 1 2 3 4 d
Instead, you have to replace the "=" with a comma. Advantage is you can
return what WAS there before; with an assignment, you can only get what
WILL BE there next. Disadvantage is the intransparent syntax.
Perhaps you can grow the custom to write:
splice @a, 1, 2 => (1 .. 4);
But that will stringify the 3rd parameter, 2; this always represents a
number. Stringifying a number doesn't feel right.
--
Bart.
------------------------------
Date: Thu, 28 Sep 2000 10:09:54 GMT
From: mexicanmeatballs@my-deja.com
Subject: Re: Candidate for the top ten perl mistakes list
Message-Id: <8qv5dg$n2g$1@nnrp1.deja.com>
In article <8qtj2n$d6g$1@provolone.cs.utexas.edu>,
logan@cs.utexas.edu (Logan Shaw) wrote:
> In article <8qr8pa$ol7$1@charm.magnus.acs.ohio-state.edu>,
> Ilya Zakharevich <ilya@math.ohio-state.edu> wrote:
> >Should not a ? b : c become
> >
> > a :-) b :-( c
> >
> >?
>
> Now *that* is an excellent idea! It actually might even be clearer
> than the standard ? : operator, at least in cases where the first of
> the two alternatives is a good one and the other is a bad one.
>
> - Logan
>
Until it appears deeply nested in a bracketed expression where
a,b and c are also bracketed expressions and then it becomes
deeply confusing.
You could _almost_ use it anyway with existing syntax:
$a ? $b :( $c) # Compact smiley operator...
or
$a ? $b :-( -$c) # If $c is a number. Nosed smiley operator..
--
Jon
perl -e 'print map {chr(ord($_)-3)} split //, "MrqEdunhuClqdph1frp";'
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: Thu, 28 Sep 2000 04:36:56 -0700
From: Seiu <Seiu@DesertLINC.com>
Subject: CGI to CGI question
Message-Id: <39D32D58.7FFE@DesertLINC.com>
I'm on a beginner's level with PERL and so the advanced techniques are
far beyond my abilities at this time ~ however I'm hoping somebody can
explain a way for me to create the following type of script...
I want to make a PERL script on one server to send data to a PERL script
on a completely different server. Example:
1) Script on server A acquires the name, age, etc of a client though
HTML
2) The script on Server A now sends this data through the net to Server
B
3) Server B receives the information and processes it further
Preferrably, I would like to not rewrite Server B's script and keep it
in the simple HTML form that I already have. So is there any way I can
send this data, like a string to Server B
"http://www.domain.com/cgi/test.cgi?name=Joe?age=34" etc ...
Thanks to anybody who responds.
- Seiu
------------------------------
Date: 28 Sep 2000 18:45:42 +0900
From: korthner@inf.furukawa.co.jp
Subject: Controlling a Serial Port
Message-Id: <wkd7hox321.fsf@inf.furukawa.co.jp>
Hi, folks.
I'm looking for a way to control a serial port on a PC.
What I'm aiming to do is have the perl script act as a telnet host,
and once a user connects, they can send/receve from a serial port
on the remote computer.
I figure that I can ise IO::Socket for the telnet end of things,
but I don't know how to control the Serial port.
Thanks in advance,
Kent.
------------------------------
Date: 28 Sep 2000 09:59:07 GMT
From: Eric Bohlman <ebohlman@enteract.com>
Subject: Re: Controlling a Serial Port
Message-Id: <8qv4pb$9u3$1@news.enteract.com>
korthner@inf.furukawa.co.jp wrote:
> Hi, folks.
> I'm looking for a way to control a serial port on a PC.
> What I'm aiming to do is have the perl script act as a telnet host,
> and once a user connects, they can send/receve from a serial port
> on the remote computer.
> I figure that I can ise IO::Socket for the telnet end of things,
> but I don't know how to control the Serial port.
Use Win32::SerialPort.
------------------------------
Date: 28 Sep 2000 21:13:29 +0900
From: korthner@inf.furukawa.co.jp
Subject: Re: Controlling a Serial Port
Message-Id: <wk66ngww7q.fsf@inf.furukawa.co.jp>
Simple enough, 'cept that I don't know where Win32::SerialPort is. If I
just add "Use Win32::SerialPort" at the top of my .pl file, it tells me
that "Can't locate..."
Is there somwhere I can get thic Module from? Or does it ship with the
Activestate Perl? And Where cna I find the documentation?
Thanks for putting up with my stupid questions.
-kent
------------------------------
Date: 28 Sep 2000 12:35:26 +0100
From: nobull@mail.com
Subject: Re: dereferencing an array from within a hash value
Message-Id: <u9lmwc92bl.fsf@wcl-l.bham.ac.uk>
"Dave" <dprovac1@twcny.rr.com> writes:
>
> %FIELDS = ('personal information' => ['Name', 'Address', 'Tele', 'Fax']);
%FIELDS is a special variable - please don't abuse it.
> foreach (keys %FIELDS) {
> print "$_ $FIELDS{$_} \n";
> }
>
> How do I dereference $FIELDS{$_} so that
You dereference reference to an array by putting an @ in front. If
the expression that yeilds the refereence contains syntatic elements
that bind less tightly than the @ then enclose the expression in {}
(_not_ ()).
@{$FIELDS{$_}}
> Name, Address, Tele, Fax prints out?
In that case you'll also need:
local @" = ', ';
--
\\ ( )
. _\\__[oo
.__/ \\ /\@
. l___\\
# ll l\\
###LL LL\\
------------------------------
Date: 28 Sep 2000 12:05:57 +0100
From: nobull@mail.com
Subject: Re: File::Find problem
Message-Id: <u9r96493oq.fsf@wcl-l.bham.ac.uk>
noodle42@my-deja.com writes:
> In article <u966ni9ipl.fsf@wcl-l.bham.ac.uk>,
> nobull@mail.com wrote:
>
> > > That is, suddenly I don't get any notification of the files in the
> > > directories (or subdirectories for that matter).
> >
> > Try setting $File::Find::dont_use_nlink
>
> That solved it - thank you very much. What's the explanation for that
> behaviour (and the solution)?
This has nothing to do with Perl:
If a directory inode has exactly two links then the unix find command
and Perl's File::Find assume that it has no sudirectories.
In the case of a non-Unix filesystem this may be an invalid
assumption.
A vanilla ISO9660 CD mounted on Linux will report all directories as
having one link so there's no problem. I do not know about other
Unicies.
A ISO9660+RR CD mounted on any Unix should report inodes as having as
many links as the RR extension data on the disk says (if this
information is recorded).
If the CD was created by mastering program that erroneously puts a
link count of 2 on a directory with subdirectories then you'll get
this problem.
I haven't looked at mkisofs recently since the author won't accept my
patches. Fixing the link count was on my list of things to do but I
abondoned it because I saw little point if my patches were not going
to make it into the primetime. (I therefore don't know if the latest
mkisofs calculates link counts properly).
--
\\ ( )
. _\\__[oo
.__/ \\ /\@
. l___\\
# ll l\\
###LL LL\\
------------------------------
Date: Thu, 28 Sep 2000 07:41:54 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: foreach two elements at a time?
Message-Id: <ebt5ts4r72qjs0g6bvsb5qm12rrf847f7s@4ax.com>
Martien Verbruggen wrote:
>> my($a, $b);
>> print join "\n", sort { $a <=> $b } map { int rand 100 } 1 .. 20;
>> -->
>> Can't use "my $a" in sort comparison at test.pl line 4.
>
>\begin{peeve}
>
>That's an argument to allow sort subs to act on @_, so that we can
>write them in a slighlty more sane way.
>
>my @foo = sort { $_[0] <=> $_[1] } @bar;
>
>It's longer, and I have no clue how hard it would be to implement, but
>I've always had a bit of a problem with the reservedness[1] of $a and
>$b.
But, in a way, you can already. See perldoc -f sort:
If the subroutine's prototype is `($$)', the elements to be
compared are passed by reference in `@_', as for a normal
subroutine. This is slower than unprototyped subroutines, where
the elements to be compared are passed into the subroutine as
the package global variables $a and $b (see example below). Note
that in the latter case, it is usually counter-productive to
declare $a and $b as lexicals.
I wouldn't know how you could possibly apply a function prototype to an
anonymous block. That's why I said: "in a way".
--
Bart.
------------------------------
Date: Thu, 28 Sep 2000 10:41:26 GMT
From: kevin_mcfarlane@my-deja.com
Subject: Hash of Hashes Problem
Message-Id: <8qv78m$obm$1@nnrp1.deja.com>
I am trying to create a map of maps according to the following pattern:
Primitive Name Node Span
"Name1" -> "Source" A
"Destination" B
"Name2" -> "Source" D
"Destination" E
"Name3" -> "Source" F
"Destination" G
I appear to be able to set this map up correctly when I examine the
contents after assigning values
but then when I iterate through the map after it has been set up I only
seem able to reference the
last item added to the map. Where am I going wrong?
Here is the code:
sub test {
my $name = 'Fred';
my $node1 = 'A';
my $node2 = 'B';
my $i = 0;
my %prim_node_span;
my %prim_name_to_node_span;
lvcommon::log_debug("Map Contents while looping through...");
# (Note: the above is just a user-defined print function)
while ($i < 3) {
# Initialise prim_node_span map
$name = $name.$i;
$node1 = $node1.$i;
$node2 = $node2.$i;
$prim_node_span{'source'} = $node1;
$prim_node_span{'destination'} = $node2;
# Initialise prim_name_to_node_span map with prim_node_span map
my $prim_node_span_ref = \%prim_node_span;
$prim_name_to_node_span{$name} = $prim_node_span_ref; # Expect
this is the problem
# but can
only store scalar references in a map
# so how
else can I do it?
# Print contents
lvcommon::log_debug("Name = ".$name);
lvcommon::log_debug("Source = ".$prim_name_to_node_span{$name}->
{'source'});
lvcommon::log_debug("Destination = ".$prim_name_to_node_span
{$name}->{'destination'});
$i++;
}
lvcommon::log_debug("Map Contents after...");
foreach $key ( keys %prim_name_to_node_span ) {
$name = $key;
lvcommon::log_debug("Name = ".$name);
lvcommon::log_debug("Source = ".$prim_name_to_node_span{$name}->
{'source'});
lvcommon::log_debug("Destination = ".$prim_name_to_node_span
{$name}->{'destination'});
}
}
The output this produces is:
Map Contents while looping through...
[This is what I want]
Name = Fred0
Source = A0
Destination = B0
Name = Fred01
Source = A01
Destination = B01
Name = Fred012
Source = A012
Destination = B012
Map Contents after...
[This is wrong]
Name = Fred0
Source = A012
Destination = B012
Name = Fred01
Source = A012
Destination = B012
Name = Fred012
Source = A012
Destination = B012
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: 28 Sep 2000 12:09:25 GMT
From: ebohlman@omsdev.com
Subject: Re: Hash of Hashes Problem
Message-Id: <8qvcdl$g9n$1@news.enteract.com>
kevin_mcfarlane@my-deja.com wrote:
> I appear to be able to set this map up correctly when I examine the
> contents after assigning values
> but then when I iterate through the map after it has been set up I only
> seem able to reference the
> last item added to the map. Where am I going wrong?
Exactly where you think you are.
> Here is the code:
> sub test {
> my $name = 'Fred';
> my $node1 = 'A';
> my $node2 = 'B';
> my $i = 0;
> my %prim_node_span;
Observe that the scope of this variable is the entire subroutine.
> my %prim_name_to_node_span;
> lvcommon::log_debug("Map Contents while looping through...");
> # (Note: the above is just a user-defined print function)
> while ($i < 3) {
> # Initialise prim_node_span map
> $name = $name.$i;
> $node1 = $node1.$i;
> $node2 = $node2.$i;
> $prim_node_span{'source'} = $node1;
> $prim_node_span{'destination'} = $node2;
> # Initialise prim_name_to_node_span map with prim_node_span map
> my $prim_node_span_ref = \%prim_node_span;
Because the scope of %prim_node_span extends outside the loop, taking a
reference to it inside the loop will always give a reference to the same
place (which, at the end of the loop, will contain only the last thing put
there). You need to declare %prim_node_span_ref inside the loop, which
will ensure that a new place is created each time around the loop.
> $prim_name_to_node_span{$name} = $prim_node_span_ref; # Expect
> this is the problem
> # but can
> only store scalar references in a map
> # so how
> else can I do it?
------------------------------
Date: 28 Sep 2000 12:28:57 GMT
From: ebohlman@omsdev.com
Subject: Re: Hash of Hashes Problem
Message-Id: <8qvdi9$g9n$2@news.enteract.com>
ebohlman@omsdev.com wrote:
> Because the scope of %prim_node_span extends outside the loop, taking a
> reference to it inside the loop will always give a reference to the same
> place (which, at the end of the loop, will contain only the last thing put
> there). You need to declare %prim_node_span_ref inside the loop, which
^^^^^^^^^^^^^^^^^^^
> will ensure that a new place is created each time around the loop.
That should, of course, be %prim_node_span.
------------------------------
Date: Thu, 28 Sep 2000 07:49:28 GMT
From: "Janek" <janekj@online.ee>
Subject: Help needed to copy files
Message-Id: <cKCA5.14$GY4.1370@nreader1.kpnqwest.net>
Hi!
I am beginner in Perl and I have a little problem.
Please help me with the piece of code to copy many files to one.
Something like: File1.txt + File2.txt + File3.txt = newFile.txt
I can do it under MS-DOS:
copy *.txt newFile.txt
This command is in my .bat file and it works fine.
With Best Regards,
Janek.
------------------------------
Date: Thu, 28 Sep 2000 09:01:09 GMT
From: pjlees@ics.forthcomingevents.gr (Philip Lees)
Subject: Re: How can I combine regular expressions?
Message-Id: <39d307d7.380136@news.grnet.gr>
On 27 Sep 2000 15:16:20 -0500, Ren Maddox <ren.maddox@tivoli.com>
wrote:
>cberry@cinenet.net (Craig Berry) writes:
>
>> Philip Lees (pjlees@ics.forthcomingevents.gr) wrote:
>> : >$line =~ s/\b([A-Z])([A-Z])(?=[a-z]|\W)/$1\l$2/g;
>> : >
>> : >Then you don't need the list of possibilities.
>> :
>> : That's brilliant - I was in the proverbial wood of vision-obstructing
>> : trees.
>>
>> The trouble is that you'll nuke other adjacent capitals besdies those
>> encoding Greek letters. "When I was in CA last weekend, I watched an XX
>> movie." You don't want the CA and XX to become Ca and Xx.
>
>Which happens anyway if any such abbreviations happen to be the same as
>a converted Greek letter. You can exclude the "|\W" piece to avoid
>this, keeping in mind that any stand-alone two-character converted
>Greek letters will not be case adjusted.
It's not a problem - I don't have to deal with mixed language text.
The input will either be all Greek or all English: in the latter case
nothing gets done to it. What I'm concerned with is things like
TH. CHaralambopoulos becoming Th. Chara... , while
TH. CHARA... stays as it is.
Phil
--
Philip Lees
ICS-FORTH, Heraklion, Crete, Greece
Ignore coming events if you wish to send me e-mail
'The aim of high technology should be to simplify, not complicate' - Hans Christian von Baeyer
------------------------------
Date: Thu, 28 Sep 2000 09:03:34 GMT
From: pjlees@ics.forthcomingevents.gr (Philip Lees)
Subject: Re: How can I combine regular expressions?
Message-Id: <39d3094e.755676@news.grnet.gr>
On Wed, 27 Sep 2000 12:40:41 GMT, Tim Richardson <ter@my-deja.com>
wrote:
>You are impressed by the power of regular expressions. Perl is a highly
>convenient host to this power.
Fair enough. And yes to both.
Phil
--
Philip Lees
ICS-FORTH, Heraklion, Crete, Greece
Ignore coming events if you wish to send me e-mail
'The aim of high technology should be to simplify, not complicate' - Hans Christian von Baeyer
------------------------------
Date: 28 Sep 2000 12:15:55 +0100
From: nobull@mail.com
Subject: Re: how to share vars at runtime from a safe compartement?
Message-Id: <u9pulo9384.fsf@wcl-l.bham.ac.uk>
lalakaka@my-deja.com writes:
> I define a subroutine outside the safe code, which means that there are
> any commands or variables allowed.
Yes, but if it is called from inside a safe compartment it is still
executed with a false symbol table root.
> The code inside the safe compartement
> calls the subroutine and turns over the name of a variable. This
> variable gets a value inside the subroutine and then should be shared
> with the safe code - but it doesn't work!
If you want code called from within a safe compartment to execute
with a the true symbol table root[1] use Safe::Hole.
[1] Or indeed a different false root.
--
\\ ( )
. _\\__[oo
.__/ \\ /\@
. l___\\
# ll l\\
###LL LL\\
------------------------------
Date: Thu, 28 Sep 2000 13:01:31 GMT
From: "John Wollner" <jwollner@earthlink.net>
Subject: HTTP::Response when client dies
Message-Id: <LiHA5.1006$9z5.49933@newsread03.prod.itd.earthlink.net>
Perlites:
I have problem I'm hoping someone can help me w/. I have an HTTP listener
script using HTTP::Daemon which works great except in one instance. On the
front end of the platform we have a software broker that does load balancing
and manages connections from clients to the script. If the broker times out
waiting on us (its a long process sometimes) it closes the connection. When
the script then goes to send the response back to the client, the connection
is gone and the script hangs. It does not happen often, but always during
peak load (I think that's why we're timing out in the first place).
What I need to know is whether there is a way to check that the client is
still out there or to set a timeout on the send_response method so if the
connection is dead, we don't hang.
TIA
------------------------------
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 4456
**************************************