[22497] in Perl-Users-Digest
Perl-Users Digest, Issue: 4718 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Mar 17 06:05:45 2003
Date: Mon, 17 Mar 2003 03:05:07 -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 Mon, 17 Mar 2003 Volume: 10 Number: 4718
Today's topics:
'Wraping' die() (James Willmore)
Re: Anyone For Golf? (Resistor Colour Codes) <goldbb2@earthlink.net>
Re: Anyone For Golf? (Resistor Colour Codes) <Steffen.Beyer@de.bosch.com>
Re: Anyone For Golf? (Resistor Colour Codes) (Jay Tilton)
Re: Anyone For Golf? (Resistor Colour Codes) <goldbb2@earthlink.net>
Re: Anyone For Golf? (Resistor Colour Codes) (Jay Tilton)
Re: Anyone For Golf? (Resistor Colour Codes) (Jay Tilton)
CGI: how to clear form? <josef.moellers@fujitsu-siemens.com>
Re: CGI: how to clear form? <peakpeek@purethought.com>
Re: CGI: how to clear form? <josef.moellers@fujitsu-siemens.com>
Re: CGI: how to clear form? <josef.moellers@fujitsu-siemens.com>
DES 64 bit encryption in Perl (Permata)
Embedding Perl in C/C++... pointer assignment problems <im_not_giving_it_here@i_hate_spam.com>
Re: Embedding Perl in C/C++... pointer assignment probl (Anno Siegel)
How to execute find -exec in perl? <bernd.fischer@xignal.de>
Re: How to execute find -exec in perl? <josef.moellers@fujitsu-siemens.com>
Re: How to execute find -exec in perl? <sfandino@yahoo.com>
Re: How to find a word which is palindromica using REGE <goldbb2@earthlink.net>
Re: How to find a word which is palindromica using REGE (W.J cnqin )
regexp and grouping <bjoernal@ifi.uio.no>
Re: regexp and grouping (Anno Siegel)
Where to find DBD::CSV help? <happier_tj@hotmail.com>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 17 Mar 2003 00:41:10 -0800
From: jwillmore@cyberia.com (James Willmore)
Subject: 'Wraping' die()
Message-Id: <e0160815.0303170041.29c00a0d@posting.google.com>
I am tring to 'wrap' die (ie $SIG{__DIE__}) from within a package.
Huh? I want to issue my own error message from the package when it
encounters an error, but allow the caller to have his own mechanism to
issue an error message.
So, for example and the sake of argument (hopfully this doesn't start
some feud):
##'main' - in different script
#!/usr/bin/perl -w
$SIG{__DIE__} = sub{print "Ouch!!\n";};
use strict;
use Some::Package;
...
$some_package->get_a();
die "Alas, I have died\n";
##'Some::Package'
$SIG{__DIE__} = sub{print "Not going well, is it?\n";};
...
sub get_a{
my $self= shift;
my $a = shift;
die "No A .....";
}
I realize this example is lame, but the basic idea of what I'm trying
to is there (I hope). I started searching the groups for some
answers, but ended up with a lot of people who don't know how to
redirect STDERR to the browser.
So, if you could shed some light on this ....
Thanks,
Jim
------------------------------
Date: Mon, 17 Mar 2003 02:14:56 -0500
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: Anyone For Golf? (Resistor Colour Codes)
Message-Id: <3E7575F0.C3542654@earthlink.net>
Shabble wrote:
[snip]
> --sample code--
> my %colours = ("black" => 0, "brown" => 1, "red" => 2, "orange" => 3,
> "yellow"
> => 4, "green" => 5,"blue" => 6, "violet" => 7, "grey" => 8, "white" =>
> 9 );
> my ($band1, $band2, $band3) = @ARGV;
> $band1 = $colours{$band1};
> $band2 = $colours{$band2};
> $band3 = $colours{$band3};
> my $futile = (($band1 * 10) + $band2) * (10**$band3);
> print "Resistance is $futile\n";
@c{qw/black brown red orange yellow green
blue violet grey white/}=0..9; ($a,$b,$c)
=@c{@ARGV}; print((0+"$a${b}e$c")."\n");
125 chars.
> --shorter code (153 chars)--
> @c=qw(bla br r o y gree b v g w);for(reverse@ARGV
> ){$i=0;while(1){if(/^\Q$c[$i]/i){push@x,$i;last}$
> i++}}print((@x,pop(@x)*10+pop@x)*10**pop@x)."\n";
>
> Any comments/suggestions/entries?
@c=qw(bla br r o y gree blu v g w);@x
=map{my$s=$_;grep$s=~/^$c[$_]/i,0..9}@
ARGV;print((0+"$x[0]$x[1]e$x[2]")."\n")
117 chars.
--
$a=24;split//,240513;s/\B/ => /for@@=qw(ac ab bc ba cb ca
);{push(@b,$a),($a-=6)^=1 for 2..$a/6x--$|;print "$@[$a%6
]\n";((6<=($a-=6))?$a+=$_[$a%6]-$a%6:($a=pop @b))&&redo;}
------------------------------
Date: Mon, 17 Mar 2003 08:10:02 +0100
From: "Steffen Beyer" <Steffen.Beyer@de.bosch.com>
Subject: Re: Anyone For Golf? (Resistor Colour Codes)
Message-Id: <b53sca$9br$1@ns2.fe.internet.bosch.com>
What about automatically detecting if the
order was reversed?
What about also translating the tolerance
colour codes?
And aren't there resistors with five codes
instead of the usual four (2 for value, 1
for order of magnitude, 1 for tolerance)?
I don't know what these are good for, though.
(Can anyone explain? Thanks!)
Solution doesn't need to be very compact,
because it wouldn't be just a pass-time,
it would actually be very useful!
> @c{qw/black brown red orange yellow green
> blue violet grey white/}=0..9; ($a,$b,$c)
> =@c{@ARGV}; print((0+"$a${b}e$c")."\n");
>
> 125 chars.
>
> @c=qw(bla br r o y gree blu v g w);@x
> =map{my$s=$_;grep$s=~/^$c[$_]/i,0..9}@
> ARGV;print((0+"$x[0]$x[1]e$x[2]")."\n")
>
> 117 chars.
Cheers,
Steffen
------------------------------
Date: Mon, 17 Mar 2003 07:12:48 GMT
From: tiltonj@erols.com (Jay Tilton)
Subject: Re: Anyone For Golf? (Resistor Colour Codes)
Message-Id: <3e75616f.20158477@news.erols.com>
On 16 Mar 2003 18:01:12 -0800, da_bisti@yahoo.com (Shabble) wrote:
: For no good reason, I decided to write a resistor colour code
: translator in perl.
: Well, actually, it was to prove to a random heathen that it was easier
: and shorter than doing it in C++ (!)
Heh. Fair enough reason.
: Rules:
: take 3 strings on the command line, space seperated, each being the
: name of a colour in the following list:
:
: #my %colours = ("black" => 0, "brown" => 1, "red" => 2, "orange" => 3,
: "yellow" => 4, "green" => 5, "blue" => 6, "violet" => 7, "grey" => 8,
: "white" => 9 );
:
: Convert it to a number and print its value (and a \n)
: It should be fairly obvious from the code below how to calculate the
: value.
:
: --shorter code (153 chars)--
I count 147 after it's de-linewrapped. Are you including the shebang
in your count?
: @c=qw(bla br r o y gree b v g w);for(reverse@ARGV
: ){$i=0;while(1){if(/^\Q$c[$i]/i){push@x,$i;last}$
: i++}}print((@x,pop(@x)*10+pop@x)*10**pop@x)."\n";
^^^
Does that need to be there?
The "\n" doesn't actually get printed.
: Any comments/suggestions/entries?
Groovy.
AFter some optimizations to yours that don't change the basic function
or flow, I got this (121).
@c=qw(bla br r o y gree b v g w);map{for$i(0..9){push(@x,$i),
last if/^$c[$i]/i}}@ARGV;print 10**$x[2]*($x[0]*10+$x[1]),$/
Two things I'd change.
1. A mathematically generated result is good, but a
character-generated result works too.
2. Use a hash instead of an indexing an array, sort of like in the
verbose sample. Build a regex from the keys.
My best is 98.
@c{@c=qw(bla br r o y gree b v g w)}=0..9;$"='|';
@s=map@c{/^(@c)/i},@ARGV;print@s[0,1],0 x$s[2],$/
------------------------------
Date: Mon, 17 Mar 2003 02:47:54 -0500
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: Anyone For Golf? (Resistor Colour Codes)
Message-Id: <3E757DAA.3987A736@earthlink.net>
Jay Tilton wrote:
[snip]
> @c{@c=qw(bla br r o y gree b v g w)}=0..9;$"='|';
> @s=map@c{/^(@c)/i},@ARGV;print@s[0,1],0 x$s[2],$/
This treats "black" and "brown" wrong, because /^b/ (for blue) matches
both of those others. Likewise, the 'g' matches green and grey.
How about:
@c{@c=qw(k wn d ge w en ue t y te)}=0..9;$"='|';
@s=map@c{/(@c)$/i},@ARGV;print@s[0,1],0 x$s[2],$/
or:
@c{@c=qw(c w re g o re u le re t)}=0..9;$"='|';@
s=map@c{/(@c).$/i},@ARGV;print@s[0,1],0 x$s[2],$/
[untested]
--
$a=24;split//,240513;s/\B/ => /for@@=qw(ac ab bc ba cb ca
);{push(@b,$a),($a-=6)^=1 for 2..$a/6x--$|;print "$@[$a%6
]\n";((6<=($a-=6))?$a+=$_[$a%6]-$a%6:($a=pop @b))&&redo;}
------------------------------
Date: Mon, 17 Mar 2003 08:14:48 GMT
From: tiltonj@erols.com (Jay Tilton)
Subject: Re: Anyone For Golf? (Resistor Colour Codes)
Message-Id: <3e757ee9.27705182@news.erols.com>
Benjamin Goldberg <goldbb2@earthlink.net> wrote:
: Jay Tilton wrote:
: [snip]
: > @c{@c=qw(bla br r o y gree b v g w)}=0..9;$"='|';
: > @s=map@c{/^(@c)/i},@ARGV;print@s[0,1],0 x$s[2],$/
:
: This treats "black" and "brown" wrong, because /^b/ (for blue) matches
: both of those others. Likewise, the 'g' matches green and grey.
The order of alternatives in the regex prevents that.
@c{@c=qw(bla br r o y gree b v g w)}=0..9;
$"='|';
for( qw/ black brown blue green grey / ) {
if( /^(@c)/ ) {
printf "color:%-5s key:%-4s value:%d\n", $_, $1, $c{$1};
}
}
output:
color:black key:bla value:0
color:brown key:br value:1
color:blue key:b value:6
color:green key:gree value:5
color:grey key:g value:8
: How about:
: @c{@c=qw(k wn d ge w en ue t y te)}=0..9;$"='|';
: @s=map@c{/(@c)$/i},@ARGV;print@s[0,1],0 x$s[2],$/
Can't argue with a shaved character, though. :)
: or:
: @c{@c=qw(c w re g o re u le re t)}=0..9;$"='|';@
^^ ^^ ^^
: s=map@c{/(@c).$/i},@ARGV;print@s[0,1],0 x$s[2],$/
Not so hot that time.
------------------------------
Date: Mon, 17 Mar 2003 08:23:26 GMT
From: tiltonj@erols.com (Jay Tilton)
Subject: Re: Anyone For Golf? (Resistor Colour Codes)
Message-Id: <3e7584c6.29207277@news.erols.com>
Benjamin Goldberg <goldbb2@earthlink.net> wrote:
: @c{qw/black brown red orange yellow green
: blue violet grey white/}=0..9; ($a,$b,$c)
: =@c{@ARGV}; print((0+"$a${b}e$c")."\n");
^^^^^^^^^^^^^
That rocks. I was fooling around with inserting 'E' then doing a
string eval. I never thought of making perl numify it automagically.
------------------------------
Date: Mon, 17 Mar 2003 09:00:52 +0100
From: Josef =?iso-8859-1?Q?M=F6llers?= <josef.moellers@fujitsu-siemens.com>
Subject: CGI: how to clear form?
Message-Id: <3E7580B4.229C0DB9@fujitsu-siemens.com>
Hi,
I have offered my judo club to write some software to handle
competitions (registration, weighing, generating starter lists,
determining rank).
For the registration and weighing, I'd like to have a single script
that, when called first (param() is undef), will generate a form to fill
in (name, passport-number, club, weight).
When called with parameters (param() is defined), this script checks the
validity of the data entered (e.g. passport-number and weight are
syntactically correct, passport-number is in some data base of valid
contestants), then stores the data in a data base for later processing
(generation of starter lists). If the data is bad, I'd like to present
the same form, with fields preset ("-value=3D>") and incorrect fields
marked (e.g. by a red star). If all data is correct, I'd like to
generate a new, empty form.
My biggest problem at present is that if I generate a new empty form
after having got some correct data, the fields are preset (have
"value"s).
I've tried to set all parameters to undef (param(-name >=3D "Name", -valu=
e
=3D> undef) or param("Name", undef)), but still, the newly generated form=
has al the values from the previous form.
How do I generate a blank form?
-- =
Josef M=F6llers (Pinguinpfleger bei FSC)
If failure had no penalty success would not be a prize
-- T. Pratchett
------------------------------
Date: Mon, 17 Mar 2003 09:22:49 +0000
From: Shroan Grant <peakpeek@purethought.com>
Subject: Re: CGI: how to clear form?
Message-Id: <r84b7vg48uikrqbfdps4c61vsli60hf6vk@4ax.com>
On Mon, 17 Mar 2003 09:00:52 +0100, in comp.lang.perl.misc, Josef Möllers <josef.moellers@fujitsu-siemens.com>
wrote:
>For the registration and weighing, I'd like to have a single script
>that, when called first (param() is undef), will generate a form to fill
>in (name, passport-number, club, weight).
>When called with parameters (param() is defined), this script checks the
>validity of the data entered (e.g. passport-number and weight are
>syntactically correct, passport-number is in some data base of valid
>contestants), then stores the data in a data base for later processing
>(generation of starter lists). If the data is bad, I'd like to present
>the same form, with fields preset ("-value=>") and incorrect fields
>marked (e.g. by a red star). If all data is correct, I'd like to
>generate a new, empty form.
>
>My biggest problem at present is that if I generate a new empty form
>after having got some correct data, the fields are preset (have
>"value"s).
>
>How do I generate a blank form?
The CGI.pm documentation has answers to this:
http://stein.cshl.org/WWW/software/CGI/
See "Deleting all Parameters". I think this will work according
to the requirement you described
For different approaches look for discussions of the -override
parameter, the -nosticky pragma and "Creating A Defaults Button"
------------------------------
Date: Mon, 17 Mar 2003 10:52:48 +0100
From: Josef =?iso-8859-1?Q?M=F6llers?= <josef.moellers@fujitsu-siemens.com>
Subject: Re: CGI: how to clear form?
Message-Id: <3E759AF0.C0DAAED0@fujitsu-siemens.com>
Shroan Grant wrote:
> =
> On Mon, 17 Mar 2003 09:00:52 +0100, in comp.lang.perl.misc, Josef M=F6l=
lers <josef.moellers@fujitsu-siemens.com>
> wrote:
> =
> >For the registration and weighing, I'd like to have a single script
> >that, when called first (param() is undef), will generate a form to fi=
ll
> >in (name, passport-number, club, weight).
> >When called with parameters (param() is defined), this script checks t=
he
> >validity of the data entered (e.g. passport-number and weight are
> >syntactically correct, passport-number is in some data base of valid
> >contestants), then stores the data in a data base for later processing=
> >(generation of starter lists). If the data is bad, I'd like to present=
> >the same form, with fields preset ("-value=3D>") and incorrect fields
> >marked (e.g. by a red star). If all data is correct, I'd like to
> >generate a new, empty form.
> >
> >My biggest problem at present is that if I generate a new empty form
> >after having got some correct data, the fields are preset (have
> >"value"s).
> >
> >How do I generate a blank form?
> =
> The CGI.pm documentation has answers to this:
> http://stein.cshl.org/WWW/software/CGI/
> =
> See "Deleting all Parameters". I think this will work according
> to the requirement you described
Unfortunately it doesn't seem to work. I just tried using the "Simple
Script" example (the "eenie meenie minie moe" form) from the CGI manpage
and inserted
my $query =3D new CGI;
$query->delete_all();
right at the top but the reply page generated (the one with the response
below the ruler) still has the name in the entry field.
Even if I change the
textfield('name')
to any of
textfield('name', "XXX")
or
textfield(-name=3D>'name', -default=3D>'XXX',)
it is still initialized with the value I inserted before.
Josef
-- =
Josef M=F6llers (Pinguinpfleger bei FSC)
If failure had no penalty success would not be a prize
-- T. Pratchett
------------------------------
Date: Mon, 17 Mar 2003 10:57:19 +0100
From: Josef =?iso-8859-1?Q?M=F6llers?= <josef.moellers@fujitsu-siemens.com>
Subject: Re: CGI: how to clear form?
Message-Id: <3E759BFF.66AE71EB@fujitsu-siemens.com>
Josef M=F6llers wrote:
> =
> Shroan Grant wrote:
> >
> > On Mon, 17 Mar 2003 09:00:52 +0100, in comp.lang.perl.misc, Josef M=F6=
llers <josef.moellers@fujitsu-siemens.com>
> > wrote:
> >
> > >For the registration and weighing, I'd like to have a single script
> > >that, when called first (param() is undef), will generate a form to =
fill
> > >in (name, passport-number, club, weight).
> > >When called with parameters (param() is defined), this script checks=
the
> > >validity of the data entered (e.g. passport-number and weight are
> > >syntactically correct, passport-number is in some data base of valid=
> > >contestants), then stores the data in a data base for later processi=
ng
> > >(generation of starter lists). If the data is bad, I'd like to prese=
nt
> > >the same form, with fields preset ("-value=3D>") and incorrect field=
s
> > >marked (e.g. by a red star). If all data is correct, I'd like to
> > >generate a new, empty form.
> > >
> > >My biggest problem at present is that if I generate a new empty form=
> > >after having got some correct data, the fields are preset (have
> > >"value"s).
> > >
> > >How do I generate a blank form?
> >
> > The CGI.pm documentation has answers to this:
> > http://stein.cshl.org/WWW/software/CGI/
> >
> > See "Deleting all Parameters". I think this will work according
> > to the requirement you described
> =
> Unfortunately it doesn't seem to work. I just tried using the "Simple
> Script" example (the "eenie meenie minie moe" form) from the CGI manpag=
e
> and inserted
> =
> my $query =3D new CGI;
> $query->delete_all();
> =
> right at the top but the reply page generated (the one with the respons=
e
> below the ruler) still has the name in the entry field.
> =
> Even if I change the
> textfield('name')
> to any of
> textfield('name', "XXX")
> or
> textfield(-name=3D>'name', -default=3D>'XXX',)
> =
> it is still initialized with the value I inserted before.
Sorry to follow up on myself (bad habit). I just remembered that this is
open source world B-{)
A quick look into CGI.pm revealed that I should use =
textfield(-name =3D> 'name', -override =3D> 1, -value =3D> "XXX")
and it worked as you suggested:
> For different approaches look for discussions of the -override =
> parameter, the -nosticky pragma and "Creating A Defaults Button"
Thanks,
-- =
Josef M=F6llers (Pinguinpfleger bei FSC)
If failure had no penalty success would not be a prize
-- T. Pratchett
------------------------------
Date: 16 Mar 2003 22:25:49 -0800
From: permata@cryptonics.com.my (Permata)
Subject: DES 64 bit encryption in Perl
Message-Id: <157f6799.0303162225.6535e8d6@posting.google.com>
Dear All,
Sorry if this sounds a bit outdated. I'm a new comer in DES
encryption.
Can anyone tell me how can I encrypt & decrypt a text, given a key,
using DES 64 bit, in perl.
I've tried but doesn't seams to work properly.
e.g:
I've these as my guidelines:
key=cryp1234
text=cryptonics
after encryption = ZNRa1GjkgeX2m5AbmqJmrw==
I've used this script. But still doesn't apear to be the same as
above;
use MIME::Base64;
use Crypt::CBC;
use vars '$CIPHER';
my $secret = "cryp1234";
$CIPHER = Crypt::CBC->new( {'key' => $secret,'cipher' =>
'DES','regenerate_key' => 0, 'prepend_iv' => 0});
my $value = $CIPHER->encrypt("cryptonics");
print "CBC-encrypt ->",$value,"\n";
print "Base64-encode ->", encode_base64($value), "\n";
print "Base64-decode ->", decode_base64(encode_base64($value)),
"\n\n";
$value = $CIPHER->decrypt($value);
print "CBC-decrypt ->",$value,"\n";
Could anyone help me on this.
Regards,
Permata
------------------------------
Date: Mon, 17 Mar 2003 09:00:52 +0000
From: Asfand Yar Qazi <im_not_giving_it_here@i_hate_spam.com>
Subject: Embedding Perl in C/C++... pointer assignment problems
Message-Id: <b542q8$6s0$1@newsg1.svr.pol.co.uk>
The gist of the problem I'm having is that I want Perl to pass pointers
of between functions ( eg $i=get_ptr("stuffit"); dostuff($i);).
I want Perl to error check the pointers passed and warn/die on
incompatibility on given/wanted pointers (eg 'dostuff() wanted Base*
argument, you supplied Grok*!')
I want Perl to not worry about what the pointers contain, except to make
sure that the correct type is passed.
The following Inline code sums up something that I want to do. Note I
use 'Inline C' because its quicker to compile, and I will simply replace
'struct Base' with a pure virtual 'class Base' afterwards.
<begin code>
#!/usr/local/bin/perl -wl
use Inline C => Config
=> OPTIMIZE => '-ggdb3';
use Inline C;
my $i = get_child1();
call_Base_output_name($i);
__END__
__C__
#include <stdio.h>
typedef struct Base
{
char* myname;
} Base;
Base dkd = {"hello"};
void
call_Base_output_name(Base* arg)
{
printf("%s\n", arg->myname);
}
Base*
get_child1()
{
return &dkd;
}
<end code>
The following error results:
<snip>
perl -I
'/home/asfand/src/games/shotgun_robot/engine/../game/data/perl/lib/site_perl'
test/test_inline.pl
Warning. No Inline C functions bound to Perl
Check your C function definition(s) for Inline compatibility
Use of inherited AUTOLOAD for non-method main::get_child1() is
deprecated at test/test_inline.pl line 8.
Can't locate auto/main/get_child1.al in @INC (@INC contains:
/home/asfand/src/games/shotgun_robot/engine/test/.Inline/lib
/home/asfand/src/games/shotgun_robot/engine/../game/data/perl/lib/site_perl/5.6.1/i686-linux
/home/asfand/src/games/shotgun_robot/engine/../game/data/perl/lib/site_perl/5.6.1
/home/asfand/src/games/shotgun_robot/engine/../game/data/perl/lib/site_perl
/opt/perl/lib/5.6.1/i686-linux /opt/perl/lib/5.6.1
/opt/perl/lib/site_perl/5.6.1/i686-linux /opt/perl/lib/site_perl/5.6.1
/opt/perl/lib/site_perl .) at test/test_inline.pl line 8
<snip>
(note the custom module directory)
I can post more info if needed.
------------------------------
Date: 17 Mar 2003 10:05:16 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Embedding Perl in C/C++... pointer assignment problems
Message-Id: <b546ks$1hs$1@mamenchi.zrz.TU-Berlin.DE>
Asfand Yar Qazi <im_not_giving_it_here@i_hate_spam.com> wrote in comp.lang.perl.misc:
> The gist of the problem I'm having is that I want Perl to pass pointers
> of between functions ( eg $i=get_ptr("stuffit"); dostuff($i);).
>
> I want Perl to error check the pointers passed and warn/die on
> incompatibility on given/wanted pointers (eg 'dostuff() wanted Base*
> argument, you supplied Grok*!')
Run time type checking in C? Hardly.
> I want Perl to not worry about what the pointers contain, except to make
> sure that the correct type is passed.
>
> The following Inline code sums up something that I want to do. Note I
> use 'Inline C' because its quicker to compile, and I will simply replace
> 'struct Base' with a pure virtual 'class Base' afterwards.
>
> <begin code>
>
> #!/usr/local/bin/perl -wl
>
> use Inline C => Config
> => OPTIMIZE => '-ggdb3';
>
> use Inline C;
>
> my $i = get_child1();
> call_Base_output_name($i);
>
> __END__
> __C__
>
> #include <stdio.h>
>
> typedef struct Base
> {
> char* myname;
> } Base;
>
> Base dkd = {"hello"};
>
> void
> call_Base_output_name(Base* arg)
Base* is not a type Inline recognizes, so this function will not
make it into Perl. Change the type to void*.
> {
> printf("%s\n", arg->myname);
Now you need a re-cast to Base*:
printf("%s\n", ((Base*)arg)->myname);
> }
>
> Base*
Same problem as above. Change the type to void*
> get_child1()
> {
> return &dkd;
> }
[snip error messages]
With the indicated changes, your code prints "hello", as intended.
Your type-checking plan will not work out, however. At run time, type
information is unknown in C.
Anno
------------------------------
Date: Mon, 17 Mar 2003 10:30:26 +0100
From: Bernd Fischer <bernd.fischer@xignal.de>
Subject: How to execute find -exec in perl?
Message-Id: <3E7595B2.EA0790EC@xignal.de>
Hi,
I want to recursively change the permissions mode
of a directory and files of that selected directory.
In UNIX I can do a
find . -type f -exec chmod 664 {} \;
and a
find . -type d -exec chmod 775 {} \;
If I want to implement that in Perl
foreach( @dir_list ){
@args = ( "find", "$_ -type f -exec chmod 464 {} \\\;" );
system( @args );
@args = ( "find", "$_ -type d -exec chmod 757 {} \\\;" );
system( @args );
}
I got
find: cannot open 'file_name' -type f -exec chmod 464 {} \;: No such file or
directory
find: cannot open 'file_name' -type d -exec chmod 757 {} \;: No such file or
directory
What's wrong?
Is there an elegant way to do this complete in Perl rather than
calling the UNIX find command?
Any suggestions are highly welcome.
Thanks Bernd
------------------------------
Date: Mon, 17 Mar 2003 11:04:10 +0100
From: Josef =?iso-8859-1?Q?M=F6llers?= <josef.moellers@fujitsu-siemens.com>
Subject: Re: How to execute find -exec in perl?
Message-Id: <3E759D9A.2F8C1E28@fujitsu-siemens.com>
Bernd Fischer wrote:
> =
> Hi,
> =
> I want to recursively change the permissions mode
> of a directory and files of that selected directory.
> =
> In UNIX I can do a
> find . -type f -exec chmod 664 {} \;
> and a
> find . -type d -exec chmod 775 {} \;
> =
> If I want to implement that in Perl
> =
> foreach( @dir_list ){
> @args =3D ( "find", "$_ -type f -exec chmod 464 {} \\\;" );
> system( @args );
> @args =3D ( "find", "$_ -type d -exec chmod 757 {} \\\;" );
> system( @args );
> }
> =
> I got
> =
> find: cannot open 'file_name' -type f -exec chmod 464 {} \;: No such fi=
le or
> directory
> find: cannot open 'file_name' -type d -exec chmod 757 {} \;: No such fi=
le or
> directory
> =
> What's wrong?
It's the fact that you already have a list with two elements so perl
won't dissect the arguments of find into a list but rather passes two
arguments to the shell: "find" and the complete second string.
try @args =3D ( "find", "$_", "-type", "f", "-exec", "chmod", "464", "{}"=
,
'\;');
See perldoc -f system for the details: "If there is more than one
argument in LIST ..."
> Is there an elegant way to do this complete in Perl rather than
> calling the UNIX find command?
Have you looked at File::Find?
-- =
Josef M=F6llers (Pinguinpfleger bei FSC)
If failure had no penalty success would not be a prize
-- T. Pratchett
------------------------------
Date: Mon, 17 Mar 2003 11:09:52 +0000
From: =?ISO-8859-1?Q?Salvador_Fandi=F1o_Garc=EDa?= <sfandino@yahoo.com>
Subject: Re: How to execute find -exec in perl?
Message-Id: <3E75AD00.1010501@yahoo.com>
Bernd Fischer wrote:
> foreach( @dir_list ){
> @args = ( "find", "$_ -type f -exec chmod 464 {} \\\;" );
> system( @args );
> @args = ( "find", "$_ -type d -exec chmod 757 {} \\\;" );
> system( @args );
> }
as you are passing several args to 'system' it doesn't call the shell
but runs find with only one argument as
exec "find", "$_ -type f -exec chmod 464 {} \\\;"
what you really want is
exec "find", $_, "-type", "f", "-exec", "chmod", "464", "{}", ";"
so try changing your script to...
foreach( @dir_list ){
system 'find', $_, qw( -type f -exec chmod 464 {} ; );
system 'find', $_, qw( -type d -exec chmod 757 {} ; );
}
or if @dir_list is not going to be too big...
system 'find', @dir_list, qw( -type f -exec chmod 464 {} ; );
system 'find', @dir_list, qw( -type d -exec chmod 757 {} ; );
bye,
- salva
------------------------------
Date: Mon, 17 Mar 2003 01:48:13 -0500
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: How to find a word which is palindromica using REGEXP
Message-Id: <3E756FAD.F294E44F@earthlink.net>
qin jiang wei wrote:
>
> Thank everyone very much!
> But now I want to find the word which is not palindrome . The style is
> like this : 'abcOTHERcba' , while OTHER can be any length , But the
> length of 'abc' and 'cba'is as maximal length as it can. How can I ?
> Sorry for my bad expression.
($str ^ reverse $str) =~ /^(\0*)/;
my $a = length $1;
if( $a == length $str ) {
print "$str is a palindrome\n";
} elsif( $a ) {
print "The leading and trailing $a letters of $str are mirrors\n";
} else {
print "The leading and trailing letters of $str are not mirrors\n";
}
--
$a=24;split//,240513;s/\B/ => /for@@=qw(ac ab bc ba cb ca
);{push(@b,$a),($a-=6)^=1 for 2..$a/6x--$|;print "$@[$a%6
]\n";((6<=($a-=6))?$a+=$_[$a%6]-$a%6:($a=pop @b))&&redo;}
------------------------------
Date: 17 Mar 2003 17:21:49 +0800
From: qin@freebsd.lzu.edu.cn (W.J cnqin )
Subject: Re: How to find a word which is palindromica using REGEXP
Message-Id: <8665qifivm.fsf@freebsd.lzu.edu.cn>
Benjamin Goldberg <goldbb2@earthlink.net> writes:
> qin jiang wei wrote:
> >
> > Thank everyone very much!
> > But now I want to find the word which is not palindrome . The style is
> > like this : 'abcOTHERcba' , while OTHER can be any length , But the
> > length of 'abc' and 'cba'is as maximal length as it can. How can I ?
> > Sorry for my bad expression.
>
> ($str ^ reverse $str) =~ /^(\0*)/;
> my $a = length $1;
> if( $a == length $str ) {
> print "$str is a palindrome\n";
> } elsif( $a ) {
> print "The leading and trailing $a letters of $str are mirrors\n";
> } else {
> print "The leading and trailing letters of $str are not mirrors\n";
> }
This is a good solution! Thanks.
------------------------------
Date: Mon, 17 Mar 2003 11:17:51 +0100
From: =?ISO-8859-1?Q?Bj=F8rnar_Lib=E6k?= <bjoernal@ifi.uio.no>
Subject: regexp and grouping
Message-Id: <b547cg$918$1@maud.ifi.uio.no>
Given the string "what is wrong with my brain", I want to get every
two-letter composition that starts with an 'r' into the grouping-variables,
that is, $1='ro' and $2='ra' in this example. How do I do this?
Bjørnar Libæk
------------------------------
Date: 17 Mar 2003 10:20:53 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: regexp and grouping
Message-Id: <b547i5$1hs$2@mamenchi.zrz.TU-Berlin.DE>
Bjørnar Libæk <bjoernal@ifi.uio.no> wrote in comp.lang.perl.misc:
> Given the string "what is wrong with my brain", I want to get every
> two-letter composition that starts with an 'r' into the grouping-variables,
> that is, $1='ro' and $2='ra' in this example. How do I do this?
my @hits = 'what is wrong with my brain' =~ /(r.)/g;
Anno
------------------------------
Date: Mon, 17 Mar 2003 18:01:12 +0800
From: "James Hou" <happier_tj@hotmail.com>
Subject: Where to find DBD::CSV help?
Message-Id: <b546ec$118t$1@mail.cn99.com>
I searched the document about DBD::CSV in www.cpan.org ,but I found it is
too simple.I don't know how can I open a CSV file and retire data form it.In
the end of this document there is a link for help on the use of DBD::CSV
http://www.isc.org/dbi-lists.html, but I found it is a dead link.Can someone
tell me where can I find a detail document for DBD::CSV.
thanks advance
James Hou
------------------------------
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 4718
***************************************