[18609] in Perl-Users-Digest
Perl-Users Digest, Issue: 777 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Apr 27 03:06:13 2001
Date: Fri, 27 Apr 2001 00: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: <988355108-v10-i777@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Fri, 27 Apr 2001 Volume: 10 Number: 777
Today's topics:
Re: [Very OT] Sex and apathy (Tad McClellan)
Re: accessing hard drive via webpage <gtoomey@usa.net>
Accessing other servers in cgi without LWP <bertdb@iinet.net.au>
Benchmark.pm is REALLY inaccurate? <xris@dont.send.spam>
best way to evaluate $1 so it's not read-only? <xris@dont.send.spam>
building Perl 5.6.0 with a custom @INC <ceverett@ceverett.com>
decimal-string to CORRECT binary-string ?? $binary_stri <murat.uenalan@gmx.de>
extracting hostname from a url? <neerajk@cs.tamu.edu>
Re: extracting hostname from a url? <tony_curtis32@yahoo.com>
Re: extracting hostname from a url? (Logan Shaw)
Re: extracting hostname from a url? <comdog@panix.com>
Functional equivant to =~ operator? <gtoomey@usa.net>
Re: Good editor for perl <notmyrealemail@fake.com>
Re: HELP!!! Bus error(coredump) - How to recover? <johnlin@chttl.com.tw>
Re: How to down size /usr/bin/perl ? <gtoomey@usa.net>
Re: How to down size /usr/bin/perl ? (Logan Shaw)
Re: perl certification <gtoomey@usa.net>
Re: Problem in Netscape with CGI Headers (David Efflandt)
referencing elements of a string <cyberian_bear@hotmail.com>
Re: referencing elements of a string (Damian James)
Re: Regexp Question (Tad McClellan)
Re: Regular expression for zip code <notmyrealemail@fake.com>
Re: Regular expression for zip code <notmyrealemail@fake.com>
Re: Regular expression for zip code <notmyrealemail@fake.com>
Re: Regular expression for zip code <wyzelli@yahoo.com>
Re: require "file.pl" (vs use ?) to access subroutine i (Tad McClellan)
Things written to socket not flushed? <dontuspamme@nospammers.com>
Re: Things written to socket not flushed? <dontuspamme@nospammers.com>
VBScript or Perl for the Job <smilepak@hotmail.com>
Re: VBScript or Perl for the Job <gtoomey@usa.net>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Thu, 26 Apr 2001 23:36:27 -0400
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: [Very OT] Sex and apathy
Message-Id: <slrn9ehq9q.2js.tadmc@tadmc26.august.net>
Tim Hammerquist <tim@vegeta.ath.cx> wrote:
>I've seen some strange threads in this group, but damn.
I was blissfully unaware of the whole fracus thanks to my
trusty scorefile, until somebody went and removed the
red flag from the Newsgroups header...
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Fri, 27 Apr 2001 12:21:54 +1000
From: "Gregory Toomey" <gtoomey@usa.net>
Subject: Re: accessing hard drive via webpage
Message-Id: <Vv4G6.12265$482.60810@newsfeeds.bigpond.com>
No it's not.
The question was whether this can be done in Perl.
gtoomey
---------
"Einhardschule Seligenstadt" <webmaster@einhardschule.de> wrote in message
news:9c8gcd$u17$03$1@news.t-online.com...
>
> Craig Berry <cberry@cinenet.net> schrieb in im Newsbeitrag:
> teebtsqe6r240e@corp.supernews.com...
> > mathieu.barroussel (mathieu.barroussel@ntlworld.com) wrote:
> > : I need to write a cgi (Perl or C) that, from my web page, enables me
to
> > : access the c:\ hard drive or just one program, on a remote PC. Is this
> > : possible?
>
> Yes it is possible. Thx IE 5.5 ;)
------------------------------
Date: Fri, 27 Apr 2001 12:54:09 +0800
From: Bert DeBoer <bertdb@iinet.net.au>
Subject: Accessing other servers in cgi without LWP
Message-Id: <3AE8FB71.ADE374DB@iinet.net.au>
For part of an assignment I have to write a cgi script that receives a text file
from another server and does something with it. Essentially if I can get the
following working, I can do what I want:
#!/usr/bin/perl
print "Content-type: text/html\n\n";
print "<HTML>\n";
print "<HEAD>\n";
print "<TITLE>Welcome</TITLE>\n";
print "</HEAD>\n";
print "<BODY>\n";
$url='http://www.server.com/directory/file.txt';
$content = &get($url);
print "$content\n"
print "</BODY>\n";
print "</HTML>\n";
Now in the assignment we are not allowed to use any external programs. At the
moment my design is implemented with 'wget' but I have to replace this with the
low level HTTP protocol requests. We are also NOT allowed to use MODULES, and
every example I find that does something like this uses LWP from the
libwww-perl-5.53 library. I have tried to understand the module Simple.pm and
write my own code, but it needs 14 other modules, and all that code pasted
together gives about a 300k text file. This is way too much to learn for the
assignment. I need a group of simple subroutines (and packages if required) that
can be pasted below the above code to make it work. Simple error handling can be
achieved by checking if $content is empty or something similar. The file
retrieved is always a text file.
Thanks in advance
-Ryan De Boer
PS could you please email me any replies at (in addition to replying in
newsgroup):
bertdb@iinet.net.au
------------------------------
Date: Fri, 27 Apr 2001 00:52:12 -0500
From: xris <xris@dont.send.spam>
Subject: Benchmark.pm is REALLY inaccurate?
Message-Id: <xris-858133.00521227042001@news.evergo.net>
and here everyone was telling me that Benchmark was such a good
indicator of the speed of various routines... so how come when I run
the same test three times in a row, I get three VERY different results?
> ./test.pl
Benchmark: timing 50000 iterations of 1, 2, 3, 4, 5...
1: 2 secs ( 1.57 usr 0.00 sys = 1.57 cpu)
2: 2 secs ( 1.53 usr 0.01 sys = 1.54 cpu)
3: 3 secs ( 1.56 usr 0.00 sys = 1.56 cpu)
4: 4 secs ( 1.72 usr 0.00 sys = 1.72 cpu)
5: 2 secs ( 1.77 usr 0.00 sys = 1.77 cpu)
> ./test.pl
Benchmark: timing 50000 iterations of 1, 2, 3, 4, 5...
1: 2 secs ( 1.54 usr 0.01 sys = 1.55 cpu)
2: 2 secs ( 1.56 usr 0.00 sys = 1.56 cpu)
3: 3 secs ( 1.56 usr 0.01 sys = 1.57 cpu)
4: 3 secs ( 1.80 usr 0.00 sys = 1.80 cpu)
5: 8 secs ( 1.79 usr 0.00 sys = 1.79 cpu)
> ./test.pl
Benchmark: timing 50000 iterations of 1, 2, 3, 4, 5...
1: 2 secs ( 1.58 usr 0.00 sys = 1.58 cpu)
2: 1 secs ( 1.56 usr 0.00 sys = 1.56 cpu)
3: 2 secs ( 1.55 usr 0.00 sys = 1.55 cpu)
4: 2 secs ( 1.71 usr 0.00 sys = 1.71 cpu)
5: 2 secs ( 1.77 usr 0.00 sys = 1.77 cpu)
ok, so I know that a lot of it could do with the system doing different
things at different times, but you'd really thing that with 50,000
iterations, it wouldn't make that much of a difference.
-Chris
------------------------------
Date: Thu, 26 Apr 2001 23:59:20 -0500
From: xris <xris@dont.send.spam>
Subject: best way to evaluate $1 so it's not read-only?
Message-Id: <xris-32E9AD.23592026042001@news.evergo.net>
ok, after recently learning that $_[0] (and related vars) are hard
references to subroutine parameters (and apparently the ONLY way to get
a hard reference to them), I've started modifying a lot of my functions
to get some minor speed increases here and there. Anyway, one of my
problems is that a lot of these functions are called both on regular
variables and on substitution patterns. The problem is that $1 and its
companions are read-only, which causes an error. My sample code is
below (yes, I know this can be done easier, I'm just using it for
testing).
sub t {
$_[0] =~ tr/a-z/A-Z/;
return $_[0];
}
$x = 'this is a test.';
$x =~ s/(test)/&t($1)/sgieo;
print $x;
I can get around this by:
$x =~ s/(test)/&t("$1")/sgieo;
but I'm wondering if there's a more efficient way to "evaluate" $1. Or,
a test I can do on $_[0] to determine if it's accessing a read-only
value or not. Any suggestions?
------------------------------
Date: Fri, 27 Apr 2001 01:44:50 -0500
From: "Christopher L. Everett" <ceverett@ceverett.com>
Subject: building Perl 5.6.0 with a custom @INC
Message-Id: <3AE91562.BAFF13E1@ceverett.com>
How? It works with 5.6.1 where ./Configure asks
if I want to have any other directories added to
the @INC, but the ./Configure for 5.6.0 doesn't
ask the question. I tried to edit the config.sh
to add a line "otherlibdirs=/usr/share/perl5"
but it doesn't get added to @INC, despite what it
says in the INSTALL file.
Without /usr/share/perl5 in @INC, the Debian
package system breaks; with Perl 5.6.1 the Debian
package system breaks too.
--Christopher
------------------------------
Date: Thu, 26 Apr 2001 22:55:29 +0200
From: "Murat Uenalan" <murat.uenalan@gmx.de>
Subject: decimal-string to CORRECT binary-string ?? $binary_string = unpack('B*', "$cnt"); fails
Message-Id: <9ca23b$cp04v$1@ID-71895.news.dfncis.de>
I simply want a CORRECT binary representation of a scalar integer. But the
method described in the FAQ gives me some ascii-translation but not the
correct translation -> as seen between $cnt 9-10 it just starts with the
second ascii position ????
for my $cnt ( 0 .. 12 )
{
printfln "$cnt = %s", $binary_string = unpack('B*', "$cnt");
}
results in
0 = 00110000
1 = 00110001
2 = 00110010
3 = 00110011
4 = 00110100
5 = 00110101
6 = 00110110
7 = 00110111
8 = 00111000
9 = 00111001
10 = 0011000100110000
11 = 0011000100110001
12 = 0011000100110010
__END__
Thanks in advance,
Murat
------------------------------
Date: Thu, 26 Apr 2001 21:23:18 -0400
From: Neeraj Khandelwal <neerajk@cs.tamu.edu>
Subject: extracting hostname from a url?
Message-Id: <3AE8CA05.A9B2697C@cs.tamu.edu>
hi
I need to extract the hostname from a url. what would be a neat regular
expression to do this? for example given url
http://www.yahoo.com/weather/today
i would like to extract http://www.yahoo.com from it.
I tried the following but it does not work:
/(http:.*\/)/
the problem with this is that it matches the last slash instead of the
first. so what this returns is:
http://www.yahoo.com/weather/
thanks in advance
neeraj
------------------------------
Date: 26 Apr 2001 21:30:05 -0500
From: Tony Curtis <tony_curtis32@yahoo.com>
Subject: Re: extracting hostname from a url?
Message-Id: <87lmonxefm.fsf@limey.hpcc.uh.edu>
>> On Thu, 26 Apr 2001 21:23:18 -0400,
>> Neeraj Khandelwal <neerajk@cs.tamu.edu> said:
> hi I need to extract the hostname from a url. what would
> be a neat regular expression to do this? for example
> given url
> http://www.yahoo.com/weather/today
> i would like to extract http://www.yahoo.com from it.
That's not a hostname!
But try the URI module. A lot easier than trying to roll
your own contorted re's:
use strict;
use URI;
my $u = new URI "http://www.yahoo.com/extra/stuff/";
print $u->host, "\n";
Use methods scheme and host_port (may not always be the
default after all) to get the bit you want:
my $bit = $u->scheme . '://' . $u->host_port;
==> http://www.yahoo.com:80
hth
t
--
Just reach into these holes. I use a carrot.
------------------------------
Date: 27 Apr 2001 00:14:47 -0500
From: logan@cs.utexas.edu (Logan Shaw)
Subject: Re: extracting hostname from a url?
Message-Id: <9cav87$i47$1@charity.cs.utexas.edu>
In article <3AE8CA05.A9B2697C@cs.tamu.edu>,
Neeraj Khandelwal <neerajk@cs.tamu.edu> wrote:
>hi
>
>I need to extract the hostname from a url. what would be a neat regular
>expression to do this? for example given url
>
>http://www.yahoo.com/weather/today
>
>i would like to extract http://www.yahoo.com from it.
>
>I tried the following but it does not work:
>
> /(http:.*\/)/
>
>the problem with this is that it matches the last slash instead of the
>first. so what this returns is:
You told it to match any number ("*") of any character ("."), and slash
is a character, so it matches. (Perl regular expressions are greedy,
which means that they try to match the longest sequence they can.)
Anyway, one way to do what you're talking about is something like this:
m<^(http://[^/]+/?)>i
Note that I've used m<> delimiters instead of //, because this makes it
so that you don't have to escape all the slash characters.
Hope that helps.
- Logan
--
my your his her our their _its_
I'm you're he's she's we're they're _it's_
------------------------------
Date: Fri, 27 Apr 2001 01:43:21 -0400
From: brian d foy <comdog@panix.com>
Subject: Re: extracting hostname from a url?
Message-Id: <comdog-007CA4.01432127042001@news.panix.com>
In article <9cav87$i47$1@charity.cs.utexas.edu>, logan@cs.utexas.edu
(Logan Shaw) wrote:
> In article <3AE8CA05.A9B2697C@cs.tamu.edu>,
> Neeraj Khandelwal <neerajk@cs.tamu.edu> wrote:
> >hi
> >
> >I need to extract the hostname from a url. what would be a neat regular
> >expression to do this? for example given url
> Anyway, one way to do what you're talking about is something like this:
>
> m<^(http://[^/]+/?)>i
why use a regular expression when a URI module exists?
--
brian d foy <comdog@panix.com>
------------------------------
Date: Fri, 27 Apr 2001 15:17:12 +1000
From: "Gregory Toomey" <gtoomey@usa.net>
Subject: Functional equivant to =~ operator?
Message-Id: <f47G6.12343$482.60960@newsfeeds.bigpond.com>
Maybe I've missed something in my Perl readings, but this has me confused.
We can use the assignment
$var1 =~ tr/a-z/A-Z/;
Is there an equivalent tr function? Something like
$var2 = tr/a-z/A-Z/ ($var1);
If there is, then we could use function composition along the following
lines
$var2 = s/123/456/g (tr/a-z/A-Z/ ($var));
Is this sort of thing available in Perl, or is it just wishful thinking?
gtoomey
------------------------------
Date: Fri, 27 Apr 2001 03:16:43 GMT
From: "BarryK" <notmyrealemail@fake.com>
Subject: Re: Good editor for perl
Message-Id: <vw5G6.31639$U4.6742386@news1.rdc1.tn.home.com>
Perl Builder is awesome. It's not cheap though.
"Super-Simon" <simon@super-simon.com> wrote in message
news:9c1csm$loh$1@news1.xs4all.nl...
> Hi all,
>
> I'm searching for a good, fast editor with syntax highlighting for perl
> (CGI) for use under Windows 2000 / Windows 98 (I use windowz only for
> editing scripts, scripts runs on Linux-server). It has to be free (I'm a
> poor student ;-)
>
> Grtz,
>
> Super-Simon
>
>
------------------------------
Date: Fri, 27 Apr 2001 10:01:12 +0800
From: "John Lin" <johnlin@chttl.com.tw>
Subject: Re: HELP!!! Bus error(coredump) - How to recover?
Message-Id: <9cajp9$o9h@netnews.hinet.net>
Thank you for responding.
"Einhardschule Seligenstadt" wrote
> What happens on
> perl -MNet::FTP -e"print 1;"
Running by super-user is OK, but running by normal user fails.
$ perl -MNet::FTP -e "print 1"
Bus error(coredump)
$ su root
$ perl -MNet::FTP -e "print 1"
1
> If it crashes, try to download Net::FTP from the CPAN (again).
Yes, we did. During the installation (running by super-user), the
perl Makefile.PL
make
phases are all OK. But the
make test
phase fails. All tests dump a core. Wow!!!
# perl Makefile.PL
<snip all OK messages>
# make
<snip all OK messages>
# make test
PERL_DL_NONLAZY=1 /usr/bin/perl -Iblib/arch -Iblib/lib -I/opt/perl5/lib/
5.6.0/PA-RISC2.0 -I/opt/perl5/lib/5.6.0 -e 'use Test::Harness qw(&runtests $verb
ose); $verbose=0; runtests @ARGV;' t/*.t
t/ftp...............dubious
Test returned status 0 (wstat 138, 0x8a)
test program seems to have generated a core
t/hostname..........dubious
Test returned status 0 (wstat 138, 0x8a)
test program seems to have generated a core
t/nntp..............dubious
Test returned status 0 (wstat 138, 0x8a)
test program seems to have generated a core
t/ph................dubious
Test returned status 0 (wstat 138, 0x8a)
test program seems to have generated a core
t/require...........dubious
Test returned status 0 (wstat 138, 0x8a)
test program seems to have generated a core
t/smtp..............dubious
Test returned status 0 (wstat 138, 0x8a)
test program seems to have generated a core
FAILED--6 test scripts could be run, alas--no output ever seen
*** Error exit code 2
We don't know what to do next...
Thank you very much.
John Lin
------------------------------
Date: Fri, 27 Apr 2001 12:12:16 +1000
From: "Gregory Toomey" <gtoomey@usa.net>
Subject: Re: How to down size /usr/bin/perl ?
Message-Id: <kr4G6.12259$482.59985@newsfeeds.bigpond.com>
Create your own language an implement it. It shoud take you about a year.
gtoomey
----
"Pally Kuo" <pally@axtronics.com.tw> wrote in message
news:9caea9$2n89$1@ccreader.nctu.edu.tw...
> what should I do if all I want is socket function ?
------------------------------
Date: 27 Apr 2001 00:17:04 -0500
From: logan@cs.utexas.edu (Logan Shaw)
Subject: Re: How to down size /usr/bin/perl ?
Message-Id: <9cavcg$i5b$1@charity.cs.utexas.edu>
In article <kr4G6.12259$482.59985@newsfeeds.bigpond.com>,
Gregory Toomey <gtoomey@usa.net> wrote:
>Create your own language an implement it. It shoud take you about a year.
Boy, I hope it doesn't take that long. In the fall, I'm planning to
take a compilers class in which (I'm told) I will get to write my own
compiler (for Pascal, yippie), and this takes only a semester.
- Logan
--
my your his her our their _its_
I'm you're he's she's we're they're _it's_
------------------------------
Date: Fri, 27 Apr 2001 12:17:01 +1000
From: "Gregory Toomey" <gtoomey@usa.net>
Subject: Re: perl certification
Message-Id: <kr4G6.12260$482.59985@newsfeeds.bigpond.com>
Being able to answer questions posted to this newsgroup.
gtoomey
-----
"Todd Smith" <todd@designsouth.net> wrote in message
news:9UZF6.29457$U4.6389179@news1.rdc1.tn.home.com...
> Is there a Perl certification course that any employer actually cares
about?
>
>
------------------------------
Date: Fri, 27 Apr 2001 03:23:58 +0000 (UTC)
From: see-sig@from.invalid (David Efflandt)
Subject: Re: Problem in Netscape with CGI Headers
Message-Id: <slrn9ehpie.t7r.see-sig@typhoon.xnet.com>
On Thu, 26 Apr 2001 16:07:29 GMT, ros@ros.com <ros@ros.com> wrote:
> I have a script that writes to a database and presents itself again to
> ask for more data. It works perfectly in explorer, but navigator is
> much less permissive with headers and only gives me a 404 asking for
> my /cgi-bin/ root
>
> The script is as follows:
>
> &readfile;
> $q=new CGI;
> print $q->start_html(),
Your problem is testing with a browser that generally ignores headers
(MSIE) and failed to realize that you failed to include any. You need
to print $q->header before $q->start_html().
--
David Efflandt (Reply-To is valid) http://www.de-srv.com/
http://www.autox.chicago.il.us/ http://www.berniesfloral.net/
http://cgi-help.virtualave.net/ http://hammer.prohosting.com/~cgi-wiz/
------------------------------
Date: Thu, 26 Apr 2001 23:13:23 -0400
From: "cyberian bear" <cyberian_bear@hotmail.com>
Subject: referencing elements of a string
Message-Id: <Qt5G6.4$bS2.518@typhoon.nyu.edu>
I need to create a tic-tac-toe program. So I need to have three arrays and
one hash.
#!/usr/bin/perl
%board = (1, "---", 2, "---",3, "---");
But in perl is language where string is not an array itself so we can't
access individual elements.
So here I have the first problem. Let's say I want to see if a certain
position in a table has already been taken up by either "0" or "1". So I
have to check whether or not the location contains "-".
Second Let say location does contain "-". Then I might decide to either fill
it in with either "0" or "1". Again I don't see how I can do it since we
can't access individual elements of a string.
Can someone please give me a clue on how to get around that problem.
PS: One of my classmates gave me a suggestion which I didn't completely
understand. Here it is:
@tictactoe = (['x', '.' ,'0'], ['0', '.', 'x'], ['0', '.' ,'x']);
$tic[0] => [0] == 'x';
@new= @{\@tic}
So here the first line is just a possible state of a board.
What the heck do other two line do?
cb
------------------------------
Date: 27 Apr 2001 03:38:14 GMT
From: damian@qimr.edu.au (Damian James)
Subject: Re: referencing elements of a string
Message-Id: <slrn9ehq9q.h7i.damian@puma.qimr.edu.au>
cyberian bear chose Thu, 26 Apr 2001 23:13:23 -0400 to say this:
>I need to create a tic-tac-toe program. So I need to have three arrays and
>one hash.
>
>#!/usr/bin/perl
>%board = (1, "---", 2, "---",3, "---");
>
>But in perl is language where string is not an array itself so we can't
>access individual elements.
Okay -- first you need to distance yourself a bit more from the idea that a
string is an array -- this is simply not the case in Perl In Perl, a string
is a scalar value.
You certainly can access the individual characters in a string
(see perldoc -f substr), but you clearly want to implement arrays
here. The problem is that elements in a hash or an array can only be
scalars.
>...
>Can someone please give me a clue on how to get around that problem.
>
>PS: One of my classmates gave me a suggestion which I didn't completely
>understand. Here it is:
>@tictactoe = (['x', '.' ,'0'], ['0', '.', 'x'], ['0', '.' ,'x']);
>$tic[0] => [0] == 'x';
^^^^
Your friend probably means '->' here.
>@new= @{\@tic}
>
>So here the first line is just a possible state of a board.
>What the heck do other two line do?
You need to read about using references to construct Lists of Lists
(LoLs). See
perldoc perllol
perldoc perlref
perldoc perlreftut
perldoc perldsc
In short, your friend is suggesting that you take an ordinary array (not a
hash -- where your hash keys are numeric and consecutive, you probably
should be using an array), and populate it with references to anonymous
arrays.
@tictactoe = (); # an empty array
@row = ('-', '-', '-'); # a row
$tictactoe[0] = \@row0; # makes the first element in @tictactoe
# a reference to @row0
$row1 = [ '-', '-', '-' ]; # a (scalar) reference to an anonymous array
$tictactoe[1] = $row1; # copies the reference to the second element
# of @tictactoe
$tictactoe(2) = ['-', '-', '-' ]; # assigns the anonymous array ref
# directly to the third element
print $tictactoe[0]->[1]; # prints the second row of the first column.
HTH,
Cheers,
Damian
--
@:=grep!($;+=m!$/|#!),split//,<DATA>;@;=0..$#:;while(@;){for($;=@;;--$;;)
{@;[$;,$:]=@;[$:,$;]if($:=rand$;+$|)!=$;}push@|,shift@;if$;[0]==@|;select
$,,$,,$,,1/80;print qq x\bxx((@;+@|)*$|++),@:[@|,@;],!@;&&$/} __END__
Just another Perl Hacker # rev 3.1 -- a JAPH in progress, I guess...
------------------------------
Date: Thu, 26 Apr 2001 22:44:33 -0400
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Regexp Question
Message-Id: <slrn9ehn8h.2js.tadmc@tadmc26.august.net>
Peter White <hpya78@postoffice.pacbell.net> wrote:
>Here is my script
>
>File:
>aa 45 23 22
>bb 2 12 67
>dd 99 98 100
>ff 101 99 100
>mm 56 87 1
>nn 10000 999 1
>------------------------
>Ouput should be:
>aa 45 23 22
>bb 2 12 67
>dd 99 98 100
>mm 56 87 1
>
>
>#!/user/bin/perl -w
>
>open(FILE, "abc.txt") || die "Cannot open\n";
open(FILE, 'abc.txt') || die "Cannot open 'abc.txt' $!";
>@abc=(<FILE>);
>foreach $info(@abc)
No need for the temp @abc variable. No need to hold the entire
file in memory:
while ( $info = <FILE> )
>{
> ($word, @nums)=split(/\s+/, $info);
[snip loops]
print " $word @nums\n" unless grep {$_ < 0 or $_ > 100} @nums;
^ ^
^ ^ I dunno what your extra spaces are for, but I left them in
>}
[ snip Jeopardy quoted text. Please don't do that. ]
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Fri, 27 Apr 2001 01:16:02 GMT
From: "BarryK" <notmyrealemail@fake.com>
Subject: Re: Regular expression for zip code
Message-Id: <mL3G6.30715$U4.6644482@news1.rdc1.tn.home.com>
OOOOHHH so close!
"Shay Harding" <sharding@ccbill.com> wrote in message
news:9cafcm$192c$1@node17.cwnet.frontiernet.net...
> >
> > s/\b(?<!-)\d{5}(-\d{4})*(?!-)\b/X/g;
> >
>
> Sorry, my last (above) expression won't work without changing the '*' into
a
> '?'. Darn greedy little guy.
>
> s/\b(?<!-)\d{5}(-\d{4})?(?!-)\b/X/g;
>
>
> Shay
>
>
>
>
>
------------------------------
Date: Fri, 27 Apr 2001 01:17:45 GMT
From: "BarryK" <notmyrealemail@fake.com>
Subject: Re: Regular expression for zip code
Message-Id: <ZM3G6.30718$U4.6645923@news1.rdc1.tn.home.com>
Rats, this fails for 12345-12345
"BarryK" <notmyrealemail@fake.com|> wrote in message
news:VA3G6.30698$U4.6635301@news1.rdc1.tn.home.com..
.
|> SOLUTION TO ZIP CODE PROBLEM (FINALLY!!)
|>
|> use warnings;
|> use diagnostics;
|>
|> $_ = <<'ENDIT';
|> 12345 12345-1234 123-12345-4444 12345-1234-1234 Zip:12345-6789 A=12345
|> and this is the next line.
|> ENDIT
|>
|> s[ \b\d{5}(?!-)\b | \b(?<! -)\d{5}-\d{4}(?!-)\b ] [X]xg;
|>
|> print $_;
|>
|>
------------------------------
Date: Fri, 27 Apr 2001 01:27:11 GMT
From: "BarryK" <notmyrealemail@fake.com>
Subject: Re: Regular expression for zip code
Message-Id: <PV3G6.30735$U4.6653545@news1.rdc1.tn.home.com>
this one works for all the cases listed.
==
use warnings;
use diagnostics;
$_ = <<'ENDIT';
12345 12345-1234 123-12345-4444 12345-12345 12345-1234-1234 Zip:12345-6789
A=12345
ENDIT
s: \b(?<![=-])\d{5}(?!-)\b | \b(?<! -)\d{5}-\d{4}(?!-)\b :X:xg;
print $_;
------------------------------
Date: Fri, 27 Apr 2001 11:22:02 +0930
From: "Wyzelli" <wyzelli@yahoo.com>
Subject: Re: Regular expression for zip code
Message-Id: <Z14G6.10$nf5.4105@vic.nntp.telstra.net>
"Ren Maddox" <ren@tivoli.com> wrote in message
news:m3itjrtr25.fsf@dhcp9-172.support.tivoli.com...
> On Thu, 26 Apr 2001, notmyrealemail@fake.com wrote:
>
> I do occasionally feel like a zero-width assertion that matches
> between a "\s" and a "\S" would be useful. It seems like I often end
> up employing "(?:^|(?<=\s))" and "(?!\s|$)". I would much rather have
> a two-character assertion for that, but I have no idea what it would
> be. All of the reasonable choices seem to be taken (eg. \b, \s, \w).
>
How about \c for 'character boundary' ?
Wyzelli
--
($a,$b,$w,$t)=(' bottle',' of beer',' on the wall','Take one down, pass it
around');
$d='$_$a$s$b$w';$e='$_$a$s$b';sub d{$h=shift;$h=~s/\$(\w+)/${$1}/g;return$h}
sub
e{return(shift!=1)?'s':''}for(reverse(1..100)){$s=e($_);$f=d($d);$g=d($e);
$c.="$f\n$g\n$t\n";$_--;$s=e($_);$e=d($d);$c.="$e\n\n";}print"$c*hic*";
------------------------------
Date: Thu, 26 Apr 2001 23:14:25 -0400
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: require "file.pl" (vs use ?) to access subroutine in file.pl ?
Message-Id: <slrn9ehp0h.2js.tadmc@tadmc26.august.net>
Yeoh Yiu <squid@panix.com> wrote:
>In the code below, m.pl is the main program and s.pl contains a
>subroutine to be called by m.pl . (I've simplified the code
>as much as I could and still demonstrate my error
>-- please, no flames like 'that's a lame sub(), it only returns 3'.
But note that the fact that it does return 3 is significant.
Things will be different if it returns 0 instead...
>I want to run m.pl, and have it call the sub chk_ps(); I'm not
>interested in running anything else in s.pl other than
>chk_ps().
If there is any "main code" (ie. any code outside of subroutines),
then it _will_ be executed when you require it whether that is
what you are interested in or not.
>This code works as intended if I leave this block in s.pl:
>
> my $result = chk_ps("bashing");
> open (NULL, ">/dev/null") or die "No null ! $! \n";
> print NULL "Result = $result\n";
> close(NULL);
The sub{} is only a definition, it does not get executed when
"require"d.
So then, what will be the value of the "last statement evaluated"?
That close() there will be evaluated last. If it succeeded in
closing (seems likely) it returns true, which becomes the return
value from s.pl.
>If I comment out these filehandle lines, as shown below, I get
^^^^^^^^^^^^^^
Actually, I'm pretty sure that it is a little *different* than
you have shown below.
>$ ./m.pl
> s.pl did not return a true value at ./m.pl line 3.
>$
All the messages that perl might issue are documented in the
perldiag.pod standard doc. You should look them up there as
a *first* step in troubleshooting:
-----------------------
=item %s did not return a true value
(F) A required (or used) file must return a true value to indicate that
it compiled correctly and ran its initialization code correctly. It's
traditional to end such a file with a "1;", though any true value would
do. See L<perlfunc/require>.
-----------------------
>Interestingly, my perldoc -f require
Did you skim on past where is said this:
-----------------------
The file must return true as the last statement to indicate
successful execution of any initialization code, so it's customary to
end such a file with C<1;> unless you're sure it'll return true
otherwise. But it's better just to put the C<1;>, in case you add more
statements.
-----------------------
>gives no example of the form
>require "filename.pl";
A double quoted string is an EXPR. perlfunc shows "require EXPR".
>So do I need s.pl to return a value to m.pl,
Yes.
>or do I need only
>chk_ps() to return the value ?
That would depend on whether or not chk_ps()'s return value ended
up also being s.pl's return value. Your code below is an example
where the subroutine's return value matters.
If you just put "1;" at the end of s.pl you don't have to sort
out all of this return value stuff.
>Or is 'require' not the best way to import subroutines, and use/eval
>somehow more apropos ?
Heavens no! eval() is a resource of last resort.
You just have to use require correctly.
(or better yet, make it a Real Module and use use)
>And why does writing to a filehandle provide a return value in this manner ?
It is not the writing to a filehandle. It is the return value from
the close() propagating to become the return value for s.pl.
> ==============================
> #!/usr/bin/perl -w
> use strict;
> # this is s.pl
> my $result = chk_ps("bashing");
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
There is an executable statement not inside of a subroutine.
It gets run when you require s.pl.
It is the _only_ thing in s.pl that gets run, so it will determine
the return value for s.pl.
I cannot duplicate the problem you describe above with the code
you have given here.
chk_ps() is hard-coded to return a true value, so I see no messages.
If you comment out the "my $result" line (or return false from chk_ps()),
_then_ I get the message you mention.
> # open (NULL, ">/dev/null") or die "No null ! $! \n";
> # print NULL "Result = $result\n";
> # close(NULL);
>
> sub chk_ps {
> my @ps_oi = @_; # p of interest
>
> my $ecode = 3; # simple logic
>
> return $ecode;
> }
>
> ==============================================
>
> #!/usr/bin/perl -w
> use strict;
> require "s.pl";
> # this is m.pl
> my $result1 = chk_ps("httpd"); # 1 running, 0 not, 3 zombie
> print "Result1 = $result1\n\n";
>
> ==============================================
>$ ./m.pl
> s.pl did not return a true value at ./m.pl line 3.
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Thu, 26 Apr 2001 19:21:53 -0700
From: "kalasend at YAHOO dot COM" <dontuspamme@nospammers.com>
Subject: Things written to socket not flushed?
Message-Id: <MG4G6.11$DB3.4041@chrome-fe.eng.netapp.com>
hi,
I'm very new to Perl. (best defender anyway :-)
I wrote a simple program to just grab the index page of any web server
given. It uses socket to connect to port 80 of a host, and then do this:
my $EOL = "\015\012";
print SOCK "GET / HTTP/1.1", $EOL;
Then it hangs there forever...I think it could be that the buffer for
that socket is not flushed? (I can read things from the socket without
problems, by the way).
thanks,
Ben
------------------------------
Date: Thu, 26 Apr 2001 19:36:47 -0700
From: "kalasend at YAHOO dot COM" <dontuspamme@nospammers.com>
Subject: Re: Things written to socket not flushed?
Message-Id: <KU4G6.12$DB3.4041@chrome-fe.eng.netapp.com>
by the way, that
my $EOL = "\015\012";
was copied from documentation on www.perl.com
some also say it needs two $EOL, i.e..
my $BLANK = $EOL x 2;
print SOCK "GET / HTTP/1.1", $BLANK;
but I tried and it didn't work too.....
"kalasend at YAHOO dot COM" <dontuspamme@nospammers.com> wrote in message
news:MG4G6.11$DB3.4041@chrome-fe.eng.netapp.com...
> hi,
> I'm very new to Perl. (best defender anyway :-)
> I wrote a simple program to just grab the index page of any web server
> given. It uses socket to connect to port 80 of a host, and then do this:
>
> my $EOL = "\015\012";
> print SOCK "GET / HTTP/1.1", $EOL;
>
> Then it hangs there forever...I think it could be that the buffer for
> that socket is not flushed? (I can read things from the socket without
> problems, by the way).
>
> thanks,
> Ben
>
>
------------------------------
Date: Fri, 27 Apr 2001 01:13:09 GMT
From: "smilepak" <smilepak@hotmail.com>
Subject: VBScript or Perl for the Job
Message-Id: <FI3G6.7$P61.3616@newsread1.prod.itd.earthlink.net>
Hello
I need a bunch of opinion and reason as to why I should use one of the two
technology to handle this particular project. I have an XML Data file (could
go as high as 700MB - 800MB per day) The data look somewhat like this (XML
data, and yes I could use XML feeder ect, but I need it in a tab delimited
flat file by parsing out the data). Should I use VBScript or Perl. Which of
the two will be more efficient in running and processing. Time wise and
system resources wise.
Sample Data: (Data below will repeat and there are approx 60+ files each
with these type of data total up to as high as 700-800MB of data daily)
<SDKE35244543>
<RES name="www.mydomain.com" t="585" total="43511">
<DATA v="1113" p="256">1</DATA>
<DATA v="438" p="101">2</DATA>
<DATA v="221" p="51">5</DATA>
<DATA v="1544" p="355">0</DATA>
<DATA v="3124" p="718">13</DATA>
<DATA v="2152" p="495">11</DATA>
<DATA v="1253" p="288">9</DATA>
<DATA v="197" p="45">6</DATA>
<DATA v="2553" p="587">17</DATA>
<DATA v="2667" p="613">20</DATA>
<DATA v="274" p="63">4</DATA>
<DATA v="2161" p="497">23</DATA>
<DATA v="498" p="114">3</DATA>
<DATA v="938" p="216">8</DATA>
<DATA v="2423" p="557">15</DATA>
<DATA v="1875" p="431">10</DATA>
<DATA v="2713" p="624">18</DATA>
<DATA v="2779" p="639">22</DATA>
<DATA v="3120" p="717">14</DATA>
<DATA v="2527" p="581">12</DATA>
<DATA v="2868" p="659">21</DATA>
<DATA v="543" p="125">7</DATA>
<DATA v="2539" p="584">16</DATA>
<DATA v="2991" p="687">19</DATA>
</RES>
<RES t="1508" total="9300">
<DATA v="1" refurl="http://movies.yahoo.com/directory/" p="1">
<PAGE v="0" url="www.mydomain.com/">directory_home</PAGE>
<PAGE v="1"
url="www.mydomain.com/directory/winners/winners.html">winners.html</PAGE>
<PAGE v="2"
url="www.mydomain.com/directory/winners/actress.html">actress.html</PAGE>
<PAGE v="3"
url="www.mydomain.com/directory/bios/roberts.html">roberts.html</PAGE>
<PAGE v="4"
url="www.mydomain.com/directory/winners/actress.html">actress.html</PAGE>
<PAGE v="5"
url="www.mydomain.com/directory/winners/winners.html">winners.html</PAGE>
</DATA>
</RES>
</SDKE35244543>
------------------------------
Date: Fri, 27 Apr 2001 12:02:10 +1000
From: "Gregory Toomey" <gtoomey@usa.net>
Subject: Re: VBScript or Perl for the Job
Message-Id: <qd4G6.12232$482.60939@newsfeeds.bigpond.com>
Both VBscript and Perl could do the job.
Processing will be completely IO bound, so they should both take about the
same time.
Providing you dont try to load a 800MB file in RAM, the programs will be
well under 1000 lines, so RAM is not an issue either.
It just comes down yo your personal preferences.
Perl has regular expression matching so is great at parsing data, and at
maniplating data.
gtoomey
---------
"smilepak" <smilepak@hotmail.com> wrote in message
news:FI3G6.7$P61.3616@newsread1.prod.itd.earthlink.net...
> Hello
>
> I need a bunch of opinion and reason as to why I should use one of the two
> technology to handle this particular project. I have an XML Data file
(could
> go as high as 700MB - 800MB per day) The data look somewhat like this (XML
> data, and yes I could use XML feeder ect, but I need it in a tab delimited
> flat file by parsing out the data). Should I use VBScript or Perl. Which
of
> the two will be more efficient in running and processing. Time wise and
> system resources wise.
>
> Sample Data: (Data below will repeat and there are approx 60+ files each
> with these type of data total up to as high as 700-800MB of data daily)
>
> <SDKE35244543>
> <RES name="www.mydomain.com" t="585" total="43511">
> <DATA v="1113" p="256">1</DATA>
> <DATA v="438" p="101">2</DATA>
> <DATA v="221" p="51">5</DATA>
> <DATA v="1544" p="355">0</DATA>
> <DATA v="3124" p="718">13</DATA>
> <DATA v="2152" p="495">11</DATA>
> <DATA v="1253" p="288">9</DATA>
> <DATA v="197" p="45">6</DATA>
> <DATA v="2553" p="587">17</DATA>
> <DATA v="2667" p="613">20</DATA>
> <DATA v="274" p="63">4</DATA>
> <DATA v="2161" p="497">23</DATA>
> <DATA v="498" p="114">3</DATA>
> <DATA v="938" p="216">8</DATA>
> <DATA v="2423" p="557">15</DATA>
> <DATA v="1875" p="431">10</DATA>
> <DATA v="2713" p="624">18</DATA>
> <DATA v="2779" p="639">22</DATA>
> <DATA v="3120" p="717">14</DATA>
> <DATA v="2527" p="581">12</DATA>
> <DATA v="2868" p="659">21</DATA>
> <DATA v="543" p="125">7</DATA>
> <DATA v="2539" p="584">16</DATA>
> <DATA v="2991" p="687">19</DATA>
> </RES>
> <RES t="1508" total="9300">
> <DATA v="1" refurl="http://movies.yahoo.com/directory/" p="1">
> <PAGE v="0" url="www.mydomain.com/">directory_home</PAGE>
> <PAGE v="1"
> url="www.mydomain.com/directory/winners/winners.html">winners.html</PAGE>
> <PAGE v="2"
> url="www.mydomain.com/directory/winners/actress.html">actress.html</PAGE>
> <PAGE v="3"
> url="www.mydomain.com/directory/bios/roberts.html">roberts.html</PAGE>
> <PAGE v="4"
> url="www.mydomain.com/directory/winners/actress.html">actress.html</PAGE>
> <PAGE v="5"
> url="www.mydomain.com/directory/winners/winners.html">winners.html</PAGE>
> </DATA>
> </RES>
> </SDKE35244543>
>
>
------------------------------
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 777
**************************************