[24671] in Perl-Users-Digest
Perl-Users Digest, Issue: 6835 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Aug 4 21:05:52 2004
Date: Wed, 4 Aug 2004 18:05:09 -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 Wed, 4 Aug 2004 Volume: 10 Number: 6835
Today's topics:
Re: 0 + 1 not an integer? <abigail@abigail.nl>
Re: @platforms = (sort keys %prj_platforms) || (DEFAULT <abigail@abigail.nl>
Re: @platforms = (sort keys %prj_platforms) || (DEFAULT (Anno Siegel)
Re: @platforms = (sort keys %prj_platforms) || (DEFAULT <abigail@abigail.nl>
Re: @platforms = (sort keys %prj_platforms) || (DEFAULT <uri@stemsystems.com>
Re: any resources to assist with why perl is better? <abigail@abigail.nl>
Re: any resources to assist with why perl is better? <ken_sington@nospam_abcdefg.com>
Re: Breaking out of nested subroutine? <null@example.net>
Re: Breaking out of nested subroutine? <abigail@abigail.nl>
Breakpoint on a builtin? <spam.keith.me.arner.not@marconi.com>
Re: CGI file ownership <null@example.net>
Re: creating shell scripts using #!/usr/local/env perl <Juha.Laiho@iki.fi>
Re: CRLF problem with DOS files (Anno Siegel)
Re: CRLF problem with DOS files <noemail@#$&&!.net>
Re: CRLF problem with DOS files <noemail@#$&&!.net>
Re: delimited data into nested array <noreply@gunnar.cc>
Re: getting line between 2 patterns (Anno Siegel)
Re: getting Values out of <Array> (Charles DeRykus)
if ( $a eq 1 || $b eq 2...) <ken_sington@nospam_abcdefg.com>
Re: join on space instead of comma <bowsayge@nomail.afraid.org>
Re: join on space instead of comma <bowsayge@nomail.afraid.org>
Re: Kqueue interface module implementation <uri@stemsystems.com>
Re: name of perl jobs newsgroup? <uri@stemsystems.com>
Re: recursive functions (Anno Siegel)
Re: recursive functions <thundergnat@hotmail.com>
Using MIME::Lite in Windows to send email with a zip at (James)
Re: Using MIME::Lite in Windows to send email with a zi <mritty@gmail.com>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 04 Aug 2004 21:46:24 GMT
From: Abigail <abigail@abigail.nl>
Subject: Re: 0 + 1 not an integer?
Message-Id: <slrnch2m9g.ec9.abigail@alexandra.abigail.nl>
Philip (noone@nowhere.org) wrote on MMMCMXCI September MCMXCIII in
<URL:news:1091627360.112056@cswreg.cos.agilent.com>:
][ Hi, I am writing a SWIG 1.3 interface to some C++ libraries.
][
][ I have a C++ method that goes like:
][
][ class MyClass {
][
][ Object Col(int);
][ Object Col(const char *);
][ :
][ }
][
][ The SWIG overloading mechanism uses SvIOK to test whether to call the first or
][ the second method.
][
][ I find that if I call Col(() from perl like so:
][
][ $intgr = 0;
][ $intgr++;
][ $myclass->Col($intgr);
][
][ It fails because SvIOK fails. Apparent $intgr becomes a number and is no longer
][ an integer.
Really? Devel::Peek thinks otherwise:
$ perl -MDevel::Peek -we 'my $intgr = 0; $intgr ++; Dump ($intgr)'
SV = IV(0x818da54) at 0x817f754
REFCNT = 1
FLAGS = (PADBUSY,PADMY,IOK,pIOK)
IV = 1
Abigail
--
perl -wle'print"Κυστ αξοτθες Πεςμ Θαγλες"^"\x80"x24'
------------------------------
Date: 04 Aug 2004 21:52:57 GMT
From: Abigail <abigail@abigail.nl>
Subject: Re: @platforms = (sort keys %prj_platforms) || (DEFAULT);
Message-Id: <slrnch2mlp.ec9.abigail@alexandra.abigail.nl>
A. Farber (Alexander.Farber@t-online.de) wrote on MMMCMXCI September
MCMXCIII in <URL:news:c9ccaf83.0408040704.2ac7e6f5@posting.google.com>:
!! Hi,
!!
!! I must confess, that I don't fully understand the
!! difference between an array and a list and suspect
!! that the cause for my problem lies somewhere there...
!!
!! Could someone please explain, why does the code below warns
!! "Useless use of sort in scalar context at ./test_case.pl"?
!!
!! #!/usr/bin/perl -w
!! use constant DEFAULT => qw(ARMI ARM4 THUMB WINS WINSCW);
!! @platforms = (sort keys %prj_platforms) || (DEFAULT);
The problem with your code has nothing whatsoever to do with array
vs list. The problem is context. The '||' operator provides scalar
context to its left operand. Which means that 'sort keys %prj_platforms'
is performed in scalar context. But since noone has come up with a good
idea of what sort in scalar context should do, a warning is produced
because it's highly unlikely the programmer wanted to sort in scalar
context. And I don't think you want that.
What you probably want is:
@platforms = keys %prj_platforms ? sort keys %prj_platforms : DEFAULT;
Abigail
--
perl -le 's[$,][join$,,(split$,,($!=85))[(q[0006143730380126152532042307].
q[41342211132019313505])=~m[..]g]]e and y[yIbp][HJkP] and print'
------------------------------
Date: 4 Aug 2004 22:09:46 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: @platforms = (sort keys %prj_platforms) || (DEFAULT);
Message-Id: <cermra$h18$1@mamenchi.zrz.TU-Berlin.DE>
Abigail <abigail@abigail.nl> wrote in comp.lang.perl.misc:
> @platforms = keys %prj_platforms ? sort keys %prj_platforms : DEFAULT;
The first "keys" could go.
Anno
------------------------------
Date: 04 Aug 2004 22:38:55 GMT
From: Abigail <abigail@abigail.nl>
Subject: Re: @platforms = (sort keys %prj_platforms) || (DEFAULT);
Message-Id: <slrnch2pbv.ec9.abigail@alexandra.abigail.nl>
Anno Siegel (anno4000@lublin.zrz.tu-berlin.de) wrote on MMMCMXCI
September MCMXCIII in <URL:news:cermra$h18$1@mamenchi.zrz.TU-Berlin.DE>:
:) Abigail <abigail@abigail.nl> wrote in comp.lang.perl.misc:
:)
:) > @platforms = keys %prj_platforms ? sort keys %prj_platforms : DEFAULT;
:)
:) The first "keys" could go.
Yeah, it could, but I always forget %prj_platforms in scalar context
returns just a number, and not a string if it's empty.
Abigail
--
perl -wle 'eval {die ["Just another Perl Hacker"]}; print ${$@}[$#{@${@}}]'
------------------------------
Date: Thu, 05 Aug 2004 01:03:34 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: @platforms = (sort keys %prj_platforms) || (DEFAULT);
Message-Id: <x78ycu4cry.fsf@mail.sysarch.com>
>>>>> "PG" == Paul GABORIT <Paul.Gaborit@invalid.invalid> writes:
PG> Use :
PG> (@platforms = sort keys %prj_platforms) || (@platforms = DEFAULT);
PG> or :
PG> @platforms = sort keys %platforms or @platforms = DEFAULT;
those are both very poor coding IMO. hard to read and not clear what is
going on. i would break it up into 2 lines:
@platforms = sort keys %platforms ;
@platforms = DEFAULT unless @platforms ;
simple and clear
uri
--
Uri Guttman ------ uri@stemsystems.com -------- http://www.stemsystems.com
--Perl Consulting, Stem Development, Systems Architecture, Design and Coding-
Search or Offer Perl Jobs ---------------------------- http://jobs.perl.org
------------------------------
Date: 04 Aug 2004 21:03:47 GMT
From: Abigail <abigail@abigail.nl>
Subject: Re: any resources to assist with why perl is better?
Message-Id: <slrnch2jpj.ec9.abigail@alexandra.abigail.nl>
davout (davZZZYYYXXXout@dial.pipex.com) wrote on MMMCMXCI September
MCMXCIII in <URL:news:41111c01$0$26982$cc9e4d1f@news.dial.pipex.com>:
[] Can anybody help point me at some web resources that explain why Perl is
[] better than say Python, TCL etc?
What makes you think Perl is better than Python or TCL?
I don't think question like yours are sensible questions.
Abigail
--
perl5.004 -wMMath::BigInt -e'$^V=Math::BigInt->new(qq]$^F$^W783$[$%9889$^F47]
.qq]$|88768$^W596577669$%$^W5$^F3364$[$^W$^F$|838747$[8889739$%$|$^F673$%$^W]
.qq]98$^F76777$=56]);$^U=substr($]=>$|=>5)*(q.25..($^W=@^V))=>do{print+chr$^V
%$^U;$^V/=$^U}while$^V!=$^W'
------------------------------
Date: Wed, 04 Aug 2004 21:00:16 -0400
From: Ken Sington <ken_sington@nospam_abcdefg.com>
Subject: Re: any resources to assist with why perl is better?
Message-Id: <65OdnUDVPdA8G4zcRVn-rg@speakeasy.net>
davout wrote:
> Can anybody help point me at some web resources that explain why Perl is
> better than say Python, TCL etc?
>
>
Aren't they different tools?
I also think the argument that Linux is better than MS Windows is a bad comparison.
They're different tools.
------------------------------
Date: Wed, 04 Aug 2004 22:47:00 GMT
From: Rich Grise <null@example.net>
Subject: Re: Breaking out of nested subroutine?
Message-Id: <EHdQc.17471$QA5.9077@nwrddc01.gnilink.net>
Abigail wrote:
> Mladen Gogala (gogala@sbcglobal.net) wrote on MMMCMLXXXVIII September
> MCMXCIII in <URL:news:pan.2004.08.01.21.41.32.669513@sbcglobal.net>:
> ** On Sat, 31 Jul 2004 23:21:47 +0000, Abigail wrote:
> **
> ** > Well, I find 'goto' in C programs quite handy. In Perl too, except I
> ** > usually spell 'goto' as 'redo', 'next' or 'last'.
> **
> ** It's not the same thing. The "C" equivalent of "next" is "continue",
> ** equivalent of "last" is "break", while C doesn't have an equivalent of
> ** "redo".
>
> I never claimed otherwise. I use 'goto' in C programs. I use 'next',
> 'last', and 'redo' in Perl programs. That's what I said. How you turn that
> into me claiming that C has 'next', 'last', or 'redo', I don't know.
Well, you did say this:
<quote from a couple of posts ago>
Well, I find 'goto' in C programs quite handy. In Perl too, except I
usually spell 'goto' as 'redo', 'next' or 'last'.
[extraneous snipe snipped]
Abigail
</quote>
And it sounds like you're cavalierly claiming that C's continue; and
break; statements are functionally equivalent to a goto, but they're
not.
Hope This Helps!
Rich
------------------------------
Date: 04 Aug 2004 22:53:54 GMT
From: Abigail <abigail@abigail.nl>
Subject: Re: Breaking out of nested subroutine?
Message-Id: <slrnch2q81.ec9.abigail@alexandra.abigail.nl>
Rich Grise (null@example.net) wrote on MMMCMXCI September MCMXCIII in
<URL:news:EHdQc.17471$QA5.9077@nwrddc01.gnilink.net>:
** Abigail wrote:
**
** > Mladen Gogala (gogala@sbcglobal.net) wrote on MMMCMLXXXVIII September
** > MCMXCIII in <URL:news:pan.2004.08.01.21.41.32.669513@sbcglobal.net>:
** > ** On Sat, 31 Jul 2004 23:21:47 +0000, Abigail wrote:
** > **
** > ** > Well, I find 'goto' in C programs quite handy. In Perl too, except I
** > ** > usually spell 'goto' as 'redo', 'next' or 'last'.
** > **
** > ** It's not the same thing. The "C" equivalent of "next" is "continue",
** > ** equivalent of "last" is "break", while C doesn't have an equivalent of
** > ** "redo".
** >
** > I never claimed otherwise. I use 'goto' in C programs. I use 'next',
** > 'last', and 'redo' in Perl programs. That's what I said. How you turn that
** > into me claiming that C has 'next', 'last', or 'redo', I don't know.
**
** Well, you did say this:
** <quote from a couple of posts ago>
** Well, I find 'goto' in C programs quite handy. In Perl too, except I
** usually spell 'goto' as 'redo', 'next' or 'last'.
** [extraneous snipe snipped]
** Abigail
** </quote>
**
** And it sounds like you're cavalierly claiming that C's continue; and
** break; statements are functionally equivalent to a goto, but they're
** not.
Really? I read what you quote a couple of times, but I see no mentioning
of 'continue' or 'break' in there.
Abigail
--
perl -wle 'eval {die ["Just another Perl Hacker"]}; print ${$@}[$#{@${@}}]'
------------------------------
Date: Wed, 4 Aug 2004 15:51:57 -0400
From: Keith NoSpam Arner <spam.keith.me.arner.not@marconi.com>
Subject: Breakpoint on a builtin?
Message-Id: <Pine.GSO.4.42.0408041550040.15519-100000@zimbra>
Is there a way in the perl debugger to set a breakpoint on a builtin
function?
I currently have a script that is deleting a file, and I want to know why
it has decided to delete the file. I'd like to set a breakpoint on the
'unlink' function, so I can catch the caller, and do the whole debugging
thing. However, when I try this, I get:
DB<1> b unlink
Subroutine main::unlink not found.
Do the builtin functions reside in a special namespace that will allow me
to, e.g., 'b special::unlink', or some such? Or is there some other,
special notation that I can use?
Thanks,
Keith
--
In questions of science, the authority of a thousand is not worth the
humble reasoning of a single individual.
-Galileo Galilei
------------------------------
Date: Wed, 04 Aug 2004 22:58:27 GMT
From: Rich Grise <null@example.net>
Subject: Re: CGI file ownership
Message-Id: <nSdQc.17477$QA5.14987@nwrddc01.gnilink.net>
Andrew wrote:
> Hi all and thanks for any help given!,
> I am currently building a web page with cgi's that create text files
> to store data. When it does this it is saving the file with ownership
> of apache, and i want to change the ownership of the file to a lesser
> owner (the one where the webpage is stored). I have tried some comands
> and variations of the commands with no sucess!. is there anyone that
> knows how to change the ownership (hardlink) to a lesser owner?, if so
> could you please provide the line of code and how it works =)
> Thanks Heaps
> Andrew
This is not a perl question.
Every time I've ever run a CGI, it's run as nobody, and the file ownership
is nobody. I don't know how it's done, because it's just been that way
on every system I've done CGI on, but I'm guessing it has something to
do with either Apache's config or its invocation.
In other words, it happens completely outside the scope of your script.
try man httpd .
Good Luck!
Rich
------------------------------
Date: Wed, 04 Aug 2004 18:57:03 GMT
From: Juha Laiho <Juha.Laiho@iki.fi>
Subject: Re: creating shell scripts using #!/usr/local/env perl
Message-Id: <cerbgk$j3g$2@ichaos.ichaos-int>
merlyn@stonehenge.com (Randal L. Schwartz) said:
>Argh! What did they do *that* for? That's crazy!
>
>The only reason "env" exists is because the brain-dead csh can't add
>arbitrary env vars per command.
Hmm.. rather hard to duplicate functionality of 'env - command', I'd
say. Not that I've ever used that form, but still - that would be one
use of env even for Bourne shells.
--
Wolf a.k.a. Juha Laiho Espoo, Finland
(GC 3.0) GIT d- s+: a C++ ULSH++++$ P++@ L+++ E- W+$@ N++ !K w !O !M V
PS(+) PE Y+ PGP(+) t- 5 !X R !tv b+ !DI D G e+ h---- r+++ y++++
"...cancel my subscription to the resurrection!" (Jim Morrison)
------------------------------
Date: 4 Aug 2004 20:03:04 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: CRLF problem with DOS files
Message-Id: <cerfdo$chs$2@mamenchi.zrz.TU-Berlin.DE>
Brian McCauley <nobull@mail.com> wrote in comp.lang.perl.misc:
> Fred <noemail@#$&&!.net> writes:
>
> > I know this topic has been covered rather much but I couldn't find my
> > specific question answered.
> >
> > Here is the code:
> >
> > # we are trying to make '0d 0a' in the output file be # only a '0a'
[...]
> > $Fld1 =~ s/\cM//g;
> > &Open_File( '>>', $filename ); # returns fh as filehandle
>
> Do not use & to call subroutines unless you know what it means and
> want those semantics.
>
> Returning the file handle using a shared variable is ugly, ugly, ugly.
>
> > binmode $fh ; # open the binmode file and write to it;
>
> Er, what is the meaning of that comment?
Whatever it is supposed to mean, it is true that a file is opened
here, though a line earlier. According to another comment a few lines
down, this happens in a loop (over $Fld1, presumably). This is a very
bad idea, even if opening in append mode seems to make it work. The
output handle ought to be opened ahead of the loop.
> > ( printf $fh "%s\r", $Fld1;)
> > $count++; # counting lines... this is all in a while loop
[...]
Anno
------------------------------
Date: Wed, 04 Aug 2004 18:07:32 +0000
From: Fred <noemail@#$&&!.net>
Subject: Re: CRLF problem with DOS files
Message-Id: <pan.2004.08.04.18.07.31.821739@#$&&!.net>
I am new to perl but not programming. At any rate I got it working. The
trick was indeed binmode(), and while the file was open using the default
variable do: tr/\n\r//d;
That would not work except in binmode(). Don't hold me to it, I'm at home
now (beers++) but after that tr call then I just did printf'ed to the
file, and the binary mode thing caused windos/dos to backoff, and leave my
line termination characters alone.
Actually for the sake of posterity, I will post all my code tomorrow.
I got it working!!!
Thanks to each of you who offered your generous help. It is very
appreciated.
------------------------------
Date: Wed, 04 Aug 2004 18:10:50 +0000
From: Fred <noemail@#$&&!.net>
Subject: Re: CRLF problem with DOS files
Message-Id: <pan.2004.08.04.18.10.50.656582@#$&&!.net>
"The output handle ought to be opened ahead of the loop."
You know, I know that. Why continually open a file handle, the overhead
would be extreme. So I'll keep HACKING on this thing and perhaps when a
frost visits purgatory, I'll have it down!!
:)
Thank you for you help!!!
------------------------------
Date: Wed, 04 Aug 2004 22:37:11 +0200
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: delimited data into nested array
Message-Id: <2ncvv7Fver2mU1@uni-berlin.de>
krakle wrote:
> Gunnar Hjalmarsson wrote:
>> How about this instead:
>>
>> #!/usr/local/bin/perl
> > use strict;
>> use warnings;
>
> How about this instead:
> #!/usr/local/bin/perl -Tw
Why would you use the -w switch when warnings are enabled through the
warnings pragma? As regards -T, it's not a CGI script, and the OP did
not indicate anything else that would make -T motivated. For what
reason did you suggest it?
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
------------------------------
Date: 4 Aug 2004 19:43:35 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: getting line between 2 patterns
Message-Id: <cere97$chs$1@mamenchi.zrz.TU-Berlin.DE>
mike <s99999999s2003@yahoo.com> wrote in comp.lang.perl.misc:
> anno4000@lublin.zrz.tu-berlin.de (Anno Siegel) wrote in message
> news:<ceqb79$iqg$1@mamenchi.zrz.TU-Berlin.DE>...
> > John W. Krahn <someone@example.com> wrote in comp.lang.perl.misc:
> > > mike wrote:
> > > >
> > > > i have a file like this:
> > > >
> > > > 2004nddjjf99jdlkdf <---- 99 is at character position 11 to 12
> > > > 2004abcdefghijklnmnopqrstuvwxyz
> > > > 2004ldfhanvsduhkjgndfnspqiekfnv
> > > > 2003nmvkdmcnfjfbndmdkvndnmvkdbn
> > > > 2004nddgdf99dkgfjs
> > > >
> > > > i wanted to get the text in between the 2 lines that have the number
> > > > "99" at the
> > > > 11th and 12th position.
> > > >
> > > > i looked at FAQ ,
> > > >
> > > > perl -ne 'print if /START/ .. /END/' file1 ...
> > > >
> > > > how can i define the START and END such that it must check for
> > > > character position 11 and 12 to look for 99 ??
> > >
> > > perl -ne 'print if /^.{10}99/ ... /^.{10}99/' file1 ...
> >
> > That prints the delimitling lines (the ones that contain "99").
> > Depending on what the OP means by "in between", it might be
> > necessary to do
> >
> > perl -ne 'print if /^.{10}99/ ... /^.{10}99/ and not /^.{10}99/' file1
> >
> > Anno
>
>
> thanks for the advise.
>
> I have another requirement
>
> 2004nddjjf99jdlkdf <---- first location that have '99' at char pos
> 11-12
> 2004abcdefghijklnmnopqrstuvwxyz
> 2004ldfhanvsduhkjgndfnspqiekfnv
> 2003nmvkdmcnfjfbndmdkvndnmvkdbn
> 2004nddgdf99dkgfjs <----------- (2)
> 2001lksdnvnvkxlxmncxkxlxknlxxcl
> 1999kldkdkfsksjdkjvkjslkjdflkjl
> 2002nodmen99ddklss <------------(3)
>
> I wanted to get the text between the first location ( where '99' is at
> char pos 11-12 ) and the second location (2), then put the text into a
> file.
> Then get the text between (2) and (3) and put to another file.
> I have no idea how to keep track of the lines that have '99' at pos
> 11-12.
> Any advise? A "psuedocode" would be a great help, cos i want to try to
> code the rest of it myself...
> thanks...
Your "additional requirement" makes this another problem altogether.
Apparently, you want to switch output files (and ignore the line)
whenever "99" appears in a certain position.
So let's say you want to number the output files "out_01" .. "out_99".
Untested:
my $file = 'out_01';
open my $out, '>', $file or die "Can't create $file: $!";
while ( <$in> ) {
if ( substr( $_, 11, 2) eq '99' ) {
$file ++; # magic string increment
open $out, '>', $file or die "Can't create $file: $!";
} else {
print $out, $_;
}
}
Anno
------------------------------
Date: Wed, 4 Aug 2004 18:20:24 GMT
From: ced@bcstec.ca.boeing.com (Charles DeRykus)
Subject: Re: getting Values out of <Array>
Message-Id: <I1xpM0.Mv1@news.boeing.com>
In article <GFIPc.21595$g4.409960@news2.nokia.com>,
Noname <Some.One@hotmail.com> wrote:
>I am not able to find any litrature on
>why?
>$Value="@Array" gives the values from an array
perldoc perldata
From above doc:
Arrays and slices are interpolated into double-quoted
strings by joining the elements with the delimiter specified
in the "$"" variable ("$LIST_SEPARATOR" in English), space
by default. The following are equivalent:
$temp = join($", @ARGV);
system "echo $temp";
system "echo @ARGV";
--
Charles DeRykus
------------------------------
Date: Wed, 04 Aug 2004 20:53:41 -0400
From: Ken Sington <ken_sington@nospam_abcdefg.com>
Subject: if ( $a eq 1 || $b eq 2...)
Message-Id: <vJmdnbh-yuSIGIzcRVn-jQ@speakeasy.net>
this is starting to bother me:
if (
$req =~ /\.html$/ ||
$req =~ /\.pl$/ ||
$req =~ /\.shtml$/ ||
$req =~ /\.txt$/ ||
$req =~ /\.cgi$/ ||
$req =~ /\.cgi\?/ ||
$req =~ /\/\?/ ||
$req =~ /\/$/
) {
$countPage++;
}
there's got to be a better way.
------------------------------
Date: Thu, 05 Aug 2004 01:03:20 GMT
From: bowsayge <bowsayge@nomail.afraid.org>
Subject: Re: join on space instead of comma
Message-Id: <sHfQc.427$nx2.258@newsread2.news.atl.earthlink.net>
Anno Siegel said to us:
> bowsayge <bowsayge@nomail.afraid.org> wrote in comp.lang.perl.misc:
>>
>> You can extract substrings from your input lines like so:
>
> Ah, you're learning fast. This begins to look like Perl code :)
[...]
Thanks. Reading yours and other people's posts surely helps :-)
>> my (@lines, @fields) = (<>);
>
> You don't need to declare @fields here. Instead, declare it in the
> smallest possible scope, which would be the loop body.
[...]
Yes, Brian told me about that too.
> "pack" and "unpack" and their formats are a sub-language of its own.
I used unpack before when I needed to convert some hex data into
a binary string, but I forgot that it can return lists, and I
forgot that it can move characters without converting.
Thanks.
--
my (@str) = split //,'ihnseb pa rretwnJt uoel.e';
my (@ndx, @arr) = qw(22 9 18 2 23 21 4 13 5 12 15 11 14
8 20 6 0 3 17 1 7 19 16 24 10);
$arr[$ndx[$_]] = $str[$_] for (@ndx); print @arr, "\n";
------------------------------
Date: Thu, 05 Aug 2004 01:03:21 GMT
From: bowsayge <bowsayge@nomail.afraid.org>
Subject: Re: join on space instead of comma
Message-Id: <tHfQc.428$nx2.398@newsread2.news.atl.earthlink.net>
Brian McCauley said to us:
[...]
> Isn't @fields being declared at the wrong scope anyhow - it should be
> inside the loop.
[...]
You're right. Vestiges of C habits are still with me :-)
>> $fields[0] = substr $_,7,7;
>
> For unpacking fixed position records you may want to consider unpack()
> as an alternative to several substr().
I didn't think of that, thanks.
--
my (@str) = split //,'eerb an. tuoisetJpel whrn';
my (@ndx, @arr) = qw(19 14 11 21 17 5 18 24 4 8 1 7 22
2 10 3 0 13 23 16 12 20 9 15 6);
$arr[$ndx[$_]] = $str[$_] for (@ndx); print @arr, "\n";
------------------------------
Date: Thu, 05 Aug 2004 01:01:22 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: Kqueue interface module implementation
Message-Id: <x7brhq4cvm.fsf@mail.sysarch.com>
>>>>> "UARR" == U A R Ruirarchzatrea <millueradfa@yahoo.com> writes:
UARR> Uri Guttman <uri@stemsystems.com> wrote in message news:<x73c33bigg.fsf@mail.sysarch.com>...
>> check out using libevent (at http://monkey.org/~provos/libevent/)
>> instead and wrapping that in perl via xs/swig/inline. that will be more
>> effective in that it gives you /dev/poll, kqueue(2), select(2), poll(2)
>> and epoll(4) support already and with one api wrapper you get all in
>> perl. i would be willing to help out with this as i have written and
>> wrapped event loops and done some (small) xs work (actually in swig).
>>
UARR> Thank you for the advice. I think doing a libevent interface i an
UARR> excellent idea. But I also think that there is still is a need for a
UARR> interface to kqueue, and that is on my list of things to study doing.
UARR> There are actually many event engines written in Perl that could
UARR> benefit from it, such as POE. Doing an engine in Perl has its
UARR> advantages, as it is eisier to understand the code and to improve upon
UARR> it, and there is less chance of memory buffer overflows.
i don't think you got what i meant. wrap libevent in perl and then stem
and poe and others can use libevent which already wraps kqueue and
several other things. for the amount of work to just wrap kqueue in
perl, you get several event interfaces in perl by wrapping libevent.
focus your effort where it will do the most good and libevent is that
for you.
uri
--
Uri Guttman ------ uri@stemsystems.com -------- http://www.stemsystems.com
--Perl Consulting, Stem Development, Systems Architecture, Design and Coding-
Search or Offer Perl Jobs ---------------------------- http://jobs.perl.org
------------------------------
Date: Thu, 05 Aug 2004 01:04:54 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: name of perl jobs newsgroup?
Message-Id: <x7657y4cpr.fsf@mail.sysarch.com>
>>>>> "CR" == Chris Richmond <crichmon@filc8046.fm.intel.com> writes:
CR> Our internal news server has a truncated group list, and
CR> I can't find the proper name for the perl jobs group. Can
CR> someone post it please? I can check for it from home.
there is no perl jobs newsgroup. there is a web site and list at
jobs.perl.org.
uri
--
Uri Guttman ------ uri@stemsystems.com -------- http://www.stemsystems.com
--Perl Consulting, Stem Development, Systems Architecture, Design and Coding-
Search or Offer Perl Jobs ---------------------------- http://jobs.perl.org
------------------------------
Date: 4 Aug 2004 19:18:05 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: recursive functions
Message-Id: <cercpd$bn1$1@mamenchi.zrz.TU-Berlin.DE>
Richard Gration <richard@zync.co.uk> wrote in comp.lang.perl.misc:
> In article <cer0qa$4um$1@mamenchi.zrz.TU-Berlin.DE>, "Anno Siegel"
> <anno4000@lublin.zrz.tu-berlin.de> wrote:
> > Richard Gration <richard@zync.co.uk> wrote in comp.lang.perl.misc:
> >> The absolute classic example of a recursive algorithm is the factorial
> >> function. ...
[...]
> But you have to agree it illustrates the concept of recursion well. A
The factorial example illustrates the *mechanics* of recursion. But so
do summing up (instead of multiplying) the first integers, or counting
the elements in a list, or a dozen tasks that can be done recursively,
but are best done iteratively, in Perl and most other languages.
It does nothing to help develop judgment of when recursion is an
appropriate solution, and where it's only (possibly expensive)
claptrap. In everyday programming, the most frequent question
about recursion is whether to use it at all. The factorial
example teaches the wrong decision.
If you want a simple arithmetic example for a naturally recursive
problem, use Euclid's algorithm.
sub euclid {
my ( $a, $b) = @_;
$b ? euclid( $b, $a % $b) : $a;
}
> computer is not the ideal tool to convert celsius to fahrenheit either,
Why on earth not? Would you prefer a slide-rule? It isn't used to
its full capacity, for sure, but that's something else.
> yet I have written a few programs to do just that when learning a
> language. :-)
You weren't taught to do that recursively, I suppose :)
Anno
------------------------------
Date: Wed, 04 Aug 2004 15:25:46 -0400
From: thundergnat <thundergnat@hotmail.com>
Subject: Re: recursive functions
Message-Id: <4111383a$0$2847$61fed72c@news.rcn.com>
Abhinav wrote:
> 4. Directory search of a file system
Heres something I had done at one point.
This could be MUCH more efficiently done with File::Find
but I wrote this to noodle around with recursion.
Print a manifest of a directory tree with file sizes to a file
$dir.mft.
#!/usr/bin/perl
use strict;
use warnings;
use Cwd;
my $dir = $ARGV[0];
die "You must specify a starting directory" unless $dir;
$dir =~ m/[\\\/](\w+)[\\\/]?$/;
die "Bad directory name: $dir" unless $1;
my $name = $1.".mft";
my $cwd = getcwd;
my ($indent,$index,@mfst);
my $space = '';
mft($dir);
chdir $cwd;
open my $MFST, ">$name" or die "Could not open file $!";
print $MFST "Manifest for $dir.\n\n";
print $MFST @mfst;
sub mft{
my $dir = shift;
$indent += 2;
chdir $dir;
my @list = glob("*");
foreach my $file(@list) {
if (-d $file){
push @mfst, (' ' x $indent).$file."\n";
mft($file);
}else{
push @mfst, (' ' x $indent).$space.$file.' '.
(((-s $file)>1024) ?
(sprintf "%.1f", (-s $file)/1024)."K\n" :
(sprintf "%d", (-s $file))."B\n");
}
}
$indent -= 2;
chdir '..';
}
------------------------------
Date: 4 Aug 2004 13:53:28 -0700
From: jgsmith@blarg.net (James)
Subject: Using MIME::Lite in Windows to send email with a zip attachment
Message-Id: <f93fa3a1.0408041253.1c924ad9@posting.google.com>
I'm not a hardcore perl master, and I spent an inordinate amount of
time trying to figure out how to send an email with a zip file
attachment. The documentation was confusing and Google didn't help,
so I'm posting this for the next guy.
This worked using Windows 2000 Professional, ActiveState Perl v5.6.1,
and MIME::Lite 3.01:
require MIME::Lite;
#
# Set up a hash with all the arguments. You don't have
# have to do it this way, but if you're writing reusable
# code, you'll be glad you did.
#
my %args = (
From => "myAccount\@mySite.com",
To => "yourAccount\@yourSite.com",
Subject => "Some droll subject",
BodyType => "TEXT",
Message => "Some pithy message",
AttachType => "application/zip",
AttachEncoding => "base64",
AttachFullpath => "D:\\the\\fullpath\\To\\MyFile.zip",
AttachFilename => "MyNewFileName.zip",
Server => "my.mail.server.com"
);
#
# Create the main body
#
my $mime_msg = MIME::Lite->new(
From => $args{From},
To => $args{To},
Subject => $args{Subject},
Type => $args{BodyType},
Data => $args{Message}
);
#
# Now add the attachment
#
$mime_msg->attach(
Type => $args{AttachType},
Encoding => $args{AttachEncoding},
Path => $args{AttachFullpath},
Filename => $args{AttachFilename},
Disposition => "attachment"
);
#
# Now send it.
#
$mime_msg->send('smtp', $args{Server}, Timeout=>60);
That's it. The very last line was the key. I couldn't find
it anywhere in the documentation or Google. The default:
$mime_msg->send()
uses sendmail instead of smtp, which doesn't exist in my setup.
The Disposition attribute can be important if you're sending
something like an html file. When I attached an html file without
specifying the Disposition, (using Outlook) I always ended up with
the html as the main message, and the "main body" I expected became
the attachment.
------------------------------
Date: Wed, 4 Aug 2004 17:58:36 -0400
From: Paul Lalli <mritty@gmail.com>
Subject: Re: Using MIME::Lite in Windows to send email with a zip attachment
Message-Id: <20040804175534.I14831@barbara.cs.rpi.edu>
On Wed, 4 Aug 2004, James wrote:
> I'm not a hardcore perl master, and I spent an inordinate amount of
> time trying to figure out how to send an email with a zip file
> attachment. The documentation was confusing and Google didn't help,
> so I'm posting this for the next guy.
<snip>
> $mime_msg->send('smtp', $args{Server}, Timeout=>60);
>
>
> That's it. The very last line was the key. I couldn't find
> it anywhere in the documentation or Google. The default:
>
> $mime_msg->send()
>
> uses sendmail instead of smtp, which doesn't exist in my setup.
Not that I don't think the next guy will appreciate it, but I'm curious
what documentation you read that you couldn't find this.
From MIME::Lite's docs, as found on CPAN:
----------------------------------------------------------------
send HOW, HOWARGS...
Class/instance method. This is the principal method for sending mail,
and for configuring how mail will be sent.
As a class method with a HOW argument and optional HOWARGS, it sets
the default sending mechanism that the no-argument instance method will
use. The HOW is a facility name (see below), and the HOWARGS is
interpreted by the facilty. The class method returns the previous HOW and
HOWARGS as an array.
<...>
There are three facilities:
"sendmail", ARGS...
Send a message by piping it into the "sendmail" command. Uses the
send_by_sendmail() method, giving it the ARGS. This usage implements (and
deprecates) the sendmail() method.
"smtp", [HOSTNAME]
Send a message by SMTP, using optional HOSTNAME as SMTP-sending host.
Uses the send_by_smtp() method.
"sub", \&SUBREF, ARGS...
Sends a message MSG by invoking the subroutine SUBREF of your
choosing, with MSG as the first argument, and ARGS following.
----------------------------------------------------------------
Did you not see this, or not understand this? I don't mean that to be
sarcastic. I'm just wondering if someone might want to suggest updates or
changes to the docs.
------------------------------
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 V10 Issue 6835
***************************************