[29763] in Perl-Users-Digest
Perl-Users Digest, Issue: 1006 Volume: 11
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Nov 6 09:09:48 2007
Date: Tue, 6 Nov 2007 06:09:08 -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 Tue, 6 Nov 2007 Volume: 11 Number: 1006
Today's topics:
Re: Platypus - Current Working Directory - write files <youcontrol@hispeed.ch>
Auction Software ajauctionpro@gmail.com
Encrypt / decrypt <vijay@iavian.com>
Re: Encrypt / decrypt <joe@inwap.com>
Re: File handling and regex <jordilin@gmail.com>
Re: File handling and regex <joe@inwap.com>
Re: File handling and regex <josef.moellers@fujitsu-siemens.com>
Re: Forking problem <joe@inwap.com>
Forum Script ajauctionpro@gmail.com
Re: How to handle fields names in comma separated file? <tadmc@seesig.invalid>
Re: Least Squares <1usa@llenroc.ude.invalid>
Re: Looking for a module (or anything) to grab a webcam <joe@inwap.com>
Perl "Shebang" <bill@ts1000.us>
Re: Perl "Shebang" <1usa@llenroc.ude.invalid>
Re: Perl "Shebang" <josef.moellers@fujitsu-siemens.com>
Re: Perl "Shebang" <krahnj@telus.net>
Re: Platypus - Current Working Directory - write files <joe@inwap.com>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Tue, 6 Nov 2007 13:25:52 +0100
From: Markus S <youcontrol@hispeed.ch>
Subject: Re: Platypus - Current Working Directory - write files
Message-Id: <47305d51@news1-rz-ap.ethz.ch>
On 2007-11-06 5:02, Larry said:
> in Platypus window:
>
> Script Type: Shell
> Script Path: your start.sh
>
> the followin is the start.sh file:
>
> #!/bin/sh
> #
> # start.sh
>
> cd $1/Contents/Resources/
>
> /usr/bin/perl $1/Contents/Resources/my_perl_script.pl
Thanks. Unfortunately, the $1 contains a space in my case and the cd
command therefore fails. I would know how to deal with this within Perl
but not on the Shell level.
(For all others, you can find out about Platypus here:
http://www.sveinbjorn.org/platypus)
------------------------------
Date: Tue, 06 Nov 2007 10:43:37 -0000
From: ajauctionpro@gmail.com
Subject: Auction Software
Message-Id: <1194345817.521342.223750@z9g2000hsf.googlegroups.com>
AJ Auction Pro is the best Auction Portal script software available
in the Universe. Being a PHP /MYSQL Script providing complete online
auction solutions, it has now expanded to offer services such as
Merchant Solutions, Packaged Software and Enterprise Solutions.
Unlike the various majorities of services out there we make a
difference!
AJ Auction Pro Package services comes with all enhanced Auction
features and Global Package services,and excellent Add On facilities
to upgrade your products.
AJ Auction Pro Enterprise Services is an entire suite of applications
and services for building auction websites. It is a variation of every
auction with more enhanced features.Open source code , Elite support
services , Life time license are the highlights here.
http://www.ajauctionpro.com/index.php
------------------------------
Date: Tue, 06 Nov 2007 02:11:02 -0800
From: "vijay@iavian.com" <vijay@iavian.com>
Subject: Encrypt / decrypt
Message-Id: <1194343862.242457.12390@i13g2000prf.googlegroups.com>
How do i do simple encrypt / decrypt of a string with pack and
unpack ?
Thanks
- Teemus
------------------------------
Date: Tue, 06 Nov 2007 03:33:12 -0800
From: Joe Smith <joe@inwap.com>
Subject: Re: Encrypt / decrypt
Message-Id: <HJOdneUf0sFoza3anZ2dnUVZ_hudnZ2d@comcast.com>
vijay@iavian.com wrote:
> How do i do simple encrypt / decrypt of a string with pack and unpack ?
You can't.
pack() and unpack() can do a simple uuencode and uudecode, and MIME base64
with a little more effort, but not cypher-strength encrypt / decrypt.
-Joe
------------------------------
Date: Tue, 06 Nov 2007 11:27:40 -0000
From: jordilin <jordilin@gmail.com>
Subject: Re: File handling and regex
Message-Id: <1194348460.755101.258850@19g2000hsx.googlegroups.com>
On Nov 5, 5:52 pm, "John W. Krahn" <kra...@telus.net> wrote:
> Luca Villa wrote:
>
> > I need help with Perl under Windows command-line to solve the
> > following task:
>
> > I have many disordered txt files and subdirectories under the root
> > directory "c:\dir", like this:
> > c:\dir\foobar.txt
> > c:\dir\popo.txt
> > c:\dir\sub1\agsds.txt
> > c:\dir\sub1\popo.txt
> > c:\dir\sub2\hghghg.txt
> > c:\dir\sub2\subbb\abc.txt
>
> > These txt files are of three types:
> > type1: those that contain a string definable by the regular expression
> > "abc[0-9]+def"
> > type2: those that contain a string definable by the regular expression
> > "lmn[0-9]+opq"
> > type3: those that contain a string definable by the regular expression
> > "rst[0-9]+uvw"
>
> > I would to copy with a Perl Windows command-line script all these txt
> > files into a single directory "c:\output" with the filename composed
> > by the number found in the regex match (the "[0-9]+" part of the
> > regex) and a "-type1.txt" or "-type2.txt" or "-type3.txt" suffix
> > depending of what of the three above regexes are found in the file,
> > obtaining a result looking like this:
> > c:\output\15-type2.txt
> > c:\output\102-type1.txt
> > c:\output\33-type1.txt
> > c:\output\49-type3.txt
> > c:\output\4-type1.txt
> > c:\output\335-type2.txt
> > c:\output\32-type3.txt
>
> > How can I do it?
>
> *UNTESTED* YMMV :-)
>
> #!/usr/bin/perl
> use warnings;
> use strict;
> use File::Find;
> use File::Copy;
>
> my $from = 'c:/dir';
> my $to = 'c:/output';
>
> my %trans = qw(
> abc(\d+)def type1
> lmn(\d+)opq type2
> rst(\d+)uvw type3
> );
>
> find sub {
> return unless open my $fh, '<', $_;
> return unless -f $fh;
> read $fh, my $data, -s _;
> close $fh;
> for my $pat ( keys %trans ) {
> next unless $data =~ $pat;
> copy $File::Find::name, "$to/$1-$trans{$pat}.txt";
> last;
> }
> }, $from;
>
> __END__
>
> John
> --
> use Perl;
> program
> fulfillment
One doubt,
when you write
read $fh, my $data, -s _;
should not be
read $fh, my $data, -s $_;
I have searched along the web without success. I don't know if _
equals $_ in this particular case
best regards,
jordi
------------------------------
Date: Tue, 06 Nov 2007 03:48:39 -0800
From: Joe Smith <joe@inwap.com>
Subject: Re: File handling and regex
Message-Id: <TfidnXf-NJwOya3anZ2dnUVZ_tSknZ2d@comcast.com>
jordilin wrote:
> when you write
> read $fh, my $data, -s _;
> should not be
> read $fh, my $data, -s $_;
>
> I have searched along the web without success. I don't know if _
> equals $_ in this particular case
It does: the bare underscore refers to the most recent file test.
The "unless -f $_;" looks at the directory entity specified by $_
and gets info about it; file-or-directory, size, modification time, etc.
The "-s _" uses that info, without doing another stat() on the file.
The special use of "_" is mentioned in 'perldoc -f stat' and 'perldoc -f -x'.
-Joe
------------------------------
Date: Tue, 06 Nov 2007 13:02:48 +0100
From: Josef Moellers <josef.moellers@fujitsu-siemens.com>
Subject: Re: File handling and regex
Message-Id: <fgpl5c$9kp$1@nntp.fujitsu-siemens.com>
jordilin wrote:
> On Nov 5, 5:52 pm, "John W. Krahn" <kra...@telus.net> wrote:
>=20
>>Luca Villa wrote:
>>
>>
>>>I need help with Perl under Windows command-line to solve the
>>>following task:
>>
>>>I have many disordered txt files and subdirectories under the root
>>>directory "c:\dir", like this:
>>>c:\dir\foobar.txt
>>>c:\dir\popo.txt
>>>c:\dir\sub1\agsds.txt
>>>c:\dir\sub1\popo.txt
>>>c:\dir\sub2\hghghg.txt
>>>c:\dir\sub2\subbb\abc.txt
>>
>>>These txt files are of three types:
>>>type1: those that contain a string definable by the regular expression=
>>>"abc[0-9]+def"
>>>type2: those that contain a string definable by the regular expression=
>>>"lmn[0-9]+opq"
>>>type3: those that contain a string definable by the regular expression=
>>>"rst[0-9]+uvw"
>>
>>>I would to copy with a Perl Windows command-line script all these txt
>>>files into a single directory "c:\output" with the filename composed
>>>by the number found in the regex match (the "[0-9]+" part of the
>>>regex) and a "-type1.txt" or "-type2.txt" or "-type3.txt" suffix
>>>depending of what of the three above regexes are found in the file,
>>>obtaining a result looking like this:
>>>c:\output\15-type2.txt
>>>c:\output\102-type1.txt
>>>c:\output\33-type1.txt
>>>c:\output\49-type3.txt
>>>c:\output\4-type1.txt
>>>c:\output\335-type2.txt
>>>c:\output\32-type3.txt
>>
>>>How can I do it?
>>
>>*UNTESTED* YMMV :-)
>>
>>#!/usr/bin/perl
>>use warnings;
>>use strict;
>>use File::Find;
>>use File::Copy;
>>
>>my $from =3D 'c:/dir';
>>my $to =3D 'c:/output';
>>
>>my %trans =3D qw(
>> abc(\d+)def type1
>> lmn(\d+)opq type2
>> rst(\d+)uvw type3
>> );
>>
>>find sub {
>> return unless open my $fh, '<', $_;
>> return unless -f $fh;
>> read $fh, my $data, -s _;
>> close $fh;
>> for my $pat ( keys %trans ) {
>> next unless $data =3D~ $pat;
>> copy $File::Find::name, "$to/$1-$trans{$pat}.txt";
>> last;
>> }
>> }, $from;
>>
>>__END__
>>
>>John
>>--
>>use Perl;
>>program
>>fulfillment
>=20
>=20
> One doubt,
> when you write
> read $fh, my $data, -s _;
> should not be
> read $fh, my $data, -s $_;
>=20
> I have searched along the web without success. I don't know if _
> equals $_ in this particular case
No, it doesn't, at least not "literally" or conceptually.
"_" is the special filehandle which refers to the filehandle used in the =
most recently used stat operation:
"If any of the file tests (or either the "stat" or "lstat" operators)=20
are given the special filehandle consisting of a solitary underline,=20
then the stat structure of the previous file test (or stat operator) is=20
used, saving a system call."
(perldoc -f -s)
--=20
These are my personal views and not those of Fujitsu Siemens Computers!
Josef M=F6llers (Pinguinpfleger bei FSC)
If failure had no penalty success would not be a prize (T. Pratchett)
Company Details: http://www.fujitsu-siemens.com/imprint.html
------------------------------
Date: Tue, 06 Nov 2007 04:12:16 -0800
From: Joe Smith <joe@inwap.com>
Subject: Re: Forking problem
Message-Id: <tpGdna6Y0auBx63anZ2dnUVZ_hOdnZ2d@comcast.com>
David Knell wrote:
> while (1) {
> if ($fs->accept("127.0.0.1", $socket)) {
> $pid = fork();
> last if ((defined($pid)) && ($pid == 0));
> }
> }
> ..rest of code..
You could borrow some of the logic from
http://www.inwap.com/mybin/miscunix/list-files.pl?tcp-proxy
Grandparent is in a while(1){} loop accepting incoming connections.
Grandparent creates a short-lived process that exits after creating
two child processes. "A" only reads from socket, "B" only writes to socket.
The two child processes are no longer connected to the long-lived grandparent;
they have PPID = 1 which means they will get reaped automatically.
-Joe
------------------------------
Date: Tue, 06 Nov 2007 10:41:41 -0000
From: ajauctionpro@gmail.com
Subject: Forum Script
Message-Id: <1194345701.956272.225610@22g2000hsm.googlegroups.com>
AJForum is a professional, powerful, scalable and fully customizable
forums package. It has unlimited categories and forums, read only
forums, Smilies, very friendly bulletin board program and most
important easy set-up.
http://www.ajsquare.com/products/forum/index.php
------------------------------
Date: Tue, 06 Nov 2007 12:02:19 GMT
From: Tad McClellan <tadmc@seesig.invalid>
Subject: Re: How to handle fields names in comma separated file?
Message-Id: <slrnfj0lqr.7db.tadmc@tadmc30.sbcglobal.net>
rthangam <ramesh.thangamani@gmail.com> wrote:
>
> somebody wrote:
>> I have a comma separated file with hundreds of field names. For the sake
>> of brevity, let's assume there are only a name, address, city, and state
>> field. I currently have the field names defined as scalars in an array
>> like:
>>
>> my @fields = (
>> my $NAME,
>> my $ADDRESS,
>> my $CITY,
>> my $STATE
>> );
>>
>>
>> This allows me to assign all of the fields to an array element in one
>> line as with the split function below. The problem with this is that
>> the field names are then known only as $fields[0], $fields[1], etc.
>> Is there a better way to handle field names in a csv file?
>>
>>
>> while ( <DATA> ) {
>>
>> chomp;
>>
>> my(@fields) = split /\,/;
>>
>> print "$fields[0]\n";
>> print "$fields[1]\n";
>> print "$fields[2]\n";
>> print "$fields[3]\n";
>
> You can store them in a hash that is better:
>
> like
>
> my %hash;
>
> $hash{NAME} = $fields[0];
And use a "hash slice" (perldoc perldata) to load them all up in one go:
my @fnames = qw/name address city state/;
my %record;
@record{ @fnames } = split /,/;
--
Tad McClellan
email: perl -le "print scalar reverse qq/moc.noitatibaher\100cmdat/"
------------------------------
Date: Tue, 06 Nov 2007 13:03:50 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: Least Squares
Message-Id: <Xns99E0520672629asu1cornelledu@127.0.0.1>
"alexxx.magni@gmail.com" <alexxx.magni@gmail.com> wrote in
news:1194335960.669911.315710@y42g2000hsy.googlegroups.com:
> On 6 Nov, 00:24, "A. Sinan Unur" <1...@llenroc.ude.invalid> wrote:
>> "alexxx.ma...@gmail.com" <alexxx.ma...@gmail.com> wrote
>> innews:1194290793.569055.310260@o38g2000hse.googlegroups.com:
>>
>> > I need to perform a huge number of Least Squares Fits to my data,
>> > using probably something like a+b*Atan(c-d*x) as the fitting
>> > function. Can you suggest me the fastest package on CPAN, according
>> > to you?
>>
>> First off, if you can't reduce that functional form to a form that is
>> linear in parameters, you are going to need to resort to numerical
>> optimization.
>
> It could be still OK for me - do you know of any module able to do
> this?
No.
>> Second, I would be more inclined to open a pipe to R or Octave (I
>> have no idea if they can do this particular estimation) for any
>> serious statistics.
>
> I'm not an expert on R/Octave, but sometimes I tried linking C and
> Mathematica - I dont know if Perl can handle this...
Perl can handle all sorts of things but at this point your problem
is too ambiguously specified. Anything I say will be pure speculation
and likely wrong for your problem.
>> Finally, you do not mention what you mean by 'fast'.
>
> Well, the project involves the processing of simple PGM images (0..255
> graylevels) of an interface swapping the image, turning it from black
> to white.
> So every pixel of the 691x517 images (300 of them!) will behave in
> time (time=1..300) approximately as a step function (thats why I use
> Atan) with noise overimposed.
> I "simply" need to know, for every pixel, at which time the step
> appears, to be able to precisely reconstruct the interface.
> ... that's what I meant by "fast"!
Again, this is too ambiguous for me. What is x and what is y in the
equation you specified above? What does it mean to
'reconstruct the interface'?
Take a look at:
http://cran.r-project.org/doc/contrib/Fox-Companion/appendix-nonlinear-regression.pdf
Read perldoc perlipc and perldoc IPC::Open3. I would be inclined to
open a pipe to an external program (such as R) at the beginning of your
script and let that program perform the computations.
Sinan
--
A. Sinan Unur <1usa@llenroc.ude.invalid>
(remove .invalid and reverse each component for email address)
clpmisc guidelines: <URL:http://www.augustmail.com/~tadmc/clpmisc.shtml>
------------------------------
Date: Tue, 06 Nov 2007 04:49:00 -0800
From: Joe Smith <joe@inwap.com>
Subject: Re: Looking for a module (or anything) to grab a webcam image
Message-Id: <PZ6dnSqWX4Uk_63anZ2dnUVZ_t6onZ2d@comcast.com>
PB wrote:
> Is there any perl-ish way to capture a USB webcam image and save it to a
> file?
my $jpeg_data = `vendor_provided_capture_program.exe`;
Very perlish: take the lazy way out when there's an existing program
that will do the dirty work for you.
-Joe
------------------------------
Date: Tue, 06 Nov 2007 04:59:29 -0800
From: Bill H <bill@ts1000.us>
Subject: Perl "Shebang"
Message-Id: <1194353969.307648.288080@o80g2000hse.googlegroups.com>
Can anyone tell me what the "--" means in this line:
#!/usr/bin/perl --
This is part of a forum script (YaBB). I haven't see just -- before
Bill H
------------------------------
Date: Tue, 06 Nov 2007 13:06:03 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: Perl "Shebang"
Message-Id: <Xns99E05266D686Basu1cornelledu@127.0.0.1>
Bill H <bill@ts1000.us> wrote in news:1194353969.307648.288080
@o80g2000hse.googlegroups.com:
> Can anyone tell me what the "--" means in this line:
>
> #!/usr/bin/perl --
>
> This is part of a forum script (YaBB). I haven't see just -- before
C:\Temp> perl -h
Usage: C:\opt\Perl\bin\perl.exe [switches] [--] [programfile] [arguments]
Clearly, it marks the end of command line switches.
My guess is, YaBB authors used it to protect against accidental binary FTP
transfers between Windows and Unix EOL based systems mucking up the shebang
line.
Sinan
--
A. Sinan Unur <1usa@llenroc.ude.invalid>
(remove .invalid and reverse each component for email address)
clpmisc guidelines: <URL:http://www.augustmail.com/~tadmc/clpmisc.shtml>
------------------------------
Date: Tue, 06 Nov 2007 14:07:55 +0100
From: Josef Moellers <josef.moellers@fujitsu-siemens.com>
Subject: Re: Perl "Shebang"
Message-Id: <fgpovh$nfc$1@nntp.fujitsu-siemens.com>
Bill H wrote:
> Can anyone tell me what the "--" means in this line:
>=20
> #!/usr/bin/perl --
>=20
> This is part of a forum script (YaBB). I haven't see just -- before
Usually '--' on a command line means that anything after that will *not* =
be considered an option, even if it begins with '-'.
I don't know YaBB and how it calls the script, but I guess that the=20
script might be called with additional parameters which may be provided=20
by the user, and this construct prevents the unwanted interpretation of=20
a leading '-' in the first argument.
--=20
These are my personal views and not those of Fujitsu Siemens Computers!
Josef M=F6llers (Pinguinpfleger bei FSC)
If failure had no penalty success would not be a prize (T. Pratchett)
Company Details: http://www.fujitsu-siemens.com/imprint.html
------------------------------
Date: Tue, 06 Nov 2007 13:31:04 GMT
From: "John W. Krahn" <krahnj@telus.net>
Subject: Re: Perl "Shebang"
Message-Id: <47306C62.4C2841A4@telus.net>
Bill H wrote:
>
> Can anyone tell me what the "--" means in this line:
>
> #!/usr/bin/perl --
>
> This is part of a forum script (YaBB). I haven't see just -- before
On the command line it means that there are no more program switches
(options) to the right of --, everything following -- is data only.
In a program like that it is used as a guard against extraneous
whitespace confusing the operating system. For example, if you edit the
script in Windows and then try to run it in *nix.
John
--
use Perl;
program
fulfillment
------------------------------
Date: Tue, 06 Nov 2007 03:38:38 -0800
From: Joe Smith <joe@inwap.com>
Subject: Re: Platypus - Current Working Directory - write files
Message-Id: <C_CdneXhxM-mz63anZ2dnUVZ_jOdnZ2d@comcast.com>
Tad McClellan wrote:
> What â € ™ s wrong with always quoting "$vars"?
Tad,
The headers on your posting says
Mime-Version: 1.0
Content-Type: text/plain; charset=iso-8859-1
Content-Transfer-Encoding: 8bit
User-Agent: slrn/0.9.8.1pl1 (Linux)
yet the article body has UTF-8 characters.
-Joe
------------------------------
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 1006
***************************************