[21764] in Perl-Users-Digest
Perl-Users Digest, Issue: 3968 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Oct 14 14:09:26 2002
Date: Mon, 14 Oct 2002 11:05:10 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Mon, 14 Oct 2002 Volume: 10 Number: 3968
Today's topics:
!\n problem (zawy)
Re: Archive::Zip - Zip contents empty files. <bongie@gmx.net>
Code explaination <uxrules@netscape.net>
Re: Code explaination <pinyaj@rpi.edu>
Re: Code explaination <dave@caledvwlch.coMA.PSuk>
Re: Code explaination <Tassilo.Parseval@post.rwth-aachen.de>
Re: do I need a demon? <bongie@gmx.net>
How can I display different charsets with Perl under Wi <uzshaf@uni-bonn.de>
Re: HTTP Command help....? <asimmons@mitre.org>
HTTP Upload From PERL to Web Page <3b533a81314e4@heavyk.org>
Re: HTTP Upload From PERL to Web Page <asimmons@mitre.org>
Learnign perl. <joec@annuna.com>
Re: Multiple Pings/Second <binabik1@mail.com>
Re: OLE Automation via Perl (Daniel Mahoney)
Read a single character from STDIN (W98) <nikogo@nigde.net>
Regular scheduled download of specific URL? (Will Lee)
Re: Regular scheduled download of specific URL? <jason@baugher.pike.il.us>
Re: Regular scheduled download of specific URL? <stephan@wanderinghorse.net>
Small syntax utility function (Zachary Beane)
Re: Small syntax utility function <Tassilo.Parseval@post.rwth-aachen.de>
Re: Splitting CSV lines <asimmons@mitre.org>
Re: Using Perl to solve interesting Banking Probm .. <nobody@dev.null>
Re: Using Perl to solve interesting Banking Probm .. <jason@baugher.pike.il.us>
Re: Weird Race Condition ctcgag@hotmail.com
Re: What purpose does eval{ ... } server? <comdog@panix.com>
Where are command line arguments described? <C2F46@nospam.com>
Re: Why is 'defined @x' deprecated? <uri@stemsystems.com>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Mon, 14 Oct 2002 15:54:45 GMT
From: zawy@yahoo.com (zawy)
Subject: !\n problem
Message-Id: <3daae718.97838489@news.knology.net>
I sometimes see a !\n inserted in text submitted to a form, or list-serv,
and now in BusinessWeek Online. I can't tell if it's a Perl, mail, or
Linux "enhancement". Does anyone know what causes this and how to prevent
it? To see it in BusinessWeek, see the 4th paragraph of the link below,
the words "thi! ngs". The \n made it come out as a space in the html.
http://biz.yahoo.com/bizwk/021014/b3803601_2.html
------------------------------
Date: Mon, 14 Oct 2002 20:03:16 +0200
From: "Harald H.-J. Bongartz" <bongie@gmx.net>
Subject: Re: Archive::Zip - Zip contents empty files.
Message-Id: <5400218.spUTVZJ5vk@nyoga.dubu.de>
Dirk Heitzmann wrote:
> I've tried to use Archive:Zip.
>
> I could create a new ZIP, add some files and save the ZIP to Disk.
> WOW ;-)
> But all files, I have added are empty (0 byte). Why ???
>
> My $source :
> my $zip = Archive::Zip->new();
> $zip->addFile("$inputfile");
> $zip->writeToFileNamed("$zipfile");
If that's your code, no wonder it doesn't work. Neither $inputfile nor
$zipfile are defined, and you don't "use Archive::Zip".
Please always send *complete* example code so that we can reproduce your
results. Use strict and warnings. Test and print return values.
(And don't put simple scalar variables in quotes unnecessarily.)
Ciao,
Harald
--
Harald H.-J. Bongartz <bongie@gmx.net>
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
"Conway's Law"
In any organization there is one person who knows what is going on.
That person must be fired.
------------------------------
Date: Mon, 14 Oct 2002 11:19:49 -0600
From: JamieBohr <uxrules@netscape.net>
Subject: Code explaination
Message-Id: <3DAAFCB5.3080104@netscape.net>
Can some one explain what/how this code works:
print $==()=<>, "\n";
I know this will count the input lines, but how? I know what <> does
have not a clue about the rest. Any help would be appreciated.
- Jamie
------------------------------
Date: Mon, 14 Oct 2002 13:38:46 -0400
From: Jeff 'japhy' Pinyan <pinyaj@rpi.edu>
To: uxrules@netscape.net
Subject: Re: Code explaination
Message-Id: <Pine.SGI.3.96.1021014133428.15355A-100000@vcmr-64.server.rpi.edu>
[posted & mailed]
On Mon, 14 Oct 2002, JamieBohr wrote:
>Can some one explain what/how this code works:
>
>print $==()=<>, "\n";
>
>I know this will count the input lines, but how? I know what <> does
>have not a clue about the rest. Any help would be appreciated.
You could run it through 'perl -MO=Deparse -e...':
$= = () = <ARGV>;
What this does is:
1. read from <ARGV> (that is, the magic <>)
2. assign the lines read to the empty list
3. stores the number of values on the RHS of the assignment to $=
Let me use another example...
$x = ($y, $z) = (10, 20, 30);
This stores 10 in $y, 20 in $z, and... 3 in $x. Not 2 (and NOT 30). The
reason it stores 3 in $x is because:
1. = is right-associative (so it's $x = (($y,$z) = (10,20,30)))
2. = returns the number of elements on its right-hand side (which is 3)
Now, we could say
$line_count = @lines = <>;
but we don't care about the actual lines themselves. So instead of
@lines, we use the empty list ().
$line_count = () = <>;
To obfuscate it, we use $= instead of $line_count, and remove that silly
whitespace.
$==()=<>;
--
Jeff "japhy" Pinyan RPI Acacia Brother #734 2002 Acacia Senior Dean
"And I vos head of Gestapo for ten | Michael Palin (as Heinrich Bimmler)
years. Ah! Five years! Nein! No! | in: The North Minehead Bye-Election
Oh. Was NOT head of Gestapo AT ALL!" | (Monty Python's Flying Circus)
------------------------------
Date: Mon, 14 Oct 2002 18:43:39 +0100
From: Dave Arnold <dave@caledvwlch.coMA.PSuk>
Subject: Re: Code explaination
Message-Id: <6e4f66854b.dave@caledvwlch.co.uk>
In message <3DAAFCB5.3080104@netscape.net>
JamieBohr <uxrules@netscape.net> wrote:
> Can some one explain what/how this code works:
>
> print $==()=<>, "\n";
>
> I know this will count the input lines, but how? I know what <> does
> have not a clue about the rest. Any help would be appreciated.
Put in some spaces and it is easier:
print $= = () = <>, "\n";
Break it down and it will become clear:
<> - this will read lines from a file
() = - forces <> into list context so all lines are read
$= = - assigns the list to a scalar, hence assigning the number of entries
I'm not sure why assigning to an empty list like this works, I assume that
the Perl compiler optimizes the middle assignment out.
Dave.
--
No, the fact that it's an infinite loop doesn't mean the program doesn't
work; it just entered a state with which I was previously unfamiliar.
Calum - Acorna, A.McCaffrey & M.Ball
------------------------------
Date: 14 Oct 2002 17:49:29 GMT
From: "Tassilo v. Parseval" <Tassilo.Parseval@post.rwth-aachen.de>
Subject: Re: Code explaination
Message-Id: <aof039$j6j$1@nets3.rz.RWTH-Aachen.DE>
Also sprach JamieBohr:
> Can some one explain what/how this code works:
>
> print $==()=<>, "\n";
>
> I know this will count the input lines, but how? I know what <> does
> have not a clue about the rest. Any help would be appreciated.
The first thing you should do is pull the above expression apart:
1)
print $= = () = <>, "\n";
2)
$= is obviously just used as an ordinary variable here (see perlvar
to learn what $= really means). Therefore, replace it with something
else:
print $n = () = <>, "\n";
3)
We know that an assignment returns the assigned value which means
that
print $n = EXPR;
is the same as
$n = EXPR;
print $n;
so we split:
$n = () = <>;
print $n, "\n";
4)
What remains is the fancy '$n = () = <>' thing. Doing
$n = <>;
would assign one line from stdin to $n leaving the rest of it in the
sort of queue waiting for the next read. To get all of them in one
go you need to enforce list context:
@n = <>;
An array in scalar context gives the number of elements in it:
@n = <>;
$n = @n;
5)
Since you only want to enforce list context and you are not
interested in the actual content of stdin (just in the number of
lines), drop the array and assign to the empty list:
$n = () = <>;
You're done.
Tassilo
--
$_=q!",}])(tsuJ[{@"tnirp}3..0}_$;//::niam/s~=)]3[))_$-3(rellac(=_$({
pam{rekcahbus;})(rekcah{lrePbus;})(lreP{rehtonabus;})(rehtona{tsuJbus!;
$_=reverse;s/sub/(reverse"bus").chr(32)/xge;tr~\n~~d;eval;
------------------------------
Date: Mon, 14 Oct 2002 19:39:47 +0200
From: "Harald H.-J. Bongartz" <bongie@gmx.net>
Subject: Re: do I need a demon?
Message-Id: <1920468.O2WuIVrEPH@nyoga.dubu.de>
jackkon wrote:
> I want to execute some perl scripts in the unix server from the remote
> program.
'remote' wrt the server, I presume.
> I think I must have a demon to receive my remote command.
> When the demon receive the command, it call the "system" function to
> do the job.
Most probably, a UNIX server already has some daemons[sic!] to allow
remote commands, e.g. sshd, telnetd, rshd, rexecd. I would not
recommend to program one yourself that would likely be vulnerable to
unauthorized access. SSH would be the most secure way to execute
remote commands, if already available and active on the server. (Be
sure to run a recent sshd implementation! There have been some security
issues lately.)
> Where can I find the example about the demon?
Look on CPAN for Net::SSH or Net::SSH::Perl
If you want to write your own daemon, be sure that it is restricted to
the things you really need and does not allow arbitrary commands to be
executed and also checks all parameters for malicious code.
Ciao,
Harald
--
Harald H.-J. Bongartz <bongie@gmx.net>
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
Airplanes are interesting toys but of no military value.
-- Marechal Ferdinand Foch, Professor of Strategy,
Ecole Superieure de Guerre.
------------------------------
Date: Mon, 14 Oct 2002 19:53:02 +0200
From: "Christian Kappler" <uzshaf@uni-bonn.de>
Subject: How can I display different charsets with Perl under Windows
Message-Id: <aof0e1$gse$1@f1node01.rhrz.uni-bonn.de>
Hello,
I have to write an application under Windows which opens a plaintext
document and displays part of it in a richedit control. This will be part of
a bigger Perl-project, so I would like to do this in Perl. My problem is,
taht the texts in different files might be written in different character
sets, such as Western ANSI (cp1252), Cyrillic Windows (cp1251) or Turkish
Windows (cp1254). Okay, I know how to create richedit controls and I have
fonts which have Cyrillic, etc. character representations. But I do not know
to much about character sets and how to work with them with perl. So I would
like to know:
1. Do I have to convert the characters to something special before I try to
display them in a richedit widget? How can I do this with Perl? Are there
some modules which can do this then for me?
2. Do I have to do something special when I create the font object to tell
the font whicht charset I want to display?
I would be happy about any hints or advice on this topic. I would be happy
to if someone points me to some manuals or code samples which help me to
understand, how I can solve the problem with the different character sets.
Thanks in advanced.
Regards,
Christian
------------------------------
Date: Mon, 14 Oct 2002 13:23:50 -0400
From: "Aaron Simmons" <asimmons@mitre.org>
Subject: Re: HTTP Command help....?
Message-Id: <aoeui6$nv3$1@newslocal.mitre.org>
I am not exactly sure what you are asking for? I think you are asking how
can you do a server-side redirect from CGI script for example. You can use
CGI.pm's redirect method
(http://stein.cshl.org/WWW/software/CGI/cgi_docs.html -- search for
redirect)
The HTTP syntax is as follows:
HTTP/1.0 302 Moved Temporarily
Location: $url
URI: <$url>
Notes
- Two newlines after the URI line
- I believe the "HTTP/1.0 302 Moved Temporarily" is optional (I only use it
for IIS)
- I believe just "URI: <$url>\n\n" is also sometimes acceptable--it depends
on the web server
--
Aaron Simmons
G066-Software Systems Eng, Lead
(703) 883-3394
AaronSimm1 (AIM)
"AB" <bill@makingitdigital.com> wrote in message
news:a7Ep9.3308$F53.3093088@newssvr28.news.prodigy.com...
> I have an application that accepts http commands that I am interfacing
with
> perl.
> the url I want to pass to access the application is something like this:
>
> http://127.0.0.1:<application_port>command?varible=example
>
>
> the problem is, that when I enter the above url/command into a browser it
> returns results.
>
> I have built an application that returns information but I only know how
to
> produce an http command with:
>
>
> print "Location:
> http://127.0.0.1:<application_port>command?varible=example";
>
>
> the problem is that this command redirect the user and return the
> application results
>
> is there another command or line of code I can use that wont redirect the
> user but will still request an HTTP or GET ?
>
> keep in mind I am a noob without a programming background.
>
> thanks in advance,
> -ab
>
>
------------------------------
Date: Mon, 14 Oct 2002 11:59:44 -0500
From: Keith Resar <3b533a81314e4@heavyk.org>
Subject: HTTP Upload From PERL to Web Page
Message-Id: <DF-dneibl_udZTegXTWc3A@News.GigaNews.Com>
Can anyone point me towards information on how to upload a file from a
PERL script to a web page that has an <input type=file> form element?
Keith Resar.
--
------------------------------
Date: Mon, 14 Oct 2002 13:24:40 -0400
From: "Aaron Simmons" <asimmons@mitre.org>
Subject: Re: HTTP Upload From PERL to Web Page
Message-Id: <aoeujn$nv8$1@newslocal.mitre.org>
http://stein.cshl.org/WWW/software/CGI/cgi_docs.html#upload_caveats
--
Aaron Simmons
G066-Software Systems Eng, Lead
(703) 883-3394
AaronSimm1 (AIM)
"Keith Resar" <3b533a81314e4@heavyk.org> wrote in message
news:DF-dneibl_udZTegXTWc3A@News.GigaNews.Com...
>
> Can anyone point me towards information on how to upload a file from a
> PERL script to a web page that has an <input type=file> form element?
>
> Keith Resar.
>
> --
------------------------------
Date: Mon, 14 Oct 2002 16:48:41 GMT
From: Joe Creaney <joec@annuna.com>
Subject: Learnign perl.
Message-Id: <3DAAF55D.2010301@annuna.com>
I am learning perl. I thik that I got most of the basics down. Are
there job opertunites if I know perl? Are there places I can go to
learn perl. Not just the language but ways to apply it or is perl a
good start for learning marketable languages?
------------------------------
Date: Mon, 14 Oct 2002 11:28:33 -0500
From: "Kevin Vaughn" <binabik1@mail.com>
Subject: Re: Multiple Pings/Second
Message-Id: <uqls5b29i4n7b9@corp.supernews.com>
I ran smackdab's code, and I got the same error. I used $^E like you said
(never used it before) and I got this:
"Error in recv: Unknown error #0x2726 (lookup 0x13D) at C:\scripts\ping.pl
line 53."
I am really feeling like a newbie now... From experience this looks like a
memory address, but I've never delved into programming far enough to look at
memory allocation at any real level. What would be a good resource for
learning how all of this works, especially in the Perl context??? If you
have time, or its not too complex to explain, how would I got about "looking
up" 0x13D?
"Benjamin Goldberg" <goldbb2@earthlink.net> wrote in message
news:3DA9D833.FD84E5F@earthlink.net...
> smackdab wrote:
> >
> > Wow what great timing...I was looking @ trying to do this, gave up and
> > then saw these posts. I have used an example of yours for nonblocking
> > port scanning, which works great (took me a while to understand it
> > though...)
> > It used IO::Select, which seems easier for us beginners...
> >
> > I can't get this to run, I currently get
> > Error in recv: Unknown error at test.pl line 53.
> > Here are the lines:
> > my $resp = "";
> > my $responder = recv( $socket, $resp, 8, 0 )
> > or die "Error in recv: $!"; # shouldn't happen.
>
> Whenever I see $! produce an "Unknown error" string, I try changing it
> to $^E... then, if that doesn't print anything useful, I try printing
> out the numeric value of $! or $^E, and then doing a google search to
> find out which Windows Socket Error that is.
>
> If you're not on windows, this advice might not help (there are other
> systems than windows where $^E prints something more useful than $!, but
> obviously on non-windows platforms you can't lookup WSA-errors)
>
> > (I changed the my ($resp), as I saw the above in another book, but
> > it didn't help...). $socket is valid at this point...
> >
> > This line was confusing, so I dropped the $t as my book only
> > said 1 thing came back from this call...
> > I noticed that IO::Select->select() returns 3 things though...
> > #(my ($n), $t) = select($rvec, $wvec, '', 0.5);
> > my $n = select($rvec, $wvec, '', 0.5);
>
> Hmm... I suppose that if you don't use $t (which an earlier version of
> my code did), then they are equivilant.
>
> > It *seems* to create the socket and call the select, but I never
> > see it call send().
> >
> > This line:
> > if( $wvec =~ tr/^\0// ) {
> > Is it looking for a NULL in a buffer...
>
> No, it is looking for a NON-nul in the w-vector.
>
> > don't understand this whole part, as $wvec is a "@" or a "." ... well
> > beyond me ;-)
>
> The $wvec variable is a bitvector, created with vec(). The only
> properties of it that we care about are whether or not:
> vec( $wvec, fileno($socket), 1 )
> is a true expression.
>
> It will have a value of "", or of "\000", or (assuming that
> fileno($socket) is 3), "\008", which is an unprintable character.
>
> The string "\000" prints out as "^@" on many systems. I don't see how
> you got the string "." ... that seems to be an impossible value.
>
> If it makes more sense to you, consider changing the if statement from:
> if( $wvec =~ tr/^\0// ) {
> to:
> if( vec $wvec, fileno($socket), 1 ) {
> Or perhaps to:
> if( $wvec eq $svec ) {
>
> --
> my $n = 2; print +(split //, 'e,4c3H r ktulrnsJ2tPaeh'
> ."\n1oa! er")[map $n = ($n * 24 + 30) % 31, (42) x 26]
------------------------------
Date: 14 Oct 2002 08:56:45 -0700
From: dan@wolf.com (Daniel Mahoney)
Subject: Re: OLE Automation via Perl
Message-Id: <6c3567b4.0210140756.1f4ec7d5@posting.google.com>
"Ron Savage" <ron@savage.net.au> wrote in message news:<ao7rrk$t4q$1@arachne.labyrinth.net.au>...
<snip>
> but frankly, I wouldn't. I'd create a text or even better XML file, since such a file could be easily processed by other scripts.
>
> Then the question arises, why not stuff the data into an MySQL db, where also it can be so easily procecessed further, eg with a CGI
> interface?
Because this application unfortunately runs on a Windows box,
replacing a very poorly-written MS Access application.
A portion of the application requires building some reports, then
displaying the reports to the user. The requirement doesn't allow me
to just build a file on disk, then tell the user where to find it; I
must actually open whatever external application I want to use to
display the report, and the external application needs to give the
user the ability to print the report if they choose.
That's why I am looking into OLE - it'd be pretty simple to build my
reports as RTF or PDF files. If I could figure out the proper way to
open Wordpad or Acroread and shove the report file over to the
program, I'd be all set with respect to displaying and printing my
reports.
So is OLE Automation not a simple task? Or is it complicated enough
that someone relatively inexperienced in the Windows world shouldn't
be attempting it?
------------------------------
Date: Mon, 14 Oct 2002 16:47:21 GMT
From: "Nemo Oudeheis" <nikogo@nigde.net>
Subject: Read a single character from STDIN (W98)
Message-Id: <tyCq9.21548$ue4.1422094@bgtnsc04-news.ops.worldnet.att.net>
I am using ActivePerl on a Win98 system. I would like to read a single
character from STDIN to get the reply from a (Y/N) question, without having
to terminate the line with by hitting <ENTER>, as is the default with getc
and read.
The example given in the ActivePerl documentation says to use stty and
$BSD_STYLE, but these are not available on a Windows system, as far as I
know.
Probably I have to slurp the character at a lower level than the STDIN
buffer, no?
Thanks for the help.
~Nemo
------------------------------
Date: 14 Oct 2002 09:17:56 -0700
From: willee1@hotmail.com (Will Lee)
Subject: Regular scheduled download of specific URL?
Message-Id: <25e033d6.0210140817.43590f5d@posting.google.com>
Hi. I was wondering if it was possible to get a Perl script scheduled
at regular intervals to take a copy of a webcam feed and then store
that copy on my PC (renaming the file as necessary)?
I was thinking about looking for an app to do it, but since I dabbled
a little in Perl a while back I thought it might be possible to do it
with Perl instead.
------------------------------
Date: Mon, 14 Oct 2002 16:35:14 GMT
From: Jason Baugher <jason@baugher.pike.il.us>
Subject: Re: Regular scheduled download of specific URL?
Message-Id: <Xns92A775DB97925jasonbaugherpikeilus@209.242.76.10>
willee1@hotmail.com (Will Lee) wrote in comp.lang.perl.misc:
> Hi. I was wondering if it was possible to get a Perl script scheduled
> at regular intervals to take a copy of a webcam feed and then store
> that copy on my PC (renaming the file as necessary)?
>
> I was thinking about looking for an app to do it, but since I dabbled
> a little in Perl a while back I thought it might be possible to do it
> with Perl instead.
Yes, it's possible.
Would you like a cost estimate? :)
--
Jason Baugher
Virtual Adept Professional Consulting Services
1406 Adams Street, Quincy, IL 62301 - (217) 221-5406
jason@baugher.pike.il.us - http://baugher.pike.il.us/virtualadept
------------------------------
Date: Mon, 14 Oct 2002 18:46:52 +0200
From: stephan <stephan@wanderinghorse.net>
Subject: Re: Regular scheduled download of specific URL?
Message-Id: <aoesdq$ds9$1@ork.noris.net>
Will Lee wrote:
> Hi. I was wondering if it was possible to get a Perl script scheduled
> at regular intervals to take a copy of a webcam feed and then store
> that copy on my PC (renaming the file as necessary)?
a)
http://homepages.tesco.net/~J.deBoynePollard/FGA/questions-with-yes-or-no-answers.html
b) 'man cron'
----- stephan
Registered Linux User #71917 http://counter.li.org
I speak for myself, not my employer. Contents may
be hot. Slippery when wet. Reading disclaimers makes
you go blind. Writing them is worse. You have been Warned.
------------------------------
Date: Mon, 14 Oct 2002 17:48:08 GMT
From: xach@xach.com (Zachary Beane)
Subject: Small syntax utility function
Message-Id: <slrnaqm0tr.a3u.xach@localhost.localdomain>
I would like to have a function "foreachpair" that lets me to this:
my @list = qw(a 1 b 2 b 9 c 3);
foreachpair {
print "$a => $b\n";
} @list;
and have it print out:
a => 1
b => 2
b => 9
c => 3
I tried doing this with dynamic scoping with "local", but that runs
into problems with package scoping. Is there any package-safe way
to write a "foreachpair" with the above behavior?
Zach
------------------------------
Date: 14 Oct 2002 18:00:54 GMT
From: "Tassilo v. Parseval" <Tassilo.Parseval@post.rwth-aachen.de>
Subject: Re: Small syntax utility function
Message-Id: <aof0om$jst$1@nets3.rz.RWTH-Aachen.DE>
Also sprach Zachary Beane:
> I would like to have a function "foreachpair" that lets me to this:
>
> my @list = qw(a 1 b 2 b 9 c 3);
>
> foreachpair {
> print "$a => $b\n";
> } @list;
>
> and have it print out:
>
> a => 1
> b => 2
> b => 9
> c => 3
>
> I tried doing this with dynamic scoping with "local", but that runs
> into problems with package scoping. Is there any package-safe way
> to write a "foreachpair" with the above behavior?
You could use a hash and use each() to iterate over it. But it may not
be the most efficient way and also you loose the sorting.
Or you use splice(). Unfortunately splice() is destructive, so use it
only on a copy of your data:
my @tmp = @list;
while (my ($i, $j) = splice @tmp, 0, 2) {
print "$i - $j\n";
}
Tassilo
--
$_=q!",}])(tsuJ[{@"tnirp}3..0}_$;//::niam/s~=)]3[))_$-3(rellac(=_$({
pam{rekcahbus;})(rekcah{lrePbus;})(lreP{rehtonabus;})(rehtona{tsuJbus!;
$_=reverse;s/sub/(reverse"bus").chr(32)/xge;tr~\n~~d;eval;
------------------------------
Date: Mon, 14 Oct 2002 12:52:10 -0400
From: "Aaron Simmons" <asimmons@mitre.org>
Subject: Re: Splitting CSV lines
Message-Id: <aoesmp$nt7$1@newslocal.mitre.org>
I've always just used Text::CSV. What is unsplit_csv?
--
Aaron Simmons
G066-Software Systems Eng, Lead
(703) 883-3394
AaronSimm1 (AIM)
"Andrew Cashin" <ajc81@hotmail.com> wrote in message
news:49b3792a.0210140342.504a9d07@posting.google.com...
> If anyone is interested, or (even better) has suggested improvements,
> here is a code fragment which copes (somewhat) with CSV lines where
> individual elements may or may not be quoted, but will be quoted if they
> contain either quotes (which will be quoted by doubling i.e. "") or
commas.
>
>
> #!/usr/bin/perl -wn
> # Copyright notice: Under the terms of my employment contract, I claim
> # that, as I have met the terms, this work is an employee invention
(meaning
> # that I own it). Anyone may freely use it under the same terms
> # as perl itself. I don't promise that it will help, and refer all to the
> # unsplit_csv perl module on CPAN.
>
> sub split_csv
> {
> my ($csv_string) = @_;
> my (@outels, @elements, $thisel, $nextel, $i, $l);
>
> @elements=split(/,/);
> while (@elements) {
> $thisel = shift @elements;
> if ( $thisel =~ s/^"// ) {
> while (@elements) {
> if ($thisel =~ m/("+)$/) {
> $l=length($1);
> if ($l % 2) {
> last;
> }
> }
> $nextel = shift @elements;
> $thisel = $thisel.",".$nextel;
> }
> chop $thisel;
> $thisel =~ s/""/"/g;
> }
> unshift (@outels, $thisel);
> }
> return reverse @outels;
> }
>
> print;
> @els = split_csv;
> $i=0;
> foreach $e (@els)
> {
> print "$i :$e:\n";
> $i++;
> }
------------------------------
Date: Mon, 14 Oct 2002 17:34:26 GMT
From: Andras Malatinszky <nobody@dev.null>
Subject: Re: Using Perl to solve interesting Banking Probm ..
Message-Id: <3DAB006B.1050603@dev.null>
KM wrote:
> PROB...
> ------------
>
> Write a program to solve the following problem. Use an array to model
> the
> safety deposit box vault and a while loop to iterate. Initialize the
> boxes
> as described below.
>
> The Saftey-Dep boxes ..
> -----------------------------
> There has been a run at the local savings and loan. 500 depositors
> have lined up in a very long vault with 500 _CLSD_ safety deposit boxes.
> One by one the depositors run through the vault. The 1st depositor
> opens every box. The 2nd depositor goes to every 2nd box and closes
> it. The 3rd depositor goes to every 3rd box and changes it (if open,
> closes it; if closed, open it). In a similiar manner, every 4th, 5th,
> 6th
> ... depositor changes every 4th, 5th, 6h, ... box. After all 500
> depositors have passed through the vault, WHICH boxes are left OPEN?
>
>
Since it's obvious that only the boxes whose numbers are perfect squares
will be left open and the last perfect square before 500 is 22*22, how about
print join "\n", map{$_*$_}(1..22);
By the way, this problem has to do little with Perl and nothing with
banking.
------------------------------
Date: Mon, 14 Oct 2002 17:39:29 GMT
From: Jason Baugher <jason@baugher.pike.il.us>
Subject: Re: Using Perl to solve interesting Banking Probm ..
Message-Id: <Xns92A780BFD24CCjasonbaugherpikeilus@209.242.76.10>
Andras Malatinszky <nobody@dev.null> wrote in comp.lang.perl.misc:
> KM wrote:
>
>> PROB...
>> ------------
>>
>> Write a program to solve the following problem. Use an array to
>> model
>> the
>> safety deposit box vault and a while loop to iterate. Initialize
>> the
>> boxes
>> as described below.
>>
>> The Saftey-Dep boxes ..
>> -----------------------------
>> There has been a run at the local savings and loan. 500 depositors
>> have lined up in a very long vault with 500 _CLSD_ safety deposit
>> boxes. One by one the depositors run through the vault. The 1st
>> depositor opens every box. The 2nd depositor goes to every 2nd box
>> and closes it. The 3rd depositor goes to every 3rd box and changes
>> it (if open, closes it; if closed, open it). In a similiar manner,
>> every 4th, 5th, 6th
>> ... depositor changes every 4th, 5th, 6h, ... box. After all 500
>> depositors have passed through the vault, WHICH boxes are left OPEN?
>>
>>
>
> Since it's obvious that only the boxes whose numbers are perfect
> squares will be left open and the last perfect square before 500 is
> 22*22, how about
>
> print join "\n", map{$_*$_}(1..22);
>
> By the way, this problem has to do little with Perl and nothing with
> banking.
>
>
It's a pretty standard homework question in programming classes. I think
I ran into it years ago when I was learning C. The parameters change,
and sometimes it's post office boxes instead of safe deposit boxes, but
the question is still the same.
--
Jason Baugher
Virtual Adept Professional Consulting Services
1406 Adams Street, Quincy, IL 62301 - (217) 221-5406
jason@baugher.pike.il.us - http://baugher.pike.il.us/virtualadept
------------------------------
Date: 14 Oct 2002 17:24:16 GMT
From: ctcgag@hotmail.com
Subject: Re: Weird Race Condition
Message-Id: <20021014132416.776$9H@newsreader.com>
appel@erzo.org (Shannon Appelcline) wrote:
> I just managed to track down a weird error in a web game I have. It
> turns out to be a race condition involving setting lock files.
This seems to be *the* classical race condition. Nothing weird
about it.
Since I have an irrational fear of using sysopen, how about this:
# open file, creating if necessary.
open LOCKHANDLE, ">>$lockFile" or die "Couldn't open lock file:$!"
until (flock LOCKHANDLE, LOCK_EX|LOCK_NB) {
unless ( time < $giveUpOnLock ) {
&ErrorReport("Sorry...game is too busy. Please reload.");
};
&LogIt("WAITING ON LOCK");
sleep 1;
};
And then, when done,
close LOCKHANDLE;
Xho
--
-------------------- http://NewsReader.Com/ --------------------
Usenet Newsgroup Service
------------------------------
Date: Mon, 14 Oct 2002 13:04:34 -0500
From: brian d foy <comdog@panix.com>
Subject: Re: What purpose does eval{ ... } server?
Message-Id: <141020021304341578%comdog@panix.com>
In article <aoe10p$fqb$1@nets3.rz.RWTH-Aachen.DE>, Tassilo v. Parseval <Tassilo.Parseval@post.rwth-aachen.de> wrote:
> Also sprach brian d foy:
>
> > In article <3DA9D8BB.A7163933@earthlink.net>, Benjamin Goldberg <goldbb2@earthlink.net> wrote:
> >
> >> Paul Tomlinson wrote:
> >
> >> > What purpose does eval{ ... } server?
> >> It catches errors created with die().
> > $quotient = eval { $m / $n };
> But in case the denominator is zero, this will die() so your eval{} does
> nothing else than trapping a die(). :-)
but when you don't see a die(), most newbies will get confused. you can
use it for things where you do not explicitly use die(). that's all i meant :)
--
brian d foy <comdog@panix.com> - Perl services for hire
The Perl Review - a new magazine devoted to Perl
<http://www.theperlreview.com>
------------------------------
Date: Mon, 14 Oct 2002 11:14:55 -0700
From: C2F46 <C2F46@nospam.com>
Subject: Where are command line arguments described?
Message-Id: <3DAB099F.1030701@nospam.com>
I've looked at the man page, info page, FAQ and could not find the
description of perl command line options anywhere. This sucks.
I have -U in my scripts like this:
#!/usr/bin/p5 -U
and could not find -U description anywhere. Any tips?
------------------------------
Date: Mon, 14 Oct 2002 16:45:23 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: Why is 'defined @x' deprecated?
Message-Id: <x78z11ezq4.fsf@mail.sysarch.com>
>>>>> "EJR" == Eric J Roode <REMOVEsdnCAPS@comcast.net> writes:
EJR> Uri Guttman <uri@stemsystems.com> wrote in
EJR> news:x7u1jsk7qa.fsf@mail.sysarch.com:
>> the biggest reason it is bad is that it leads newbies to think defined
>> on an aggregate will tell you if it has any elements in it which as you
>> seem to know is wrong. this is now deprecated for that reason as no one
>> should want to use defined for the allocation reason.
EJR> I have often wanted defined(@x) to work, and I find this deprecation
EJR> annoying. There have been many times when I have wanted to say "Has this
EJR> array been assigned a value, even the empty array value?"
EJR> my @arr; # undefined
EJR> @arr = (); # defined
but from a data point of view, both of those are the same. they should
not be differentiated.
use this:
my $arr_ref ;
my $arr_ref = [] ;
no defined needed and no problem with storage management.
EJR> Your argument, it seems to me, is tantamount to saying "Why
EJR> should there be an undefined state? Just use '' for
EJR> uninitialized scalar variables; you don't really need anything
EJR> else."
no, my argument is that defined is meant to be a logical test and not a
storage test. and the workaround for aggregates is trivial and safe,
just use a scalar and store a ref to the aggregate. if you have a ref,
it was allocated, if no ref, it was not. simple and it doesn't bend the
meaning of defined. aggregates do not inherently have a undef value. you
can't assign undef to them nor should you be able to test them with
defined. that was a bug that is slowly being excised.
uri
--
Uri Guttman ------ uri@stemsystems.com -------- http://www.stemsystems.com
----- Stem and Perl Development, Systems Architecture, Design and Coding ----
Search or Offer Perl Jobs ---------------------------- http://jobs.perl.org
------------------------------
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 3968
***************************************