[29456] in Perl-Users-Digest
Perl-Users Digest, Issue: 700 Volume: 11
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Jul 30 21:09:45 2007
Date: Mon, 30 Jul 2007 18:09:10 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Mon, 30 Jul 2007 Volume: 11 Number: 700
Today's topics:
deleting duplicates in array using references <billbealey@f2s.com>
Re: deleting duplicates in array using references <mritty@gmail.com>
Re: deleting duplicates in array using references <glennj@ncf.ca>
Re: deleting duplicates in array using references <billbealey@f2s.com>
Re: fork command. <tzz@lifelogs.com>
Re: form script question <dnpyles@acousticmusic.com>
Re: form script question <glex_no-spam@qwest-spam-no.invalid>
Re: form script question <noreply@gunnar.cc>
Re: form script question <dnpyles@acousticmusic.com>
Re: getting arguments <spamtrap@dot-app.org>
How to load a dll (dynamic link library) in Tcl? mike.hfzhang@gmail.com
Re: Perl with DBI <hjp-usenet2@hjp.at>
Re: Perl with DBI <hjp-usenet2@hjp.at>
Re: question on reference to array slice <tzz@lifelogs.com>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Mon, 30 Jul 2007 11:37:57 -0700
From: billb <billbealey@f2s.com>
Subject: deleting duplicates in array using references
Message-Id: <1185820677.343566.93920@q75g2000hsh.googlegroups.com>
i have a multidimensional array, but i want to delete duplicate
entries based on the first element of each 'row'.
my array is:
my @array = ( [UK9004411, A140, B, 0.040] , [UK0030239, H7140, H,
0.030] , [UK0030239, S1393, M1, 0.030] , [UK0012821, H4030, H,
0.010] , [UK0012821, H4060, H, 0.010] );
and I want to end up with
( [UK9004411, A140, B, 0.040] , [UK0030239, H7140, H, 0.030] ,
[UK0012821, H4030, H, 0.010] )
(no real preference in which row is dropped...just on a first come
first served basis.)
i.e. take out the duplicate codes based on the first element of each
row $array[$row] -> [0]
i looked into splice() function based on the index but not sure this
is the best way or the syntax for this?
splice (@array , $row, 1); ?
thanks.
------------------------------
Date: Mon, 30 Jul 2007 11:46:14 -0700
From: Paul Lalli <mritty@gmail.com>
Subject: Re: deleting duplicates in array using references
Message-Id: <1185821174.620098.49310@b79g2000hse.googlegroups.com>
On Jul 30, 2:37 pm, billb <billbea...@f2s.com> wrote:
> i have a multidimensional array, but i want to delete duplicate
> entries based on the first element of each 'row'.
$ perldoc -q duplicate
Found in /opt2/Perl5_8_4/lib/perl5/5.8.4/pod/perlfaq4.pod
How can I remove duplicate elements from a list or array?
> my array is:
>
> my @array = ( [UK9004411, A140, B, 0.040] , [UK0030239, H7140, H,
> 0.030] , [UK0030239, S1393, M1, 0.030] , [UK0012821, H4030, H,
> 0.010] , [UK0012821, H4060, H, 0.010] );
>
> and I want to end up with
> ( [UK9004411, A140, B, 0.040] , [UK0030239, H7140, H, 0.030] ,
> [UK0012821, H4030, H, 0.010] )
>
> (no real preference in which row is dropped...just on a first come
> first served basis.)
>
> i.e. take out the duplicate codes based on the first element of each
> row $array[$row] -> [0]
$ perl -MData::Dumper -e'
my @array = (
[UK9004411, A140, B, 0.040] ,
[UK0030239, H7140, H, 0.030] ,
[UK0030239, S1393, M1, 0.030] ,
[UK0012821, H4030, H, 0.010] ,
[UK0012821, H4060, H, 0.010] ,
);
my %seen;
my @nodups = grep { !$seen{$_->[0]}++ } @array;
print Dumper(\@nodups);
'
$VAR1 = [
[
'UK9004411',
'A140',
'B',
'0.04'
],
[
'UK0030239',
'H7140',
'H',
'0.03'
],
[
'UK0012821',
'H4030',
'H',
'0.01'
]
];
> i looked into splice() function based on the index but not sure this
> is the best way or the syntax for this?
>
> splice (@array , $row, 1); ?
splice() is fine for removing the elements once you know which ones
you want to remove, but it's useless for actually finding which
elements to remove.
Paul Lalli
------------------------------
Date: 30 Jul 2007 18:58:50 GMT
From: Glenn Jackman <glennj@ncf.ca>
Subject: Re: deleting duplicates in array using references
Message-Id: <slrnfasd7b.sqn.glennj@smeagol.ncf.ca>
At 2007-07-30 02:37PM, "billb" wrote:
> i have a multidimensional array, but i want to delete duplicate
> entries based on the first element of each 'row'.
>
> my array is:
>
> my @array = ( [UK9004411, A140, B, 0.040] , [UK0030239, H7140, H,
> 0.030] , [UK0030239, S1393, M1, 0.030] , [UK0012821, H4030, H,
> 0.010] , [UK0012821, H4060, H, 0.010] );
>
> and I want to end up with
> ( [UK9004411, A140, B, 0.040] , [UK0030239, H7140, H, 0.030] ,
> [UK0012821, H4030, H, 0.010] )
my @array = (
['UK9004411', 'A140', 'B', 0.040],
['UK0030239', 'H7140', 'H', 0.030],
['UK0030239', 'S1393', 'M1', 0.030],
['UK0012821', 'H4030', 'H', 0.010],
['UK0012821', 'H4060', 'H', 0.010]
);
my %hash = map {$_->[0] => $_} @array;
my @uniq = values %hash;
--
Glenn Jackman
"You can only be young once. But you can always be immature." -- Dave Barry
------------------------------
Date: Mon, 30 Jul 2007 14:18:02 -0700
From: billb <billbealey@f2s.com>
Subject: Re: deleting duplicates in array using references
Message-Id: <1185830282.245868.115830@22g2000hsm.googlegroups.com>
On 30 Jul, 19:46, Paul Lalli <mri...@gmail.com> wrote:
> On Jul 30, 2:37 pm, billb <billbea...@f2s.com> wrote:
>
> > i have a multidimensional array, but i want to delete duplicate
> > entries based on the first element of each 'row'.
>
> $ perldoc -q duplicate
> Found in /opt2/Perl5_8_4/lib/perl5/5.8.4/pod/perlfaq4.pod
> How can I remove duplicate elements from a list or array?
>
> > my array is:
>
> > my @array = ( [UK9004411, A140, B, 0.040] , [UK0030239, H7140, H,
> > 0.030] , [UK0030239, S1393, M1, 0.030] , [UK0012821, H4030, H,
> > 0.010] , [UK0012821, H4060, H, 0.010] );
>
> > and I want to end up with
> > ( [UK9004411, A140, B, 0.040] , [UK0030239, H7140, H, 0.030] ,
> > [UK0012821, H4030, H, 0.010] )
>
> > (no real preference in which row is dropped...just on a first come
> > first served basis.)
>
> > i.e. take out the duplicate codes based on the first element of each
> > row $array[$row] -> [0]
>
> $ perl -MData::Dumper -e'
> my @array = (
> [UK9004411, A140, B, 0.040] ,
> [UK0030239, H7140, H, 0.030] ,
> [UK0030239, S1393, M1, 0.030] ,
> [UK0012821, H4030, H, 0.010] ,
> [UK0012821, H4060, H, 0.010] ,
> );
> my %seen;
> my @nodups = grep { !$seen{$_->[0]}++ } @array;
> print Dumper(\@nodups);
> '
> $VAR1 = [
> [
> 'UK9004411',
> 'A140',
> 'B',
> '0.04'
> ],
> [
> 'UK0030239',
> 'H7140',
> 'H',
> '0.03'
> ],
> [
> 'UK0012821',
> 'H4030',
> 'H',
> '0.01'
> ]
> ];
>
> > i looked into splice() function based on the index but not sure this
> > is the best way or the syntax for this?
>
> > splice (@array , $row, 1); ?
>
> splice() is fine for removing the elements once you know which ones
> you want to remove, but it's useless for actually finding which
> elements to remove.
>
> Paul Lalli
ah, very simple and very fast as well! I'll have to understand how
this is working. It uses a hash I see. Many thanks.
------------------------------
Date: Mon, 30 Jul 2007 20:14:41 -0400
From: Ted Zlatanov <tzz@lifelogs.com>
Subject: Re: fork command.
Message-Id: <m2lkcxl98u.fsf@lifelogs.com>
On Mon, 30 Jul 2007 17:12:06 +0530 "rajendra" <rajendra.prasad@in.bosch.com> wrote:
r> If i want to update(modify) a in both child and parent process, how
r> can I do this?....
As I mentioned earlier, you should learn about the Unix environment and
what fork() does before you can understand the answer to this question.
It's just not a simple answer, that's all. Here's the one-paragraph
version:
Unix processes use fork() to copy their memory space (I'm simplifying)
and start another copy of themselves. Thus, any changes each copy makes
won't affect the original. The copy doesn't keep a magic connection to
the original process. Unlike lightweight thread models, Unix processes
need to communicate using Unix IPC methods (sometimes this is called the
heavyweight thread model). Thus, Unix processes can't communicate using
their own functions *alone*. The nice thing is that you can use IPC to
communicate between your fork()ed processes, *and* with other processes.
I am suggesting that you learn this for your benefit; please don't take
the simple answer of "you do it with module X" but instead learn what
Unix actually does with processes and IPC. You'll be a much better
Unix and Perl programmer if you do.
Ted
------------------------------
Date: Mon, 30 Jul 2007 14:42:11 -0400
From: David Pyles <dnpyles@acousticmusic.com>
Subject: Re: form script question
Message-Id: <f8lbe8$2oip$1@pyrite.mv.net>
On 7/30/2007 12:47 PM, J. Gleixner wrote:
> David Pyles wrote:
>> I'm a web designer, but not a perl programmer. I've been working on
>> some forms using the form mail program that is part of VDeck.
>
> Whatever that is...
>
>
>> $vdeck->send_email({ -to => $to,
>> -from => $to,
>> -cc => [split ',', $cc],
>> -bcc => [split ',', $bcc],
>> -subject => "Feedback: from $form_meta->[2]",
>> -message => $message
>> });
>
>>
>> Can someone tell me how to modify this script to make it pick-up the
>> value of a hidden "subject" field in the form and place it's value in
>> the subject line of the resulting email?
>
> -subject => $q->param('name_of_hidden_subject_field'),
>
> If $to is supplied via the form, then anyone can easily set it and use
> your site to send E-Mail to anyone.
Thanks. Mumia W. suggested the same thing in a private email, but it
soesn't work. I just get a server error. I guess I'll leave it as is.
Dave Pyles
------------------------------
Date: Mon, 30 Jul 2007 15:10:30 -0500
From: "J. Gleixner" <glex_no-spam@qwest-spam-no.invalid>
Subject: Re: form script question
Message-Id: <46ae45b6$0$503$815e3792@news.qwest.net>
David Pyles wrote:
> On 7/30/2007 12:47 PM, J. Gleixner wrote:
>> David Pyles wrote:
>>> I'm a web designer, but not a perl programmer. I've been working on
>>> some forms using the form mail program that is part of VDeck.
>>
>> Whatever that is...
>>
>>
>>> $vdeck->send_email({ -to => $to,
>>> -from => $to,
>>> -cc => [split ',', $cc],
>>> -bcc => [split ',', $bcc],
>>> -subject => "Feedback: from $form_meta->[2]",
>>> -message => $message
>>> });
>>
>>>
>>> Can someone tell me how to modify this script to make it pick-up the
>>> value of a hidden "subject" field in the form and place it's value in
>>> the subject line of the resulting email?
>>
>> -subject => $q->param('name_of_hidden_subject_field'),
>>
>> If $to is supplied via the form, then anyone can easily set it and use
>> your site to send E-Mail to anyone.
> Thanks. Mumia W. suggested the same thing in a private email, but it
> soesn't work. I just get a server error. I guess I'll leave it as is.
> Dave Pyles
You're not giving us enough information to help you. What's the error
and the code you're using that causes the error?
If the HTML contains...
<form ...>
<input type="hidden" name="bar" value="foo">
...other form elements...
<input type="submit">
</form>
And the CGI program to process it contained something like:
use CGI;
my $q = CGI->new();
my $hidden_value = $q->param( 'bar' );
Then $hidden_value will be 'foo'.
Possibly it's something to do with 'VDeck', so maybe it's covered in
the documentation for that product.
------------------------------
Date: Mon, 30 Jul 2007 22:22:34 +0200
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: form script question
Message-Id: <5h6vqoF3jdu6tU1@mid.individual.net>
David Pyles wrote:
> ... it soesn't work. I just get a server error.
To see what the server complains about, you can either check the error
log of the web server, or put this line in the beginning of the script:
use CGI::Carp 'fatalsToBrowser';
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
------------------------------
Date: Mon, 30 Jul 2007 17:11:57 -0400
From: David Pyles <dnpyles@acousticmusic.com>
Subject: Re: form script question
Message-Id: <f8lk6p$2r9b$1@pyrite.mv.net>
On 7/30/2007 4:10 PM, J. Gleixner wrote:
> David Pyles wrote:
>> On 7/30/2007 12:47 PM, J. Gleixner wrote:
>>> David Pyles wrote:
>>>> I'm a web designer, but not a perl programmer. I've been working on
>>>> some forms using the form mail program that is part of VDeck.
>>>
>>> Whatever that is...
>>>
>>>
>>>> $vdeck->send_email({ -to => $to,
>>>> -from => $to,
>>>> -cc => [split ',', $cc],
>>>> -bcc => [split ',', $bcc],
>>>> -subject => "Feedback: from $form_meta->[2]",
>>>> -message => $message
>>>> });
>>>
>>>>
>>>> Can someone tell me how to modify this script to make it pick-up the
>>>> value of a hidden "subject" field in the form and place it's value
>>>> in the subject line of the resulting email?
>>>
>>> -subject => $q->param('name_of_hidden_subject_field'),
>>>
>>> If $to is supplied via the form, then anyone can easily set it and
>>> use your site to send E-Mail to anyone.
>> Thanks. Mumia W. suggested the same thing in a private email, but it
>> soesn't work. I just get a server error. I guess I'll leave it as is.
>> Dave Pyles
>
> You're not giving us enough information to help you. What's the error
> and the code you're using that causes the error?
>
> If the HTML contains...
>
> <form ...>
> <input type="hidden" name="bar" value="foo">
> ...other form elements...
> <input type="submit">
> </form>
>
> And the CGI program to process it contained something like:
>
> use CGI;
> my $q = CGI->new();
> my $hidden_value = $q->param( 'bar' );
>
>
> Then $hidden_value will be 'foo'.
>
> Possibly it's something to do with 'VDeck', so maybe it's covered in
> the documentation for that product.
>
>
>
Thanks for the help. The VDeck" documentation truly sucks.
Dave
------------------------------
Date: Mon, 30 Jul 2007 16:38:13 -0400
From: Sherm Pendley <spamtrap@dot-app.org>
Subject: Re: getting arguments
Message-Id: <m2d4y91vbe.fsf@dot-app.org>
Michele Dondi <bik.mido@tiscalinet.it> writes:
> On Sat, 28 Jul 2007 17:07:22 -0400, Sherm Pendley
> <spamtrap@dot-app.org> wrote:
>
>>Sorry, this is "abuse" - "arguments" is down the hall on your left. :-)
>
> Huh, sorry for being dense... is this the famous Monty Pyton's sketch?
Yep. :-)
I'm glad someone got it - I dread the day when a Monty Python reference is
too obscure for this group...
sherm--
--
Web Hosting by West Virginians, for West Virginians: http://wv-www.net
Cocoa programming in Perl: http://camelbones.sourceforge.net
------------------------------
Date: Mon, 30 Jul 2007 21:54:53 -0000
From: mike.hfzhang@gmail.com
Subject: How to load a dll (dynamic link library) in Tcl?
Message-Id: <1185832493.478362.178390@x40g2000prg.googlegroups.com>
Hi there, I would like to load a dll file in TCL, but i dont have any
clues on how to do that, anyone can let me know the way for that?
thanks.
Mike
------------------------------
Date: Mon, 30 Jul 2007 23:37:15 +0200
From: "Peter J. Holzer" <hjp-usenet2@hjp.at>
Subject: Re: Perl with DBI
Message-Id: <slrnfasmgb.qkd.hjp-usenet2@zeno.hjp.at>
On 2007-07-29 22:47, Jason <jwcarlton@gmail.com> wrote:
>> But this is very dangerous unless you tightly restrict the users who can
>> invoke your CGI script. A user could invoke almost any SQL command this
>> way (read up on "SQL injection").
>
> I've moved away from the idea of dynamic table names, but I'm
> concerned that they can invoke commands through other means. I read
> this warning in a tutorial, but there was no explanation on how to get
> around it.
>
> Currently, the only MySQL parts of the script that the user can invoke
> are:
>
> # Delete if id exists
> if (param('reply') {
> $dbh->do("DELETE FROM subjects WHERE id=" . $dbh->quote($id));
> }
>
> # Add new id
> my $sth = $dbh->prepare(<<SQL);
> INSERT INTO subjects (id, lastmodified, subject)
> VALUES (?, ?, ?)
> SQL
>
> $sth->execute($id, $timestamp, param('subject'));
[...]
> I'm hoping that the use of binding will prevent the users from
> inserting things like "; drop database".
Yes. Using placeholders is the recommended way. $dbh->quote() also works
(unless there's a bug in the DBD module), but is generally more
expensive and more tempting to omit.
hp
--
_ | Peter J. Holzer | I know I'd be respectful of a pirate
|_|_) | Sysadmin WSR | with an emu on his shoulder.
| | | hjp@hjp.at |
__/ | http://www.hjp.at/ | -- Sam in "Freefall"
------------------------------
Date: Tue, 31 Jul 2007 00:02:08 +0200
From: "Peter J. Holzer" <hjp-usenet2@hjp.at>
Subject: Re: Perl with DBI
Message-Id: <slrnfasnv0.qkd.hjp-usenet2@zeno.hjp.at>
On 2007-07-29 22:57, Jason <jwcarlton@gmail.com> wrote:
> I'm tagging this onto the same thread because it's the same topic, but
> the issue is a little different.
>
> With the ID field, I'm wanting to create a unique ID for each new
> submission. I was originally using auto_increment, but the problem is
> that when I remove a row, I do not want the ID to be reused.
For MySQL, depends on the database engine. For MyISAM tables,
auto_increment values are not reused, but for InnoDB, they are.
Also the behavior changed at least once, and may change again in the
future, so you shouldn't rely on it.
Oracle has sequences instead of auto_increment columns, which are
guarantueed to be never reused. You can simulate them in MySQL with a
table with just one value, which you increment programmatically (but you
have to lock it to prevent concurrent access).
> I originally considering added a "status" field, but would rather not
> do that since I would eventually end up with a lot of wasted space
> with rows that are marked as dead.
>
> Is there a logical solution to this? I started to use:
>
> $id = $dbh->selectcol_arrayref("SELECT MAX(id) FROM subjects");
> $id++;
>
> But this isn't working quite right, for 2 reasons.
>
> 1. it's not finding the maximum number in the ID field; it's finding
> the largest number in the entire table.
If that really happens, then there's a bug in your RDBMS. Can you
write a script which reproduces the error starting with an empty
database?
> 2. if I remove the last row, which would have had the maximum ID, then
> that ID would be reused... which I don't want.
So its the same as auto_increment, except
3) Unless you lock the table, you create a race condition: Consider two
scripts running at roughly the same time:
a) the first script will select MAX(id) and get (for example) 759.
b) the second script will select MAX(id) and also get 759.
c) both scripts will increment their value and get 760.
d) the first script will insert a new row with id 760.
e) the second script will try to insert a new row with id 760 and
fail.
hp
--
_ | Peter J. Holzer | I know I'd be respectful of a pirate
|_|_) | Sysadmin WSR | with an emu on his shoulder.
| | | hjp@hjp.at |
__/ | http://www.hjp.at/ | -- Sam in "Freefall"
------------------------------
Date: Mon, 30 Jul 2007 20:20:07 -0400
From: Ted Zlatanov <tzz@lifelogs.com>
Subject: Re: question on reference to array slice
Message-Id: <m2hcnll8zs.fsf@lifelogs.com>
On Sun, 29 Jul 2007 18:04:28 -0000 Rick <rick.peng.du@gmail.com> wrote:
R> Hi, guys
R> In C we can store a set of pointers which point to different arrays
R> into an array of pointer. This way we could fast access different
R> array by looking it up in this pointer array. Is there anyway to do
R> this in Perl. I've been trying different things and no luck so far.
R> LIke:
R> @nums = (1 .. 20);
R> I want to store the reference to @nums[1..10] into $data[0], and the
R> reference to @nums[11:20] into $data[1], so that I could visit, for
R> example, the second set of @nums by something like $data[1][5] to get
R> 15.
R> Is this possible for Perl anyway?
It depends on your purpose. If you aim for speed, just use C (Inline::C
for example). Otherwise, to make your own and everyone else's life
easier, use a function to translate the offsets or a constant. Even
better, explain what you're trying to do; it may be that hashes or
multidimensional arrays or array slices are the right answer for you.
Note you don't have to call the offset function every time, only at the
beginning to find out the offset. So it's not a big speed penalty.
Of course, you can always write your own Tie module, but those are IMHO
the last resort.
Ted
------------------------------
Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 6 Apr 01)
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: due to the current flood of worm email banging on ruby, the smtp
server on ruby has been shut off until further notice.
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 V11 Issue 700
**************************************