[19413] in Perl-Users-Digest
Perl-Users Digest, Issue: 1608 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sat Aug 25 00:05:31 2001
Date: Fri, 24 Aug 2001 21:05:08 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <998712308-v10-i1608@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Fri, 24 Aug 2001 Volume: 10 Number: 1608
Today's topics:
Re: 4th ed of the Camel? <samneric@tigerriverOMIT-THIS.com>
Accessing Microsoft SQL Server (version 6+) from Active <Bradl@AAAcostbook.com>
Re: CGI redirect <guymal@__NOSPAM_hotmail.com>
Re: CGI redirect <flavell@mail.cern.ch>
Re: confused about 4 argument select (Chris Fedde)
Re: Grep Implemented in Perl <goldbb2@earthlink.net>
Re: How do I match and store || ??? <samneric@tigerriverOMIT-THIS.com>
Re: How do I match and store || ??? (Ian Boreham)
IO::Select's can_read hanging forever. <goldbb2@earthlink.net>
Re: localtime() - returns the wrong year! <samneric@tigerriverOMIT-THIS.com>
Re: localtime() - returns the wrong year! (Tad McClellan)
Re: localtime() - returns the wrong year! <Pcmann1@btinternet.com>
Re: localtime() - returns the wrong year! <mbudash@sonic.net>
Re: localtime() - returns the wrong year! (Eric Bohlman)
net::aim help <hockeyvb8@hotmail.com>
Re: Pattern Matching Qeustion <goldbb2@earthlink.net>
Re: pl or not pl, that is the question (Randal L. Schwartz)
Re: quick(?) programming question for perl newbie (Nathan McDannold)
Re: quick(?) programming question for perl newbie <davidhilseenews@yahoo.com>
Re: quick(?) programming question for perl newbie <krahnj@acm.org>
Re: quick(?) programming question for perl newbie <davidhilseenews@yahoo.com>
Read/write specific line of file <angenent@kabelfoon.nl>
Re: request for assistance (Chris Fedde)
Re: request for assistance <jurgenex@hotmail.com>
Re: request for assistance <callgirl@la.znet.com>
String Substitution across two files (Pularis)
Webmail fanzila@yahoo.com
Re: Yet another regex question <wyzelli@yahoo.com>
Re: Yet another regex question (Randal L. Schwartz)
Re: Yet another regex question <callgirl@la.znet.com>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Fri, 24 Aug 2001 23:38:46 -0400
From: Samneric <samneric@tigerriverOMIT-THIS.com>
Subject: Re: 4th ed of the Camel?
Message-Id: <MPG.15f0e7b868a90544989697@news.onemain.com>
Randal L. Schwartz wrote:
> Unless someone's keeping a BIG secret from me, there's no Camel 4
> planned before Perl 6. :)
Let me know before you publish it. My copy of v3 omits >ALL< of the margin-
scribblings that I made in my copy of v2 !!
Might have been a mis-print, but still...
We don't what THAT to happen again...
------------------------------
Date: Fri, 24 Aug 2001 16:52:32 -0700
From: "Brad" <Bradl@AAAcostbook.com>
Subject: Accessing Microsoft SQL Server (version 6+) from ActiveState Perl?
Message-Id: <3b86e9a4$0$23793$e2e8da3@nntp.cts.com>
Is this possible? If so, can someone point me to the modules?
Thanks
Brad
------------------------------
Date: Sat, 25 Aug 2001 02:40:17 +0200
From: "Guy" <guymal@__NOSPAM_hotmail.com>
Subject: Re: CGI redirect
Message-Id: <9m6oo5$alt$1@news.netvision.net.il>
LWP would be used to open a connection from the web server to another url.
What I need is to redirect the USER to another url (just like the CGI.pm
redirect function).
Guy
"Michael Budash" <mbudash@sonic.net> wrote in message
news:mbudash-C673C4.23485221082001@news.sonic.net...
> In article <3b832ff4@news.barak.net.il>, "Guy"
> <guymal@__NOSPAM__hotmail.com> wrote:
>
> > How can I redirect to a url, using POST, and pass it some parameters?
> >
> > I'm using CGI.pm to open a saved query:
> > open(OLD_Q,"$saved_query_path")|| die "Error: $! in file: ".__FILE__."
> > line:
> > ".__LINE__."Cannot open saved query $saved_query_path \n";
> > my $old_query=new CGI(OLD_Q);
> > close(OLD_Q);
> >
> > and I would like to redirect to a url as if the user submitted a form
> > (the
> > parameters from the saved query) to the new url:
> >
> > print $old_query->redirect("http://my-server.com/cgi-bin/a-script.pl");
> > #but
> > I need to pass all saved parameters using POST
> >
> > What I basically need is how to do something like this:
> > my $one=$old_query->param('param_1');
> > my $two=$old_query->param('param_2');
> > print
> >
$old_query->redirect("http://my-server.com/cgi-bin/a-script.pl?param_1=$on
> > e&
> > param_2=$two....");
> >
> > but using POST.
>
> use the LWP perl module (which can be found at
> http://www.perl.com/CPAN-local/modules/by-module/LWP/ as libwww-perl)
>
> hth-
> --
> Michael Budash ~~~~~~~~~~ mbudash@sonic.net
------------------------------
Date: Sat, 25 Aug 2001 02:14:39 +0200
From: "Alan J. Flavell" <flavell@mail.cern.ch>
Subject: Re: CGI redirect
Message-Id: <Pine.LNX.4.30.0108250208360.2872-100000@lxplus023.cern.ch>
On Aug 25, Guy hung upside-down from a convenient news server and
blurted out to the general confusion of the astonished Usenauts:
> LWP would be used to open a connection from the web server to another url.
You could do that. Configuring Apache to proxy the request would be
another option.
> What I need is to redirect the USER to another url (just like the CGI.pm
> redirect function).
What do you mean, "just like"? If you already know what you want, why
aren't you just doing it?
Let's see what the real problem was...
[extract from Jeopardy-quote follows]
> > > How can I redirect to a url, using POST, and pass it some parameters?
Exactly. So take a look at my page
http://ppewww.ph.gla.ac.uk/~flavell/www/post-redirect.html
and ponder whether you haven't already been offered a reasonable
answer, in spite of your apparent inability to follow Netiquette.
------------------------------
Date: Fri, 24 Aug 2001 23:11:20 GMT
From: cfedde@fedde.littleton.co.us (Chris Fedde)
Subject: Re: confused about 4 argument select
Message-Id: <saBh7.607$V3.190828544@news.frii.net>
In article <PGyh7.33$A83.39607@typhoon1.gnilink.net>,
Alex Hart <news@althepal#nospam#.com> wrote:
>I have read the doc on this, but there are things about the select(4
>argument) that I don't get. I see in the doc to set it up like this:
>
> $rin = $win = $ein = '';
> vec($rin,fileno(STDIN),1) = 1;
> vec($win,fileno(STDOUT),1) = 1;
> $ein = $rin | $win;
>
>or this:
> sub fhbits {
> my(@fhlist) = split(' ',$_[0]);
> my($bits);
> for (@fhlist) {
> vec($bits,fileno($_),1) = 1;
> }
> $bits;
> }
> $rin = fhbits('STDIN TTY SOCK');
>then this:
> ($nfound,$timeleft) =
> select($rout=$rin, $wout=$win, $eout=$ein,
>$timeout);
>
>Can someone please explain the significance of the $rout=$rin part? What
>does $rin look like . Can you tell me in english what is going on here.
>
>Also, is this the only method of timing out a read? Will <> ever time
>out, or is it forever?
>
>It's all very appreciated. Thanks.
>
You know of course that the one argument form of select has nothing
to do with the 4 argument form. But as review the 4 argument form
waits till one of several file handles need attention. It's one of
the older ways that unix implements event loops. The C interface
to the unix system call uses a bit map to indicate which file
handles to watch. Perl inherited this interface from there.
If the file descripter for STDIN is 1, TTY is 3 and SOCK is 6 then
the binary form of $rin might look something like this 01001010.
The $rout=$win as arguments to select are a bit of cleverness that
replaces three seperate assignment statements before the call to
select.
An simpler object interface to this functionality can be fouind in IO::Select.
Good Luck.
--
This space intentionally left blank
------------------------------
Date: Fri, 24 Aug 2001 23:41:45 -0400
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: Grep Implemented in Perl
Message-Id: <3B871E79.B9938D3E@earthlink.net>
Buck Turgidson wrote:
>
> I think the PPT version is the one I am looking for.
>
> I see the -r flag, to process an entire directory. Any idea how to
> do, say "*.sql" within a directory?
find directory -name "*.sql" | xargs tcgrep [flags] pattern {}
--
I'm not a programmer but I play one on TV...
------------------------------
Date: Fri, 24 Aug 2001 18:07:41 -0400
From: Samneric <samneric@tigerriverOMIT-THIS.com>
Subject: Re: How do I match and store || ???
Message-Id: <MPG.15f09a389705e8d8989695@news.onemain.com>
Syrag wrote:
> I discovered that using (\|\|) matches and stores the ||, but using (\|\|)?
> to match 0 or more does not work,
That's not how to indicate "zero or more |'s". Use "\|*".
> it always matches (in the context of the
> code below) and nothing is stored in $1.
> > elsif ( m/^\s*.*(||)?.*\s+(xyz)\s*\..*\r?$/i ) {
I thought you only wanted to save the "xyz" part. If so, then don't put parens
around the "\|*" unless you use "(?:\|*)" indicating "don't save". Otherwise,
you're putting "zero or more |'s" into $1, and "xyz" into $2.
------------------------------
Date: 24 Aug 2001 20:13:07 -0700
From: ianb@ot.com.au (Ian Boreham)
Subject: Re: How do I match and store || ???
Message-Id: <f02c4576.0108241913.59e74aef@posting.google.com>
"Syrag" <syrag@my-deja.com> wrote in message news:<9m6gdq$2ef$1@tilde.csc.ti.com>...
> I discovered that using (\|\|) matches and stores the ||, but using (\|\|)?
> to match 0 or more does not work, it always matches (in the context of the
Zero or one. It does work with the correct context. I will assume that
you only care to find out about one set of pipes, but that more can
appear. Trying to count the number of appearances could not be done in
a single step.
> code below) and nothing is stored in $1.
> >
> > I want to match white space followed by some characters that might contain
> > || (which I want to know about) followed by some other stuff that contains
> > xyz with a . after it.
It's not clear what "some characters" means here. Do you mean
non-whitespace? If it means "any characters", then you don't need to
make a special case for the whitespace at the start. If you mean
"non-whitespace", then you should say so in the regex, and most of you
problems are solved. If you mean a mixture (but perhaps not including
"xyz"), things might get trickier.
Since you are only capturing "||" and "xyz", you might as well get rid
of the .*\r?$ at the end, since it isn't doing anything for you
(unless you are going to use $&, which I hope you're not).
If "xyz" is really a constant, there's not much point capturing it,
since if the match succeeds, it's always going to be "xyz". I assume
this would really be a more complex pattern? If it is more complex,
how are you going to distinguish between the "some characters" at the
start and the "xyz" bit? Is "xyz" forbidden in the "some characters"?
> > Here is what I am generally trying to do. Maybe I am taking the wrong
> > approach here.
> >
> >
> > elsif ( m/^\s*.*(||)?.*\s+(xyz)\s*\..*\r?$/i ) {
A whole program and some sample data would make this a lot easier to
sort out.
This discussion assumes you do not have newlines embedded in the
middle of the data (meaning that here .* will match anything).
The first \s* might match something substantial, but even if it does,
the .* following it would have matched it too. The first .* will also
match any pipes you have in there, so the (corrected) (\|\|)? is never
going to match more than zero width. The .* after it will never match
anything substantial either. The \s+ will either match a single space
(since the first .* will have swallowed any others already), or it
won't find a match at all and will cause the entire match to fail.
So, you can see that it is crucial to define exactly what the "some
characters" around the potential pipe pair can be.
> > if ( $1 eq "||") {
> > printf("found || with xyz");
> > $pipes++;
> > }
> > else {
> > $pipes--;
I'm not quite sure why you're decrementing this when you don't find
any, but I'll leave that up to you to sort out.
> > }
> > }
I will assume "xyz" is constant, there can be more pipe pairs, but you
just want to know if there is at least one pair, and "some characters"
means anything except single pipe characters.
#!/usr/bin/perl -w
@data = (
"random garbage that doesn't match",
" should||match xyz . blah.blah .blah",
" shouldmatchtoo xyz . blah.blah .blah",
" should match ||too xyz . blah.blah .blah",
" should match|| to||o xyz . blah.blah .blah",
" should match #$%#$%too xyz. blah.blah .blah",
);
foreach (@data)
{
if ( m/^[^|]*(\|\|)?.*\sxyz\s*\./i )
{
print "Matched. Found ", (defined $1)? "": "no ", "pipes.\n";
}
else
{
print "Failed.\n";
}
}
The output is as follows:
Failed.
Matched. Found pipes.
Matched. Found no pipes.
Matched. Found pipes.
Matched. Found pipes.
Matched. Found no pipes.
The regex works as follows:
^[^|]*(\|\|)?.*\sxyz\s*\.
"^[^|]*": matches as many non-pipe characters as possible at the start
(whilst still allowing the remainder of the regex to match). Using ^|
prevents this chunk overrunning the pipe pair in the way that .*
would. If the data can include single pipe characters, this will not
work, and you will need a more complex regex.
"(\|\|)?": Captures a pipe pair if there are any.
".*\sxyz": Matches any characters ending with (at least) one
whitespace and the constant xyz.
"\s*\.": Asserts that the xyz is followed by (potential whitespace
and) a "."
This could be varied to prevent the occurrence of more pipe pairs, to
allow xyz to be more complex, to assert that the pipes are surrounded
by word characters, to allow single pipe characters in the data, and
so on. If you can state more clearly what the requirements are, I
could go into some of these in more detail.
Regards,
Ian
------------------------------
Date: Fri, 24 Aug 2001 21:57:14 -0400
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: IO::Select's can_read hanging forever.
Message-Id: <3B8705FA.DA9B7BC7@earthlink.net>
I have a bit of code which needs to distribute some computation between
to proccesses, and I use IO::Select to help tell what is happening when.
Unfortunatly, I've a call to it's can_read method, which seems to never
return.
Here's the problem code:
# this is executed in a child proccess created by fork()
my $rsel = IO::Select->new($reader);
MAIN: while( 1 ) {
print STDERR "$$: entering select...\n";
() = $rsel->can_read(undef)
or die "select: $!";
print STDERR "$$: select returned.\n";
# The parent calls this
print STDERR "Sending [$cmd, $args]...\n";
store_fd( [$cmd, $args], $$self{writer} )
or $self->serialize_error;
print STDERR "Sent.\n";
# Then this
print STDERR "Getting a $state message\n";
while( $status = fd_retrieve $reader ) {
print STDERR "Got a message of some sort.\n";
die $status->{error} if $status->{error};
if( exists $status->{$state} ) {
# here's the relevant debug output:
6841: entering select...
Sending [connect, ARRAY(0x405d4df4)]...
Sent.
Getting a connect message
And then it hangs there... can_read should return at this point, but it
doesn't... it just sits there.
Does anyone have a clue as to what's going on, or do I need to post more
code?
--
I'm not a programmer but I play one on TV...
------------------------------
Date: Fri, 24 Aug 2001 18:15:13 -0400
From: Samneric <samneric@tigerriverOMIT-THIS.com>
Subject: Re: localtime() - returns the wrong year!
Message-Id: <MPG.15f09bfbb6a6083d989696@news.onemain.com>
Peter Mann wrote:
> Dear All,
> I have a small problem I can't work out! I need to retrieve the current
> date and display it in 'short date' format. This is my code I have to try
> and achieve this! The problem is that is displays '24/07/101'
> The day and month are correct, but 101 for the year isn't! Why wont is give
> me back the correct year?
It is the correct year. It's been 101 years since 1900. Check the docs.
And be glad you weren't using localtime before 1900. There was absolutely no
documentation of it at that time (little-known historical fact) - although the
docs are just barely consulted more now than they were then...
------------------------------
Date: Fri, 24 Aug 2001 18:00:30 -0400
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: localtime() - returns the wrong year!
Message-Id: <slrn9odjju.c26.tadmc@tadmc26.august.net>
Peter Mann <Pcmann1@btinternet.com> wrote:
[snip y2k problem, you're awfully late...]
> my (undef, undef, undef, $day, $month, $year) = localtime();
>Any suggestions would be much appreciated!
I suggest reading up on localtime to see what it says about
the values that it returns.
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Fri, 24 Aug 2001 23:51:22 +0100
From: "Peter Mann" <Pcmann1@btinternet.com>
Subject: Re: localtime() - returns the wrong year!
Message-Id: <9m6lmv$26k$1@uranium.btinternet.com>
Dear All,
I have just recently realised the reason for the error in my code! I
should have read the FAQ's more clearly!
My sincere apologies for posting such an obvious question.
Regards
- Pete
"Peter Mann" <Pcmann1@btinternet.com> wrote in message
news:9m6idn$p3s$1@neptunium.btinternet.com...
> Dear All,
> I have a small problem I can't work out! I need to retrieve the
current
> date and display it in 'short date' format. This is my code I have to try
> and achieve this! The problem is that is displays
> '24/07/101'
> The day and month are correct, but 101 for the year isn't! Why wont is
give
> me back the correct year?
>
> sub tasksBehind
> {
> my (undef, undef, undef, $day, $month, $year) = localtime();
> print "$day/$month/$year";
> }
>
>
> Any suggestions would be much appreciated!
> Thanks in advance
> - Pete
>
>
------------------------------
Date: Fri, 24 Aug 2001 23:13:36 GMT
From: Michael Budash <mbudash@sonic.net>
Subject: Re: localtime() - returns the wrong year!
Message-Id: <mbudash-58F2D6.16133624082001@news.sonic.net>
In article <9m6idn$p3s$1@neptunium.btinternet.com>, "Peter Mann"
<Pcmann1@btinternet.com> wrote:
> Dear All,
> I have a small problem I can't work out! I need to retrieve the
> current
> date and display it in 'short date' format. This is my code I have to try
> and achieve this! The problem is that is displays
> '24/07/101'
> The day and month are correct, but 101 for the year isn't! Why wont is
> give
> me back the correct year?
>
> sub tasksBehind
> {
> my (undef, undef, undef, $day, $month, $year) = localtime();
> print "$day/$month/$year";
> }
>
>
> Any suggestions would be much appreciated!
> Thanks in advance
the function is operating as designed... RTFM (perldoc -f localtime):
Converts a time as returned by the time function to a 9-element array
with the time analyzed for the local time zone. Typically used as
follows:
# 0 1 2 3 4 5 6 7 8
($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) =
localtime(time);
All array elements are numeric, and come straight out of a struct tm.
In particular this means that $mon has the range 0..11 and $wday has
the range 0..6 with sunday as day 0. Also, $year is the number of
years since 1900, that is, $year is 123 in year 2023.
If EXPR is omitted, uses the current time (C<localtime(time)>).
In a scalar context, returns the ctime(3) value:
$now_string = localtime; # e.g., "Thu Oct 13 04:54:34 1994"
Also see the Time::Local module, and the strftime(3) and mktime(3)
function available via the POSIX module.
hth-
--
Michael Budash ~~~~~~~~~~ mbudash@sonic.net
------------------------------
Date: 24 Aug 2001 23:59:48 GMT
From: ebohlman@omsdev.com (Eric Bohlman)
Subject: Re: localtime() - returns the wrong year!
Message-Id: <9m6ppk$k$1@bob.news.rcn.net>
Peter Mann <Pcmann1@btinternet.com> wrote:
> I have just recently realised the reason for the error in my code! I
> should have read the FAQ's more clearly!
When you're having trouble with the behavior of a function, the FAQs
aren't the first place to turn to. Rather, you need to read the
documentation for the function in perlfunc (perldoc -f localtime will do
the lookup for you). As Tad is fond of pointing out, using a function
without having read its documentation is like signing a contract without
having read it.
Part of being an effective programmer is making a habit out of this
consultation of the documentation. It should eventually become second
nature to you.
------------------------------
Date: Sat, 25 Aug 2001 01:06:57 GMT
From: Ryan <hockeyvb8@hotmail.com>
Subject: net::aim help
Message-Id: <6iudot47eersnrva30ei92fagb87qnr8u0@4ax.com>
... i just installed the net::aim module but i have never coded in
perl before. Does any one have pre-made bot scripts to help me out?
thanks for the help!
hockeyvb8@hotmail.com
------------------------------
Date: Fri, 24 Aug 2001 23:36:59 -0400
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: Pattern Matching Qeustion
Message-Id: <3B871D5B.D0C49FEE@earthlink.net>
Salvador Peralta wrote:
>
> Being something of a stathead, I was fooling around with a perl
> script to take a look at the performance of certain players in a
> football game.
>
> The file to be parsed has a bunch of line records that look like this:
>
> 1-10-DAL 29 (1:48) K.Coleman left tackle to DAL 28 for 1 yard
> (J.Carter). 2-9-DAL 28 (1:01) K.Coleman up the middle to DAL 25 for 3
> yards (L.Scott). 3-6-DAL 25 (:20) K.Coleman left end to DAL 27 for -2
> yards (M.Steele).
If I understand correctly, when you say "line records," you are calling
each record [each game play] a "line," right? Not that there is one
record per line of the file?
Are there any newlines in this file in the original format, or were they
added by your news program when you posted the message? I'm going to
*assume* that the contents of the file are all on one line, with no
newlines [and the ones you have here were added by your news program].
> At first I thought that I could do something like this:
>
> if($line =~ /(K.Coleman.+?\)\.)/g) {
> print $&, "\n\n";
> }
>
> This is okay, but if 2 occurances of the same play happen on the same
> line, it will only match the first instance despite the global
> instruction.
In a scalar context, a regex will only do one match, even with the /g
flag. You are thinking of it as an instruction to match "globally" but
this isn't quite right -- in scalar context all it means is that it will
begin it search where the last one left off instead of the beginning of
the string. The reason this would be useful is for things like:
while( $line =~ /some pattern/g ) {
# do stuff with $&, and/or $1, $2, $3, etc.
}
Oh, and you should probably be using $1, $2, etc, instead of $&.
>
> $ ./football.pl
>
> K.Coleman up the middle to DAL 35 for 5 yards (A.Fields).
>
> K.Coleman left tackle to DAL 28 for 1 yard (J.Carter).
>
> ...
>
> If I remove the ? from the regex, the output looks something like
> this where multiple plays occur on the same line:
>
> K.Coleman up the middle to DAL 30 for 3 yards (J.Carter). 2-17-DAL 30
> (13:11) J.Jackson pass to C.Cole to DAL 25 for 5 yards (J.Jones).
>
> K.Coleman left tackle to DAL 28 for 1 yard (J.Carter). 2-9-DAL 28
> (1:01) K.Coleman up the middle to DAL 25 for 3 yards (L.Scott).
> 3-6-DAL 25 (:20) K.Coleman left end to DAL 27 for -2 yards (M.Steele).
>
> ...
>
> Can anyone suggest a RE pattern that will print out each instance of
> the pattern and match and print multiple occurances of the pattern on
> a single line? The output should look like the first 2 examples,
> only it should get every instance rather than just the first. I
> probably just missed it in perldoc -q regex. Sincere apologies if
> that's the case.
local $_ = do {
local (*FOOTBALL, $/);
open( FOOTBALL, "<", "plays.text" )
or die "Couldn't open plays file: $!";
<FOOTBALL>;
};
print $1, "\n" while( /(.*?\.)\s+/gs );
#print $_, "\n" foreach( /(.*?\.)\s+/gs );
#print $_, "\n" foreach( split /(?<=\.)\s/ );
It doesn't matter *much* in this case, but if I'd used $& instead of $1,
my print statement would include the whitespace following the period
which marks the end of each record. The two commented foreach
statements both have similar effect, except that they're a bit slower.
--
I'm not a programmer but I play one on TV...
------------------------------
Date: 24 Aug 2001 17:50:39 -0700
From: merlyn@stonehenge.com (Randal L. Schwartz)
Subject: Re: pl or not pl, that is the question
Message-Id: <m13d6hx8rk.fsf@halfdome.holdit.com>
>>>>> "Ilya" == Ilya Martynov <ilya@martynov.org> writes:
Ilya> .pl as 'perl library' was valid in Perl 4 days. Nowdays people
Ilya> (including me) often use .pl for scripts. I think it is ok.
Do you put .sh on the end of all your shell scripts, and .py on the
end of all your python programs? And do you rename /bin/cat to
/bin/cat.o? It's an object file after all! And what happens
if you change the implementation from Perl to shell? Do you have
to readjust all the invokers of your commands?
I'm of the firm belief that a *command* (aka "program") should *not*
have the implementation language embedded in the path. And I'm not
the only one out there. Why should I care when I invoke your program
that it was shell or Perl or C originally? I just care about the
interface!
Also, if it's in the path, and that path is used for CGI, then it
gives away a potential exploit. For example, if I'm a bad guy, and I
discover that many Python scripts can be broken by typing "FOO" into a
form box, then I'll look for "_____.py" in paths using a search
engine. Instant hole, because you've given away more than you need to
give away.
Please stop with this nonsense about "Perl scripts are named .pl".
Maybe they *must* be on stupid operating systems that need to use
extensions, but *not* under Unix. Unix doesn't need extensions to
determine executable file types. It's all in the first two bytes,
baby!
--
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!
------------------------------
Date: 24 Aug 2001 17:35:23 -0700
From: nmcdannold@yahoo.com (Nathan McDannold)
Subject: Re: quick(?) programming question for perl newbie
Message-Id: <58f70619.0108241635.567b5ace@posting.google.com>
"John W. Krahn" <krahnj@acm.org> wrote in message news:<3B86A3D3.27EE0920@acm.org>...
> Nathan McDannold wrote:
> > I tried this code:
> >
> > $filename= "F:\\myfile.dat";
> >
> > print &getheaderval($filename),"\n";
> >
> > sub getheaderval {
> > my $filename = shift || return;
> >
> > open IN, $filename or die "Cannot open $filename: $!";
> > binmode IN;
> > my $shortval;
> > read( IN, $shortval, 2, 2194 ) == 2 or die "Cannot read from
> > $filename: $!";
> > close IN;
> >
> > return unpack 'n', pack 'S', $shortval;
> > }
> >
> > and it returns "0". The original code returns 2, which is correct. Am
> > I doing this wrong here? Looking at "myfile.dat" in a HEX editor gives
> > values of 00 02 for bytes 2194-2195. I'm not sure I "get" the
> > pack/unpack commands and what they really do. Any ideas of what I'm
> > missing?
>
> Sorry, I think I misread your original post. Change:
> return unpack 'n', pack 'S', $shortval;
> to:
> return unpack 'n', $shortval;
>
>
>
> John
hmm...it still returns "0". I'll look at it some more tomorrow.
Nathan
------------------------------
Date: Sat, 25 Aug 2001 01:30:57 GMT
From: "David Hilsee" <davidhilseenews@yahoo.com>
Subject: Re: quick(?) programming question for perl newbie
Message-Id: <ldDh7.14922$hT4.4071850@news1.rdc1.md.home.com>
"Nathan McDannold" <nmcdannold@yahoo.com> wrote in message
news:58f70619.0108241635.567b5ace@posting.google.com...
> "John W. Krahn" <krahnj@acm.org> wrote in message
news:<3B86A3D3.27EE0920@acm.org>...
> > Nathan McDannold wrote:
> > > I tried this code:
> > >
> > > $filename= "F:\\myfile.dat";
> > >
> > > print &getheaderval($filename),"\n";
> > >
> > > sub getheaderval {
> > > my $filename = shift || return;
> > >
> > > open IN, $filename or die "Cannot open $filename: $!";
> > > binmode IN;
> > > my $shortval;
> > > read( IN, $shortval, 2, 2194 ) == 2 or die "Cannot read from
> > > $filename: $!";
> > > close IN;
> > >
> > > return unpack 'n', pack 'S', $shortval;
> > > }
> > >
> > > and it returns "0". The original code returns 2, which is correct. Am
> > > I doing this wrong here? Looking at "myfile.dat" in a HEX editor gives
> > > values of 00 02 for bytes 2194-2195. I'm not sure I "get" the
> > > pack/unpack commands and what they really do. Any ideas of what I'm
> > > missing?
> >
> > Sorry, I think I misread your original post. Change:
> > return unpack 'n', pack 'S', $shortval;
> > to:
> > return unpack 'n', $shortval;
> >
> >
> >
> > John
>
>
> hmm...it still returns "0". I'll look at it some more tomorrow.
>
> Nathan
I implemented it myself (and tested it with some data that I generated), but
John was slightly quicker on the draw. My way of implementing the read was
as follows:
seek ( FILE, 2194, 0 ) or die "Couldn't seek: $!\n";
2 == read ( FILE, $short, 2 ) or die "Error reading from $file: $!\n";
I took a cursory look at John's code and it looked almost the same, so I
didn't pursue the matter any further. However, after reading the
documentation for read() (and re-reading it!), I gathered that the "offset"
value specified in the argument list is not an offset into the file, but an
offset into the scalar. Needless to say, I don't find myself using read()
all that often.
"An OFFSET may be specified to place the read data into some other place in
SCALAR than the beginning."
Well, I never would have guessed it from the signature of the function.
Oops!
David Hilsee
------------------------------
Date: Sat, 25 Aug 2001 03:46:14 GMT
From: "John W. Krahn" <krahnj@acm.org>
Subject: Re: quick(?) programming question for perl newbie
Message-Id: <3B871FF3.870298A2@acm.org>
David Hilsee wrote:
>
> I implemented it myself (and tested it with some data that I generated), but
> John was slightly quicker on the draw. My way of implementing the read was
> as follows:
>
> seek ( FILE, 2194, 0 ) or die "Couldn't seek: $!\n";
> 2 == read ( FILE, $short, 2 ) or die "Error reading from $file: $!\n";
>
> I took a cursory look at John's code and it looked almost the same, so I
> didn't pursue the matter any further. However, after reading the
> documentation for read() (and re-reading it!), I gathered that the "offset"
> value specified in the argument list is not an offset into the file, but an
> offset into the scalar. Needless to say, I don't find myself using read()
> all that often.
>
> "An OFFSET may be specified to place the read data into some other place in
> SCALAR than the beginning."
>
> Well, I never would have guessed it from the signature of the function.
> Oops!
Thanks David!
Nathan, change the subroutine to this:
sub getheaderval {
my $filename = shift || return;
open IN, $filename or die "Cannot open $filename: $!";
binmode IN;
seek IN, 2194, 0 or die "Cannot seek on $filename: $!";
my $shortval;
read( IN, $shortval, 2 ) == 2 or die "Cannot read from $filename:
$!";
close IN;
return unpack 'n', pack 'S', $shortval;
}
John
--
use Perl;
program
fulfillment
------------------------------
Date: Sat, 25 Aug 2001 04:01:21 GMT
From: "David Hilsee" <davidhilseenews@yahoo.com>
Subject: Re: quick(?) programming question for perl newbie
Message-Id: <lqFh7.15289$hT4.4220872@news1.rdc1.md.home.com>
"John W. Krahn" <krahnj@acm.org> wrote in message
news:3B871FF3.870298A2@acm.org...
> David Hilsee wrote:
> >
> > I implemented it myself (and tested it with some data that I generated),
but
> > John was slightly quicker on the draw. My way of implementing the read
was
> > as follows:
> >
> > seek ( FILE, 2194, 0 ) or die "Couldn't seek: $!\n";
> > 2 == read ( FILE, $short, 2 ) or die "Error reading from $file: $!\n";
> >
> > I took a cursory look at John's code and it looked almost the same, so I
> > didn't pursue the matter any further. However, after reading the
> > documentation for read() (and re-reading it!), I gathered that the
"offset"
> > value specified in the argument list is not an offset into the file, but
an
> > offset into the scalar. Needless to say, I don't find myself using
read()
> > all that often.
> >
> > "An OFFSET may be specified to place the read data into some other place
in
> > SCALAR than the beginning."
> >
> > Well, I never would have guessed it from the signature of the function.
> > Oops!
>
> Thanks David!
>
> Nathan, change the subroutine to this:
>
>
> sub getheaderval {
> my $filename = shift || return;
> open IN, $filename or die "Cannot open $filename: $!";
> binmode IN;
> seek IN, 2194, 0 or die "Cannot seek on $filename: $!";
> my $shortval;
> read( IN, $shortval, 2 ) == 2 or die "Cannot read from $filename:
> $!";
> close IN;
> return unpack 'n', pack 'S', $shortval;
> }
>
>
>
> John
> --
> use Perl;
> program
> fulfillment
I think that last statement should be:
return unpack 'n', $shortval;
After all, it is a short in network byte order, right?
--
David Hilsee
------------------------------
Date: Sat, 25 Aug 2001 06:03:56 +0200
From: "GOGAR" <angenent@kabelfoon.nl>
Subject: Read/write specific line of file
Message-Id: <9m781u$10gv$1@news.kabelfoon.nl>
Hello there,
i'm fairly new to perl and ..umm i was just wondering if it was possible to
read or write a specific line of a file instead of having to go through the
whole file..
i'm working on some cgi scripts so it's important that it's as fast as
possible.
Reading in the whole file and picking out the line i want just doesn't feel
right..
my guess is that it's something with sysread and syswrite but i'm not sure
how to approach this, i hope anybody can help me here.
thanks for any suggestions or help, ;o)
Chris
------------------------------
Date: Fri, 24 Aug 2001 23:15:18 GMT
From: cfedde@fedde.littleton.co.us (Chris Fedde)
Subject: Re: request for assistance
Message-Id: <aeBh7.608$V3.171507712@news.frii.net>
In article <3B86B188.A29D3E51@alumni.uchicago.edu>,
Aaron Borowski <a-borowski-11@alumni.uchicago.edu> wrote:
>-=-=-=-=-=-
>The objective of this program would be to grab info from certain
>websites and save it to hard disk for faster off-line viewing. The main
>objective is to automate our information retrieval services. The
>attached file has a more detailed description of what we need and what
>we would like to have it accomplish in the future. Please email us f you
>
I recomend that you look in a local Chicago directory of consultants or
look for candidates in one of the news groups that has the words 'job',
'consultant', or 'wanted' in the title.
Good Luck
--
This space intentionally left blank
------------------------------
Date: Fri, 24 Aug 2001 19:22:01 -0700
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: request for assistance
Message-Id: <3b870bca@news.microsoft.com>
[CC to author]
"Aaron Borowski" <a-borowski-11@alumni.uchicago.edu> wrote in message
news:3B86B188.A29D3E51@alumni.uchicago.edu...
> I work with a small company on the south side of Chicago, and we really
> need a program developed. I am emailing you
No, you didn't. You posted an article to a Usenet usegroup.
> for your help in building
> this software.
No, you didn't. You didn't ask for help, you asked for someone to write it
for you.
> If you know of any friends, colleagues, or students that
> would be interested in undertaking this project please let me know, we
> are willing to pay competitively.
Please post your job offer in market.jobs.offered
> The objective of this program would be to grab info from certain
> websites and save it to hard disk for faster off-line viewing.
Please see module LWP.
> The main
> objective is to automate our information retrieval services. The
> attached file
Usenet is a text-only medium. Please do not use attachements in Usenet
> has a more detailed description of what we need and what
> we would like to have it accomplish in the future. Please email us f you
> can provide us with any assistance.
It is rude to post to a NG and ask for a reply via email (unless you promise
to post a compiled summary of the answers you got).
jue
------------------------------
Date: Fri, 24 Aug 2001 19:57:18 -0700
From: Kira <callgirl@la.znet.com>
Subject: Re: request for assistance
Message-Id: <3B87140E.28D6F6B8@la.znet.com>
"Jürgen Exner" wrote:
> Aaron Borowski wrote:
> > I work with a small company on the south side of Chicago, and we really
> > need a program developed. I am emailing you
(snipped deserved scolding for soliciting contract work here)
> It is rude to post to a NG and ask for a reply via email (unless you promise
> to post a compiled summary of the answers you got).
Don't think this a critique nor negative article.
Your comment about compiled summary of email responses
gave me an ornery smile. I just finished sending off
a psuedo formal complaint about email harassment to
a person's provider, his upstream provider and his
anonymous remailer. It is assured eyebrows will rise
and, he will pause for thought before again sending
me unlawful harassment email, at least he should.
Dunno, harassers are not real bright boys. Actually,
I both believe and know they are blithering idiots.
Would you like me to post a compilation of all this
harassment email I receive from regulars here? This
might be amusing, hmmm.. maybe not after a pause
for a bit of thought. Amusing for me however!
I _NEVER_ send harassment email.
These few job offering posts I read here, these
are nothing, not even worth a response.
Godzilla! Queen Of Ethicia.
--
19:50:04 08/24/2001 - RESTRICTED FILE REDIRECT:
- DNS: - IPA: 207.42.189.130
- System:
- Redirect URL: /default.ida
------------------------------
Date: 24 Aug 2001 20:38:18 -0700
From: pularis@go.com (Pularis)
Subject: String Substitution across two files
Message-Id: <aef550d9.0108241938.22d12df5@posting.google.com>
I have two very long multi column text files. Is it possible to
somehow look at one of the columns in one file and then substitue an
entry from that file to the other file if a match is found. Both
files have a common column, I want to replace other entries in one of
the columns if a match is found. I would greatly appreciate any help.
thanks
------------------------------
Date: Sat, 25 Aug 2001 00:50:05 GMT
From: fanzila@yahoo.com
Subject: Webmail
Message-Id: <3b87f619.4169937@news.free.fr>
I want to set up free webmail service for my site, where the user sign
up automatly
does anyone know free script ?
best regards and thank you in advance
Pierre
webmaster@gxist.com
http://www.gxist.com
------------------------------
Date: Sat, 25 Aug 2001 09:40:06 +0930
From: "Wyzelli" <wyzelli@yahoo.com>
Subject: Re: Yet another regex question
Message-Id: <wKBh7.8$o_2.16787@wa.nnrp.telstra.net>
"Stan Brown" <stanb@panix.com> wrote in message
news:9m698e$2o4$1@panix2.panix.com...
> given a string like in(0,1) where there may b 2 to many terms between the
> parens, and they may or may not be numbers. How can best parse this, such
> that I wind up with the terms between the parens in an array?
Assuming a split into the array on all commas, (putting any whitespace into
the array as well, and splitting on embedded commas as well, if any), here
are two options:
Assuming string is in $str,
@array = split /,/, $1 if $str =~ m/.*\((.*)\)/; #leaves original string
@array = split /,/, $str if $str =~ s/.*\((.*)\)/$1/; #modifies string
Assuming the string is in $_,
@array = split /,/, $1 if m/.*\((.*)\)/; # leaves
@array = split /,/ if s/.*\((.*)\)/$1/; #modifies
Actually the match version can be shortened to
@array = split /,/, $1 if m/\((.*)\)/;
since the leading .* is only needed for the substitution.
Wyzelli
--
#Modified from the original by Jim Menard
for(reverse(1..100)){$s=($_==1)? '':'s';print"$_ bottle$s of beer on the
wall,\n";
print"$_ bottle$s of beer,\nTake one down, pass it around,\n";
$_--;$s=($_==1)?'':'s';print"$_ bottle$s of beer on the
wall\n\n";}print'*burp*';
------------------------------
Date: 24 Aug 2001 18:04:14 -0700
From: merlyn@stonehenge.com (Randal L. Schwartz)
Subject: Re: Yet another regex question
Message-Id: <m1vgjdvtkh.fsf@halfdome.holdit.com>
>>>>> "Wyzelli" == Wyzelli <wyzelli@yahoo.com> writes:
Wyzelli> "Stan Brown" <stanb@panix.com> wrote in message
Wyzelli> news:9m698e$2o4$1@panix2.panix.com...
>> given a string like in(0,1) where there may b 2 to many terms between the
>> parens, and they may or may not be numbers. How can best parse this, such
>> that I wind up with the terms between the parens in an array?
Wyzelli> Assuming a split into the array on all commas, (putting any whitespace into
Wyzelli> the array as well, and splitting on embedded commas as well, if any), here
Wyzelli> are two options:
There are always more than two options. :)
This one gets rid of the enclosing whitespace:
$str = "foo( a, b1 b2 , c )";
my @items = split /\s*,\s*/, ($str =~ /\(\s*(.*?)\s*\)/)[0];
print map "[$_]", @items;
--
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!
------------------------------
Date: Fri, 24 Aug 2001 19:43:20 -0700
From: Kira <callgirl@la.znet.com>
Subject: Re: Yet another regex question
Message-Id: <3B8710C8.24244F7B@la.znet.com>
Randal L. Schwartz wrote:
> >>>>> Wyzelli wrote:
> > Stan Brown wrote:
> >> given a string like in(0,1) where there may b 2 to many terms between the
> >> parens, and they may or may not be numbers. How can best parse this, such
> >> that I wind up with the terms between the parens in an array?
> Wyzelli> Assuming a split into the array on all commas, (putting any whitespace into
> Wyzelli> the array as well, and splitting on embedded commas as well, if any), here
> Wyzelli> are two options:
> There are always more than two options. :)
Well, there are lots of options when clear, concise and coherent
parameters are provided. The author provided stereotypical
incoherent gibberish parameters.
* not surprised seventy-five percent of high school students *
* do not read nor write at an acceptable skill level *
> This one gets rid of the enclosing whitespace:
> $str = "foo( a, b1 b2 , c )";
> my @items = split /\s*,\s*/, ($str =~ /\(\s*(.*?)\s*\)/)[0];
> print map "[$_]", @items;
This one below my signature does it a little more efficiently
but not as stylish as your method and, not quite with the
same parameters you set for yourself. My benchmark comparison
is not truly a valid test with unequal parameters but rather
exemplifies how efficiency can be address when working with
well stated information and well stated parameters.
With the orginating author writing an article amounting to
nothing more than pure gibberish, I have made an assumption
his parenthetical data is single space delimited as shown
with multiple spaces not a part of data.
My experience is, when a participant within this newsgroup
writes clear, concise and coherent articles, especially
pertaining to parameters, efficiency can be well addressed.
Godzilla! Queen Of High Literacia.
--
#!perl
print "Content-Type: text/plain\n\n";
$data = "foo( a, b1 b2 , c )";
$data =~ s/\s\s+//g;
$data =~ s/,\s+/,/;
@Array = split (/,/, substr ($data, index ($data, "(") + 1, rindex ($data, ")") - 1 - index ($data, "(")));
$" = "¦";
print "@Array";
exit;
PRINTED RESULTS:
________________
a¦b1 b2¦c
#!perl
print "Content-type: text/plain\n\n";
use Benchmark;
print "Run One:\n\n";
&Time;
print "\n\nRun Two:\n\n";
&Time;
print "\n\nRun Three:\n\n";
&Time;
sub Time
{
timethese (100000,
{
'name1' =>
'$data = "foo( a, b1 b2 , c )";
@items = split /\s*,\s*/, ($data =~ /\(\s*(.*?)\s*\)/)[0];
@items = map "[$_]", @items;
@items = ();',
'name2' =>
'$data = "foo( a, b1 b2 , c )";
$data =~ s/\s\s+//g;
$data =~ s/,\s+/,/;
@Array = split (/,/, substr ($data, index ($data, "(") + 1, rindex ($data, ")") - 1 - index ($data, "(")));
@Array = ();',
} );
}
PRINTED RESULTS:
________________
Run One:
Benchmark: timing 100000 iterations of name1, name2...
name1: 6 wallclock secs ( 5.88 usr + 0.00 sys = 5.88 CPU) @ 17006.80/s
name2: 4 wallclock secs ( 3.68 usr + 0.00 sys = 3.68 CPU) @ 27173.91/s
Run Two:
Benchmark: timing 100000 iterations of name1, name2...
name1: 6 wallclock secs ( 5.94 usr + 0.00 sys = 5.94 CPU) @ 16835.02/s
name2: 4 wallclock secs ( 3.68 usr + 0.00 sys = 3.68 CPU) @ 27173.91/s
Run Three:
Benchmark: timing 100000 iterations of name1, name2...
name1: 6 wallclock secs ( 5.82 usr + 0.00 sys = 5.82 CPU) @ 17182.13/s
name2: 4 wallclock secs ( 3.68 usr + 0.00 sys = 3.68 CPU) @ 27173.91/s
------------------------------
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 1608
***************************************