[22431] in Perl-Users-Digest
Perl-Users Digest, Issue: 4652 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Mar 3 00:05:41 2003
Date: Sun, 2 Mar 2003 21:05:06 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Sun, 2 Mar 2003 Volume: 10 Number: 4652
Today's topics:
'@' symbol confusion <ncmike@nc.rr.com>
Re: '@' symbol confusion <abigail@abigail.nl>
building 5.8.0 fails on Linux 2.0 system (John Meissen)
Re: building 5.8.0 fails on Linux 2.0 system <goldbb2@earthlink.net>
Delete the element with the lowest value? NEED SPEED! <FreddoSpaceMonkey@hotmail.com>
Re: Delete the element with the lowest value? NEED SPEE (Walter Roberson)
Re: Delete the element with the lowest value? NEED SPEE <REMOVEsdnCAPS@comcast.net>
Re: Delete the element with the lowest value? NEED SPEE <mgjv@tradingpost.com.au>
Re: filename returned by server? <abigail@abigail.nl>
Re: Going around in circles with modules? <abigail@abigail.nl>
Re: Guestbook Pro 1.0 (PCMedics)
Re: Looking for a utility to remove duplicates <peakpeek@purethought.com>
Re: moving a string 'string' into perl script <abigail@abigail.nl>
Moving on a grd. <mail@annuna.com>
Re: Moving on a grd. <mgjv@tradingpost.com.au>
Need to trim word with parenthesis impervious@attbi.com
Re: Need to trim word with parenthesis <wsegrave@mindspring.com>
Re: new Perl feature request: call into shared libs <no.spam@gknw.de>
Re: Perl & VB without activeperl on Windows?? (Autrijus Tang)
Re: search algorithm needed <goldbb2@earthlink.net>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Mon, 03 Mar 2003 00:22:42 GMT
From: mike <ncmike@nc.rr.com>
Subject: '@' symbol confusion
Message-Id: <mfx8a.7579$ki.539004@twister.southeast.rr.com>
I'm sure that this is probably a very simple problem to fix but I can't find
any documentation on it. Perl seems to be confusing the '@' in an email
address with an array variable I'd guess. I get the following error when
trying to run the script. Any help would be greatly appreciated. By the
way, the exact same insert statement will work fine in mysql (I tried that
just to make sure.)
Mike
DBD::mysql::st execute failed: You have an error in your SQL syntax near
'@dippy.com, 101FLippyWay,
Hippyville, SK, 00001, Y)' at line 1 at
/usr/local/lib/perl5/site_perl/5.8.0/i686-linux/Mysql.pm line 173.
#!/usr/bin/perl -w
use strict;
use Mysql;
my $fname = 'dude';
my $lname = 'trippy';
my $email = 'dippy@dippy.com';
my $notifmethod = 'Y';
my $street = '101FLippyWay';
my $city = 'Hippyville';
my $state = 'SK';
my $zip = '00001';
my $dbh = Mysql->Connect("localhost", "wigglefish", "myapache", "secret" );
my $sth = $dbh->query(INSERT INTO user_list VALUES (NULL, $fname, $lname,
$email, $street, $city, $state, $zip, $notifmethod));
------------------------------
Date: 03 Mar 2003 00:32:11 GMT
From: Abigail <abigail@abigail.nl>
Subject: Re: '@' symbol confusion
Message-Id: <slrnb658kb.63e.abigail@alexandra.abigail.nl>
mike (ncmike@nc.rr.com) wrote on MMMCDLXXI September MCMXCIII in
<URL:news:mfx8a.7579$ki.539004@twister.southeast.rr.com>:
__
__ DBD::mysql::st execute failed: You have an error in your SQL syntax near
__ '@dippy.com, 101FLippyWay,
__ Hippyville, SK, 00001, Y)' at line 1 at
__ /usr/local/lib/perl5/site_perl/5.8.0/i686-linux/Mysql.pm line 173.
That's not a Perl error. It's your MySQL that doesn't like unquoted values.
Abigail
--
print 74.117.115.116.32;
print 97.110.111.116.104.101.114.32;
print 80.101.114.108.32;
print 72.97.99.107.101.114.10;
------------------------------
Date: 3 Mar 2003 01:36:23 GMT
From: jmeissen@shell1.aracnet.com (John Meissen)
Subject: building 5.8.0 fails on Linux 2.0 system
Message-Id: <b3ubin01nj7@enews2.newsguy.com>
OK, it doesn't really fail to build. But the socketpair tests fail.
Seems to me that this could be bad.
ext/Socket/socketpair................
# Failed test (../ext/Socket/socketpair.t at line 221)
# got: '0'
# expected: undef
# Failed test (../ext/Socket/socketpair.t at line 223)
# got: '0'
# expected: '1'
# Looks like you failed 2 tests of 45.
FAILED at test 36
I've looked through the files included, as well as searching the
web and newsgroups. I'm not exactly sure where to go from here.
Pointers and suggestions would be appreciated.
Linux 2.0.34
I know, I should upgrade to a more recent Linux distribution.
I'm working on it. But this is a working system with a lot of
custom scripting. I can't just go slapping on a new version.
So I'm slowly migrating everything over to a completely new
system with the latest and greatest. In the meantime, I need
to make perl 5.8.0 work on this system.
john-
------------------------------
Date: Sun, 02 Mar 2003 22:39:11 -0500
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: building 5.8.0 fails on Linux 2.0 system
Message-Id: <3E62CE5F.4B876334@earthlink.net>
John Meissen wrote:
>
> OK, it doesn't really fail to build. But the socketpair tests fail.
Socketpairs tend to have different behavior from one operating system to
another. Making a portable perl interface to these unportable things is
a difficult trick.
> Seems to me that this could be bad.
Do you use any modules or programs which actually *use* socketpairs?
(For that matter, do you even *know of* any which use them, forget about
whether you actually use those modules?)
The advantage of them isn't all that much -- I'm generally willing to
use two pipes instead of one socketpair. (Of course, I'm on windows,
which doesn't *have* socketpair, so of course I don't use them. Or at
least, it doesn't with perl5.6. In perl5.8, there's an experimental
socketpair emulation which uses tcp sockets).
[snip failing test]
> I've looked through the files included, as well as searching the
> web and newsgroups. I'm not exactly sure where to go from here.
> Pointers and suggestions would be appreciated.
My suggestion is to ignore the test failure.
> Linux 2.0.34
>
> I know, I should upgrade to a more recent Linux distribution.
> I'm working on it. But this is a working system with a lot of
> custom scripting. I can't just go slapping on a new version.
> So I'm slowly migrating everything over to a completely new
> system with the latest and greatest. In the meantime, I need
> to make perl 5.8.0 work on this system.
Well, it all works, except that if you try and use alarm() to timeout a
read on a socketpair, it'll fail. (Just a guess; I don't have the code
for the socketpair tests in front of me, but I seem to recall hearing
that that was the cause of this failure or a similar failure.)
--
$;=qq qJ,krleahciPhueerarsintoitq;sub __{0 &&
my$__;s ee substr$;,$,&&++$__%$,--,1,qq;;;ee;
$__>2&&&__}$,=22+$;=~y yiy y;__ while$;;print
------------------------------
Date: Mon, 3 Mar 2003 02:13:07 -0000
From: "Freddo" <FreddoSpaceMonkey@hotmail.com>
Subject: Delete the element with the lowest value? NEED SPEED!
Message-Id: <b3udkc$s2l$1@wisteria.csv.warwick.ac.uk>
Hi there,
I've been trying to devise a method to delete the lowest value from an array
(without disturbing the order of the array). For example:
@array contains:
5,4,2,1,3
# Code to remove smallest number, preserving order goes here
@array now contains:
5,4,2,3
The code I have come up so far is inefficient and I think overly-complex. Is
there a 'quick' way to do this? I'm stumped if I can find it!
Thanks!
FrEddO
------------------------------
Date: 3 Mar 2003 03:03:47 GMT
From: roberson@ibd.nrc-cnrc.gc.ca (Walter Roberson)
Subject: Re: Delete the element with the lowest value? NEED SPEED!
Message-Id: <b3ugmj$787$1@canopus.cc.umanitoba.ca>
In article <b3udkc$s2l$1@wisteria.csv.warwick.ac.uk>,
Freddo <FreddoSpaceMonkey@hotmail.com> wrote:
:I've been trying to devise a method to delete the lowest value from an array
:(without disturbing the order of the array). For example:
What should happen if the array contains duplicates?
--
Warning: potentially contains traces of nuts.
------------------------------
Date: Sun, 02 Mar 2003 21:30:39 -0600
From: "Eric J. Roode" <REMOVEsdnCAPS@comcast.net>
Subject: Re: Delete the element with the lowest value? NEED SPEED!
Message-Id: <Xns9332E4F98A57Asdn.comcast@216.166.71.239>
-----BEGIN xxx SIGNED MESSAGE-----
Hash: SHA1
"Freddo" <FreddoSpaceMonkey@hotmail.com> wrote in
news:b3udkc$s2l$1@wisteria.csv.warwick.ac.uk:
> I've been trying to devise a method to delete the lowest value from an
> array (without disturbing the order of the array). For example:
>
> @array contains:
> 5,4,2,1,3
>
> # Code to remove smallest number, preserving order goes here
>
> @array now contains:
> 5,4,2,3
>
> The code I have come up so far is inefficient and I think
> overly-complex. Is there a 'quick' way to do this? I'm stumped if I
> can find it!
You'll need one pass over the data to find the index of the smallest
number, then you'll need to delete that element with splice().
@array = (...whatever...);
my $ix = min_index (\@array);
splice @array, $ix, 1;
sub min_index
{
my $aref = shift;
my $min_num = $aref->[0];
my $min_idx = 0;
my $idx = 0;
for my $val (@$aref)
{
if ($val < $min_num)
{
$min_num = $val;
$min_idx = $idx;
}
$idx++;
}
return $min_idx;
}
- --
Eric
print scalar reverse sort qw p ekca lre reh
ts uJ p, $/.r, map $_.$", qw e p h tona e;
-----BEGIN xxx SIGNATURE-----
Version: PGPfreeware 7.0.3 for non-commercial use <http://www.pgp.com>
iQA/AwUBPmLMVmPeouIeTNHoEQKMtgCgyWSBQJDsB+sZ+WnZr3zQ9PPES28AoLbJ
YCLtroXmQmWdSeses0m710u0
=0GEH
-----END PGP SIGNATURE-----
------------------------------
Date: Mon, 03 Mar 2003 03:40:20 GMT
From: Martien Verbruggen <mgjv@tradingpost.com.au>
Subject: Re: Delete the element with the lowest value? NEED SPEED!
Message-Id: <slrnb65jl0.1ir.mgjv@verbruggen.comdyn.com.au>
On Mon, 3 Mar 2003 02:13:07 -0000,
Freddo <FreddoSpaceMonkey@hotmail.com> wrote:
> Hi there,
>
> I've been trying to devise a method to delete the lowest value from an array
> (without disturbing the order of the array). For example:
>
> @array contains:
> 5,4,2,1,3
Don't try to say it in English. Use Perl:
my @array = (5, 4, 2, 1, 3);
> # Code to remove smallest number, preserving order goes here
>
> @array now contains:
> 5,4,2,3
You will need to find that minimum value first. Something like:
sub min
{
my $min = shift;
for (@_) { $min = $_ unless $min < $_ }
return $min;
}
Should do for that.
Then, if you want to remove all elements that are equal to that
minimum:
@array = grep $_ != $min, @array;
If you have duplicates, and you only want to remove one of them, you
should probably keep track of the position of that one, and use
splice.
To remove the first, you could use something like
sub min_pos
{
my $min = $_[0];
my $pos = 0;
for my $i (1 .. $#_)
{
if ($_[$i] < $min)
{
$min = $_[$i];
$pos = $i;
}
}
return $pos;
}
to get the position of the first minimum value, and then use
splice @data, min_pos(@data), 1;
to remove it. To get the last one, change the if()-condition to <=,
instead of <.
I wouldn't recommend using one of the following, but they'll do the
job, albeit more slowly and obscurely:
To remove a "random" (depending on your sort [1]):
my $i = 0;
@data =
map $_->[0],
sort { $a->[1] <=> $b->[1] }
(sort { $b->[0] <=> $a->[0] } map [$_, $i++], @data)[0..$#data - 1];
^^^^
With more suitable sort routines (for the last, underlined, sort in
that example), you can remove the first, or the last one:
To remove the first one:
{ $b->[0] <=> $a->[0] || $b->[1] <=> $a->[1] }
To remove the last one:
{ $b->[0] <=> $a->[0] || $a->[1] <=> $b->[1] }
But none of these are more readable, and almost guaranteed to be
slower for reasonable sized arrays than the linear approach described
in the first part of this post.
Martien
[1] In perl 5.8.0, sort is stable, so leaving the second sort key
unspecified means that you will be removing the last occurence of a
minimum field. With earlier perls, sort is not (necessarily) stable
--
|
Martien Verbruggen | I took an IQ test and the results were
Trading Post Australia | negative.
|
------------------------------
Date: 02 Mar 2003 23:43:49 GMT
From: Abigail <abigail@abigail.nl>
Subject: Re: filename returned by server?
Message-Id: <slrnb655pl.63e.abigail@alexandra.abigail.nl>
Jef S (zaphod@frognet.net) wrote on MMMCDLXX September MCMXCIII in
<URL:news:bi436v8i3ioc2s8ol287smpeo37rnumk5g@4ax.com>:
-- I'm writing a search program in perl and am trying to figure out how
-- to determine the name of the file returned from the server if I send a
-- request for something like http://www.mydomain.com I'd like to be
-- able to find out if the file returned is index.htm, index.html,
-- index.php, etc.
What makes you think a file is returned? There are a lot of devices
out there that are web enabled, but don't have the concept of a file
system, or files. But, even if the host in the URL points to a device
that has a concept of files, there's no reason the request should
return the content of a file on that device.
There is *NO* relationship between URLs and files, other than
site policy. There's nothing in the HTTP protocol that will
expose this site policy.
Not that any of this has anything to do with Perl.
Abigail
--
sub f{sprintf'%c%s',$_[0],$_[1]}print f(74,f(117,f(115,f(116,f(32,f(97,
f(110,f(111,f(116,f(104,f(0x65,f(114,f(32,f(80,f(101,f(114,f(0x6c,f(32,
f(0x48,f(97,f(99,f(107,f(101,f(114,f(10,q ff)))))))))))))))))))))))))
------------------------------
Date: 02 Mar 2003 23:39:18 GMT
From: Abigail <abigail@abigail.nl>
Subject: Re: Going around in circles with modules?
Message-Id: <slrnb655h6.63e.abigail@alexandra.abigail.nl>
Peter Cooper (newsfeed2@boog.co.uk) wrote on MMMCDLXX September MCMXCIII
in <URL:news:20n8a.9693$EN3.75919@newsfep4-glfd.server.ntli.net>:
|| Let's say I have a main program.. something.pl
||
|| something.pl has a number of global settings that are held within Settings.p
|| which is kept nice and simple so that people installing the program can simp
|| edit that one file.
||
|| Now.. something.pl uses a lot of subroutines that are in Subroutines.pm, so
|| something.pl simply uses Settings.pm and Subroutines.pm. Simple enough. But.
||
|| Subroutines.pm -also- needs to use Settings.pm.
||
|| Does this mean that 'Settings.pm' is imported twice, once into the program a
|| once into Subroutines? Is there now double the memory usage for it? Can Perl
|| stuck in some sort of circular loop? I've got a lot of info on modules, but
|| haven't found anything that specifically mentions any problems with a bunch
|| modules all calling each other in recursion.
||
|| Or, as I'm guessing, there's no 'loop' anyway.. since modules are only impor
|| into the calling code, and not all the way up the tree..? Perhaps I'm thinki
|| too hard on this!
Just do:
use Subroutines;
use Settings;
in something.pl, and do
use Settings;
in Subroutines.pm. Unless you go out of your way, Perl will not compile
a module twice (it keeps track of what has been compiled); it will
call 'import ()' each time though, so if Settings exports something,
it's exported into both Subroutines.pm and something.pl.
Abigail
--
package Just_another_Perl_Hacker; sub print {($_=$_[0])=~ s/_/ /g;
print } sub __PACKAGE__ { &
print ( __PACKAGE__)} &
__PACKAGE__
( )
------------------------------
Date: 2 Mar 2003 19:22:46 -0800
From: sales@pcmedix.org (PCMedics)
Subject: Re: Guestbook Pro 1.0
Message-Id: <e826f4aa.0303021922.75fef4e0@posting.google.com>
tadmc@augustmail.com (Tad McClellan) wrote in message news:<slrnb5mt4d.40h.tadmc@magna.augustmail.com>...
> PCMedics <sales@pcmedix.org> wrote:
>
> > Guestbook pro is a unique guestbook,
>
>
> And it was written by a spammer.
>
> Commercial posts are not welcome in discussion newsgroups.
Thank you for your OPINION!... and it is disregarded! please keep your
OPIONIONS to your self. I beg to differ on the "SPAMMER" remark...
------------------------------
Date: Sun, 02 Mar 2003 23:16:56 +0000
From: Sharon Grant <peakpeek@purethought.com>
Subject: Re: Looking for a utility to remove duplicates
Message-Id: <6ju46vco845ed7267is47j01olv7h1ln76@4ax.com>
On Sun, 2 Mar 2003 13:21:20 -0000, in comp.lang.perl.misc, "Jade V Williams" <2001_jade@msn.com> wrote:
>@fruits:
>[0] Banana: 0.12
>[1] Apple: 0.15
>[2] Pear: 0.16
>[3] Banana: 0.13
>
>I'd like to remove all duplicates in fruit field and when deciding which one
>to remove, remove the heaviest
Perl has a data structure called a hash, which is like an array
except that the elements are accessed by name rather than number.
You can use a hash to remove duplicates
This script builds a hash from your array. If the fruit is
already in the hash, it is replaced if the weight is lower.
Thus your heavier fruit duplicates are deleted
#!/usr/bin/perl -T
use warnings; use strict;
my @fruits = ('Banana: 0.12', 'Apple: 0.15', 'Pear: 0.16', 'Banana: 0.13');
my %fruit_hash;
foreach my $fruit (@fruits) {
my ($fruit_name, $fruit_weight) = split /: /, $fruit;
if (exists $fruit_hash{$fruit_name}) {
$fruit_hash{$fruit_name} = $fruit_weight
if $fruit_weight < $fruit_hash{$fruit_name};
}
else {
$fruit_hash{$fruit_name} = $fruit_weight;
}
}
foreach my $fruit_name (keys %fruit_hash) {
print "$fruit_name: $fruit_hash{$fruit_name}\n";
}
>Might it help to sort by weight first? I need to do this anyway, so before
>or after the removal of duplicates would be good
No
To remove heavier duplicates by sorting you would sort by
fruit name and weight
#!/usr/bin/perl -T
use warnings; use strict;
my @fruits = ('Banana: 0.12', 'Apple: 0.15', 'Pear: 0.16', 'Banana: 0.13');
my @sorted_fruits = sort {
my ($a_name, $a_weight) = split /: /, $a;
my ($b_name, $b_weight) = split /: /, $b;
if ($a_name eq $b_name) {
return $a_weight <=> $b_weight;
}
else {
return $a_name cmp $b_name;
}
} @fruits;
my @dedup_fruits;
my $prev_name = '';
foreach my $fruit (@sorted_fruits) {
my ($name, $weight) = split /: /, $fruit;
push @dedup_fruits, $fruit unless $name eq $prev_name;
$prev_name = $name;
}
foreach my $fruit (@dedup_fruits) {
print "$fruit\n";
}
=====
Using a hash is a bit simpler, but requires a slight change
to the sort sequence to sort by fruit and heaviest first. Then
when building the hash, the lighter duplicates simply replace
the existing entry for the same fruit
#!/usr/bin/perl -T
use warnings; use strict;
my @fruits = ('Banana: 0.12', 'Apple: 0.15', 'Pear: 0.16', 'Banana: 0.13');
my @sorted_fruits = sort {
my ($a_name, $a_weight) = split /: /, $a;
my ($b_name, $b_weight) = split /: /, $b;
if ($a_name eq $b_name) {
return $b_weight <=> $a_weight;
}
else {
return $a_name cmp $b_name;
}
} @fruits;
my %fruit_hash;
foreach my $fruit (@sorted_fruits) {
my ($name, $weight) = split /: /, $fruit;
$fruit_hash{$name} = $weight;
}
foreach my $fruit_name (keys %fruit_hash) {
print "$fruit_name: $fruit_hash{$fruit_name}\n";
}
--
Sharon
------------------------------
Date: 02 Mar 2003 23:45:51 GMT
From: Abigail <abigail@abigail.nl>
Subject: Re: moving a string 'string' into perl script
Message-Id: <slrnb655tf.63e.abigail@alexandra.abigail.nl>
Gunnar Hjalmarsson (noreply@gunnar.cc) wrote on MMMCDLXX September
MCMXCIII in <URL:news:b3soqn$1p1j1q$1@ID-184292.news.dfncis.de>:
^^ Doron Stein wrote:
^^ > Apparently when i do
^^ >
^^ > perl_script 'string'
^^ >
^^ > and inside the script i have
^^ >
^^ > $in = shift ;
^^ > print $in
^^ >
^^ > i get
^^ >
^^ > string
^^ >
^^ > ( without the ' ' )
^^ >
^^ > The same is true when the input is "string".
^^ > In other words , the shell strip both '' and "".
^^ > How do i pass on the exact input without the stripping?
^^
^^ I tested on my W98 installation, and the singlequotes were not
^^ "stripped", while the doublequotes were. The behaviour in this respect
^^ is obviously OS dependent.
It isn't OS dependent. It's a feature of the shell.
^^ I don't know if you can tell the OS not to strip. To retain
^^ doublequotes, you can do:
^^
^^ perl_script \"string\"
Or just use a shell that doesn't have a quoting mechanism.
Abigail
--
INIT {print "Perl " }
BEGIN {print "Just " }
END {print "Hacker\n"}
CHECK {print "another "}
------------------------------
Date: Sun, 02 Mar 2003 20:09:50 -0600
From: Joe Creaney <mail@annuna.com>
Subject: Moving on a grd.
Message-Id: <3E62B96E.1000703@annuna.com>
Again I am trying to write simple programs in perl and getting a little
fustrated. I am trying to write a little demo program that will print
out a grid
*...
....
....
....
I would like to be able to move the star around the grid. I realize
that this is a text program and will have to re-print the grid after
each move. Is there a place I could look up simmilar programs.
I see lots of books on how to write the syntax of a language but very
few on teaching how write programs.
------------------------------
Date: Mon, 03 Mar 2003 03:42:08 GMT
From: Martien Verbruggen <mgjv@tradingpost.com.au>
Subject: Re: Moving on a grd.
Message-Id: <slrnb65joh.1ir.mgjv@verbruggen.comdyn.com.au>
On Sun, 02 Mar 2003 20:09:50 -0600,
Joe Creaney <mail@annuna.com> wrote:
> Again I am trying to write simple programs in perl and getting a little
> fustrated. I am trying to write a little demo program that will print
> out a grid
> *...
> ....
> ....
> ....
> I would like to be able to move the star around the grid. I realize
> that this is a text program and will have to re-print the grid after
> each move. Is there a place I could look up simmilar programs.
To do this sort of thing reliably, you should probably look into using
something like curses (and the Curses module for a Perl interface).
Whether you can use it depends a little on your platform, as does the
manner in which you would install the module.
Martien
--
|
Martien Verbruggen | I used to have a Heisenbergmobile. Every time
Trading Post Australia | I looked at the speedometer, I got lost.
|
------------------------------
Date: Mon, 03 Mar 2003 04:24:55 GMT
From: impervious@attbi.com
Subject: Need to trim word with parenthesis
Message-Id: <e6j56vgvl7m4hgam3j8asjnf9d1dj0qqrf@4ax.com>
Can someone tell me how I could trim a string that looks like this:
(Tue) Mar 04, 2004
So that it looks like this:
Mar 04, 2004
I tried the following code but it has some sort of syntax error. The
first part of the line could be any of the days of the week, not just
Tue and is always followed by a space which also needs to be trimmed
out.
$_ = s/^[(.{3}) ]//;
Thanks
------------------------------
Date: Sun, 2 Mar 2003 22:34:59 -0600
From: "William Alexander Segraves" <wsegrave@mindspring.com>
Subject: Re: Need to trim word with parenthesis
Message-Id: <b3umaj$1du$1@slb9.atl.mindspring.net>
<impervious@attbi.com> wrote in message
news:e6j56vgvl7m4hgam3j8asjnf9d1dj0qqrf@4ax.com...
> Can someone tell me how I could trim a string that looks like this:
>
> (Tue) Mar 04, 2004
>
> So that it looks like this:
>
> Mar 04, 2004
$_ = '(Tue) Mar 04, 2004';
s/^\(.{3}\) //;
print $_;
Bill Segraves
------------------------------
Date: Mon, 03 Mar 2003 00:45:22 +0100
From: Guenter <no.spam@gknw.de>
Subject: Re: new Perl feature request: call into shared libs
Message-Id: <3E629792.9030200@gknw.de>
Hi,
> Tassilo v. Parseval schrieb:
>
>> This functionality exists for windows and is provided by Win32::API.
>
> no, not really; there you can only access some functions...
> and you cant define others...
sorry, was wrong here! Exactly, that's it! I've not carefully looked...
do you know if there exists a similar extension for Unix??
but thanks again for the Win32 hint!
Guenter.
------------------------------
Date: 2 Mar 2003 19:14:02 -0800
From: autrijus@autrijus.org (Autrijus Tang)
Subject: Re: Perl & VB without activeperl on Windows??
Message-Id: <12bcf56.0303021914.49e12e0c@posting.google.com>
nobody <noemail@nowhere.net> wrote in message news:<Xns932E63F4972FFabccbaabc@129.250.170.100>...
> I've read the documentation again and I can't think what led me to
> my earlier conclusion. My mistake.
No problem. I should have made it clearer up-front anyway. :-)
> For an MSWIN app using ActivePerl, it sounds like I'd just need to
> deliver the app .exe and perl56.dll (for example). Great!
Thanks! Also note that 0.63 has a rather unpleasant bug relating
to binmode() that prevents it to dynamically load packed .dll
files on windows... 0.64 has been released to correct this problem,
and I look forward to your feedback. :)
See http://nntp.x.perl.org/group/perl.par/31 for the release announcement.
If you don't have Microsoft VC++, just wait for a few days and
the new version should make its way to the ActivePerl PPM repository.
Thanks,
/Autrijus/
------------------------------
Date: Sun, 02 Mar 2003 22:28:06 -0500
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: search algorithm needed
Message-Id: <3E62CBC6.5F54D5EA@earthlink.net>
FMAS wrote:
>
> Hi Benjamin,
>
> Thank you very much for your help, it is much appreciated. As I am a
> novice at Perl, it'll take a bit of time to test out all the
> suggestions.
>
> You want to have an idea of the type of phrases I am processing.
> Actually there are bilingual entries separated by a tab (I left this
> out of my question and script in order to keep things simple). Typical
> entries are like (with a tab between the 2 languages):
[snip some example phrases]
> A sensor scans the container after the infeed starwheel and transmits
> a signal to the electronic components. Ein Sensor tastet den Behälter
> nach dem Einlaufstern ab und gibt an die Elektronik ein Signal.
[snip]
> The terms list with (English) terms is extracted from such phrases,
> e.g. "gripper finger", "CIP cup"; "bar code", "starwheel"....
Can terms contain more than two words? Also, are they always english
terms (do the letters all match \w), or are some of the searches for
german (or whatever) (Letters like "ä" don't match \w except in the
appropriate locale, and only if "use locale;" is in effect).
Anyway, assuming that *only* one or two words can be matched, and only
words consisting of \w can be matched, then use the following to create
a mapping from terms to phrases.
my $i = 0;
for my $phrase ( @phrases ) {
my ($english) = split /\t/, $phrase;
push @$_, $i for @term2phrases{$english =~ /\w+/g};
push @{$term2phrases{$1.$2}}, $i
while $english =~ /(\w+ (?=\w+)/g;
++$i;
}
Hmm... actually, I've forgotten something important -- stopwords. You
need to make sure that you *don't* create indices for those words which
are commonly used.
my %stopwords = map {;$_ => 1} qw(
a of the it and in for be is are
);
my $i = 0;
for my $phrase ( @phrases ) {
my ($english) = split /\t/, $phrase;
push @$_, $i for @term2phrases{
grep !$stopwords{lc $_}, $english =~ /\w+/g};
!$stopwords{lc $1} and !$stopwords{lc $2} and
push @{$term2phrases{"$1 $2"}}, $i
while $english =~ /(\w+) (?=(\w+))/g;
++$i;
}
if( $DEBUG ) {
my ($word, $count) = (undef, -1);
while( my ($term, $phrases) = each %term2phrases ) {
next if @$phrases < $count;
($word, $count) = ($term, scalar @$phrases);
}
print "Consider the word $word as a possible ";
print "stopword, since it appears in $count phrases\n";
}
[untested]
You might want to use lc() on all the terms, to effectively make the
search case-insensitive.
--
$;=qq qJ,krleahciPhueerarsintoitq;sub __{0 &&
my$__;s ee substr$;,$,&&++$__%$,--,1,qq;;;ee;
$__>2&&&__}$,=22+$;=~y yiy y;__ while$;;print
------------------------------
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.
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 V10 Issue 4652
***************************************